/**
 * All intellectual property rights in this Software throughout the world belong to UK Radioplayer, 
 * rights in the Software are licensed (not sold) to subscriber stations, and subscriber stations 
 * have no rights in, or to, the Software other than the right to use it in accordance with the 
 * Terms and Conditions at www.radioplayer.co.uk/terms. You shall not produce any derivate works 
 * based on whole or part of the Software, including the source code, for any other purpose other 
 * than for usage associated with connecting to the UK Radioplayer Service in accordance with these 
 * Terms and Conditions, and you shall not convey nor sublicense the Software, including the source 
 * code, for any other purpose or to any third party, without the prior written consent of UK Radioplayer.
 *
 * sets up the overlay container
 * @constructor
 * @param {String} container CSS selector of the overlay container
 */
radioplayer.models.RadioplayerOverlayContainer = function(container) {
	this._CONTAINER_HEIGHT = '530px';
	this._$overlayContainer = glow.dom.get(container);
	this._isOpen = false;
};

radioplayer.models.RadioplayerOverlayContainer.prototype = {
	/**
	 * show the overlay container
	 */
	slidedown: function(height) {
		var that = this,
			opts = {
				onStart: function() {
					that._isOpen = true;
				}
			};
		return this._slideElement('down', opts, height);
	},

	/**
	 * hide the overlay container
	 */
	slideup: function(height) {
		var that = this,
			opts = {
				onComplete: function() {
					that._isOpen = false;
				}
			};
		return this._slideElement('up', opts, height);
	},
	
	/**
	 * generic method that slides up & down
	 */
	_slideElement: function(action, opts, height) {
		var that = this,
			animation,
			fromHeight,
			completeHeight,
			setHeight = height ? (height+'px') : this._CONTAINER_HEIGHT,
			duration = 0.3;

		opts = glow.lang.apply({
			tween: glow.tweens.easeBoth()
		}, opts);

		if (action === "up") {
			// give the element layout in IE
			if (glow.env.ie < 8) {
				this._$overlayContainer.css('zoom', 1);
			}
			completeHeight = 0;
			fromHeight = setHeight;
		} else if (action === "down") {
			fromHeight = 0;
			completeHeight = setHeight;
		}
		animation = glow.anim.css(this._$overlayContainer, duration, {
			'height': {from: fromHeight, to: completeHeight}
		}, opts);

		return animation;
	},
	
	/**
	 * toggle the overlay container
	 */
	toggleContainer: function(height) {
		return this._isOpen ? this.slideup(height) : this.slidedown(height);
	},
	
	/**
	 * is the container open?
	 * @returns {boolean}
	 */
	isOpen: function() {
		return this._isOpen;
	}
		
};

