function setSWFByContainer(selectors)
{
	//document.title = "run function setSWFByContainer";
	if (typeof selectors != 'string') return false;
	$selectors = $(selectors);
	if (selectors.length==0) return false;
	$embed = $selectors.find('embed');
	if ($embed.length==0) return false;
	if ($embed.length==1)
	{
		if (!$embed.attr('id')) $embed.attr('id', $selectors.attr('id')+'-embed');
		swfobject.registerObject($embed.attr('id'), "9.0.0", "/common/expressInstall.swf");
	}
	else
	{
		$embed.each(function(index){
			if (!$(this).attr('id')) $(this).attr('id',$selectors.attr('id')+'-embed'+index);
			swfobject.registerObject($(this).attr('id'), "9.0.0", "/common/expressInstall.swf");
		});
	}
}

function getFlashMovieObject(movieName)
{
	if (window.document[movieName]) {
		return window.document[movieName];
	} else {
		if (navigator.appName.indexOf("Microsoft Internet") == -1) {
			if (document.embeds && document.embeds[movieName]) return document.embeds[movieName];
		} else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) 
			return document.getElementById(movieName);
	}

}

function showroomDolabel(target, emb_id) {
	var movieInstance = getFlashMovieObject(emb_id);
	if (movieIsLoaded(movieInstance)) {
		movieInstance.SetVariable("interacted", true);
		movieInstance.SetVariable("chosenModel", target);
		movieInstance.TGotoLabel("_level0/", "go");
	}
}

function movieIsLoaded(theMovie) {
	if (theMovie != null) {
		return theMovie.PercentLoaded() == 100;
	} else {
		return false;
	}
}

var heroExpandVD = {
	flashElId: '#expandDemo',
	containerElId: '#expanding-hero, #header-visualization',
	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.height();
		var collapseHeight = container.eq(0).height();
		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)
		var configset = config || false;
		if (configset)
		{
			$elem.css({
				//height: config.startHeight + 'px',
				overflow: 'hidden'
			});
			if ($elem.length==1)
			{
				$elem.animate({height:config.endHeight+'px'},{duration:config.duration});
			}
			else if ($elem.length>1)
			{
				$elem.each(function(i){
					$(this).animate({height:config.endHeight+'px'},{duration:config.duration});
				});
			}
		}
		
	}
};
