// Ultimate Garage v1

var _GARAGE = null; //Have the flash instructions been viewed?

function buttonOver(imageID){
	var parentID = "ug_garage"+imageID;
	var heading = document.getElementsByClassName('ug_heading',parentID);
	heading[0].style.textDecoration = "underline";
}

function buttonOut(imageID){
	var parentID = "ug_garage"+imageID;
	var heading = document.getElementsByClassName('ug_heading',parentID);
	heading[0].style.textDecoration = "none";
}

function loadFlash(movie){
	_GARAGE = Get_Cookie('GARAGE');
	if(movie == "great"){
		var fo = new FlashObject("flash/garage.swf", "flsh_movie", "530", "555", "7", "#447233");
		fo.addVariable("MOVIE","great");
	}else if(movie == "ultimate"){
		var fo = new FlashObject("flash/garage.swf", "flsh_movie", "530", "555", "7", "#447233");
		fo.addVariable("MOVIE","ultimate");
	}
	fo.addParam("quality", "high");
	fo.addParam("wmode", "transparent");
	if (HomeDepot.linkParams != undefined) {
		if(HomeDepot.linkParams.length > 0){
			fo.addVariable("HD_LINK_PARAMS",escape(HomeDepot.linkParams));
		}
	}
	if(_GARAGE != null){
		fo.addVariable("VIEWED","true");
	}
	fo.setAltContent('<img src="images/flashbackup/homepage_generic.jpg" alt="" />');
	$('garage_selector').style.display = "none";
	$('flash_content').style.display = "block";
	fo.write("flash_content");
}

function openHDTV(videoID){
	window.open('http://www6.homedepot.com/tv/hdtv_player.html?videoID='+videoID,'hdtv','width=800,height=575');	
	
}

function loadQuery(){
	var query = location.search.substring(1).toQueryParams();
	var garage = query['g'];
	if(garage == "great"){
		$('garage_selector').style.display = "none";
		loadFlash('great');	
		buttonOver('Btn1');
		$('Btn1').style.backgroundImage = "url(images/ug_garageBtn1_over.jpg)";	
		$('great_link').onmouseout = null;
		$('great_link').onmouseover = null;
	}else if(garage == "ultimate"){
		$('garage_selector').style.display = "none";
		loadFlash('ultimate');	
		buttonOver('Btn2');
		$('Btn2').style.backgroundImage = "url(images/ug_garageBtn2_over.jpg)";	
		$('ultimate_link').onmouseout = null;
		$('ultimate_link').onmouseover = null;
	}
}

function loadPage(garageType){
	var query = location.search.substring(1);
	var params = query.toQueryParams();
	if(garageType == "great"){
		window.location = "index.html?g=great" + "&cm_sp=THD_Marketing-_-UltGarage07-_-leftnav-_-Great_Garage_Home";
	}else{
		window.location = "index.html?g=ultimate" + "&cm_sp=THD_Marketing-_-UltGarage07-_-leftnav-_-Ultimate_Garage_Home";
	}
}

//Usage Set_Cookie( 'GARAGE', 'true', 30, '/', '', '' );
function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
	
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function instructionsViewed(){
	//alert("Set Cookie");
	Set_Cookie( 'GARAGE', 'true', 30, '/', '', '' );
}