


/**
	expanding hero area for flash content
	called from flash movie with hero.expand(duration) / hero.collapse(duration)
	where duration is in msec
 */
var heroExpandVD = {
	flashElId: 'expandDemo',
	containerElId: 'expanding-hero',
	defaultExpandDuration: 300,
	defaultCollapseDuration: 300,
	elementProperties: null,
	
	// duration is in ms
	expand: function (duration) {
		var ep = this.getElementProperties();
		if (ep === null) return false;
		this.animate(ep.container, {
			duration: duration || this.defaultExpandDuration,
			endHeight: ep.expandHeight,
			startHeight: ep.collapseHeight
		});
		return true;
	},
	collapse: function (duration) {
		var ep = this.getElementProperties();
		if (ep === null) return false;
		this.animate(ep.container, {
			duration: duration || this.defaultExpandDuration,
			startHeight: ep.expandHeight,
			endHeight: ep.collapseHeight
		});
		return true;
	},
	getElementProperties: function () {
		if (this.elementProperties) return this.elementProperties;
		
		var flashEl = $(this.flashElId);
		var container = $(this.containerElId);
		if (!container || !flashEl) return null;
		
		var expandHeight = flashEl.getHeight();
		var collapseHeight = container.getHeight();
		if (expandHeight > 0 && collapseHeight > 0) {
			return this.elementProperties = {
				container: container,
				expandHeight: expandHeight,
				collapseHeight: collapseHeight
			};
		}
		return null;
	},
	animate: function (elem, config) {
		// config: startHeight (px), endHeight (px), duration (ms)
		config = config || {};
		var timer,          // setInterval ID
			interval,       // duration of each frame
			frameCount,     // number for frames
			step,           // increment per step
			i = 0;
			
		interval = 15;
		frameCount = config.duration / interval;
		step = (config.endHeight - config.startHeight) / frameCount;
		
		elem.setStyle({
			height: config.startHeight + 'px',
			overflow: 'hidden'
		});
		timer = setInterval(run, interval);
		
		function run () {
			if (i < frameCount) {
				i++;
				elem.setStyle({ height: (config.startHeight + step * i) + 'px' });
			}
			else {
				clearInterval(timer);
				elem.setStyle({ height: config.endHeight + 'px' });
			}
		}
	}
};




// end of file
document.observe("dom:loaded", generalJsInit);
