/**
 * @author Stan Carrico, WHITTMANHART Interactive
 * July, 2009
 * changelog :: 07/28 - updated swf embed height to 630px //SC
 * changelog :: 8/5/09 - updated search validation
 */

/* get context */
var host = window.location.host;
var environment = "www";
if(host == "wip.wcm.harley-davidson.com")
	environment = "wip.wcm";
else if(host == "stage.wcm.harley-davidson.com")
	environment = "stage.wcm";
/* end get context */

//GLOBAL VARS
var linkArray = new Array();
var domLinks = new Array();
var docBody;

// YUI shorthand
var YUC = YAHOO.util.Connect;
var YUD = YAHOO.util.Dom; 
var YUE = YAHOO.util.Event;
var YUS = YAHOO.util.StyleSheet;

YUS('homeTemp').set("#" + 'home_source', {
    display : "none"
});

if (typeof home == "undefined" || !home) {
	var home = {};
}

//Scripts from page shell
function getControllerPath() {return 'http://www.harley-davidson.com/wcm/cwp/controller.h-d';}
function validate_search_query(f) {if (f.q.value=="Search H-D") {f.q.value="*";} else {if (f.q.value=="SEARCH") {f.q.value="*";}}}
var hasVB = false;
function getStandardQueryParams(){return 'locale=en_US&bmLocale=en_US';}

if (typeof WCS == "undefined" || !WCS) {
    var WCS = {};
}
if (typeof WCS.data == "undefined" || !WCS.data) {
    WCS.data = {};
    WCS.data.Timestamp = 1245856413341;
}

var sTimestamp = WCS.data.Timestamp;

for (var i = 0; i < flashMovieWithLinksArray.length; i++) {var movieName = flashMovieWithLinksArray[i].movieName;var xpos = findPosXByName(movieName);var ypos = findPosYByName(movieName);for (var j = 0; j < flashMovieWithLinksArray[i].linkArray.length; j++) {var linkId = flashMovieWithLinksArray[i].linkArray[j].linkId;document.write("<a style=\"color:#333333;text-decoration: none;cursor: default;\" href=\"javascript:_hbLink('" + linkId + "', '', '" + xpos + ", " + ypos + ", " + itemWidth + ", " + itemHeight + "')\">&nbsp;&nbsp;&nbsp;&nbsp;</a>");}document.write("<br/>");} 

var _hbEC=0;_hbE=new Array;
function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");
hbx.vpc="HBX0200u";
hbx.gn="webr.harley-davidson.com"

if ((environment == 'wip.wcm') || (environment == 'stage.wcm')) {
hbx.acct="DM5105291PFM10EN3";
} 
else {
hbx.acct="DM5201108HDV10EN3";
}



hbx.pn="home.html";hbx.mlc="/Home";hbx.pndef="title";hbx.ctdef="full";hbx.fv="";hbx.lt="none";hbx.dlf="n";hbx.dft="n";hbx.elf="n";hbx.seg="";hbx.fnl="";hbx.cmp="";hbx.cmpn="";hbx.dcmp="";hbx.dcmpn="";hbx.dcmpe="";hbx.dcmpre="";hbx.hra="";hbx.hqsr="";hbx.hqsp="";hbx.hlt="";hbx.hla="";hbx.gp="";hbx.gpn="";hbx.hcn="";hbx.hcv="";hbx.cp="null";hbx.cpd="";hbx.ci="";hbx.hc1="";hbx.hc2="";hbx.hc3="";hbx.hc4="";hbx.hrf="";hbx.pec="";
//nav preload JSP output
var utilImg0false=new Image();utilImg0false.src='/en_US/Media/images/Navigation/Sitenav/Dealers/dl_global_dark_off.gif';var utilImg0true=new Image();utilImg0true.src='/en_US/Media/images/Navigation/Sitenav/Dealers/dl_global_dark_on.gif';var utilImg1false=new Image();utilImg1false.src='/en_US/Media/images/Navigation/Sitenav/Utility/faq_global_dark_off.gif';var utilImg1true=new Image();utilImg1true.src='/en_US/Media/images/Navigation/Sitenav/Utility/faq_global_dark_on.gif';var utilImg2false=new Image();utilImg2false.src='/en_US/Media/images/Navigation/Sitenav/Utility/contact_global_dark_off.gif';var utilImg2true=new Image();utilImg2true.src='/en_US/Media/images/Navigation/Sitenav/Utility/contact_global_dark_on.gif';var utilImg3false=new Image();utilImg3false.src='/en_US/Media/images/Navigation/Sitenav/Utility/cart_global_dark_off.gif';var utilImg3true=new Image();utilImg3true.src='/en_US/Media/images/Navigation/Sitenav/Utility/cart_global_dark_on.gif';var utilImg4false=new Image();utilImg4false.src='/en_US/Media/images/Navigation/Sitenav/Utility/list_global_dark_off.gif';var utilImg4true=new Image();utilImg4true.src='/en_US/Media/images/Navigation/Sitenav/Utility/list_global_dark_on.gif';var utilImg5false=new Image();utilImg5false.src='/en_US/Media/images/Navigation/Sitenav/Utility/myp_global_dark_off.gif';var utilImg5true=new Image();utilImg5true.src='/en_US/Media/images/Navigation/Sitenav/Utility/myp_global_dark_on.gif';var utilImg6false=new Image();utilImg6false.src='/en_US/Media/images/Navigation/Sitenav/Utility/logout_global_dark_off.gif';var utilImg6true=new Image();utilImg6true.src='/en_US/Media/images/Navigation/Sitenav/Utility/logout_global_dark_on.gif';var navImg0false=new Image();navImg0false.src='/en_US/Media/images/Navigation/Sitenav/Motorcycles/mc_global_dark_off.gif';var navImg0true=new Image();navImg0true.src='/en_US/Media/images/Navigation/Sitenav/Motorcycles/mc_global_dark_on.gif';var navImg1false=new Image();navImg1false.src='/en_US/Media/images/Navigation/Sitenav/Experience/goab_global_dark_off.gif';var navImg1true=new Image();navImg1true.src='/en_US/Media/images/Navigation/Sitenav/Experience/goab_global_dark_on.gif';var navImg2false=new Image();navImg2false.src='/en_US/Media/images/Navigation/Sitenav/A_and_A/aa_global_dark_off.gif';var navImg2true=new Image();navImg2true.src='/en_US/Media/images/Navigation/Sitenav/A_and_A/aa_global_dark_on.gif';var navImg3false=new Image();navImg3false.src='/en_US/Media/images/Navigation/Sitenav/Experience/exv2_global_dark_off.gif';var navImg3true=new Image();navImg3true.src='/en_US/Media/images/Navigation/Sitenav/Experience/exv2_global_dark_on.gif';var navImg4false=new Image();navImg4false.src='/en_US/Media/images/Navigation/Sitenav/Experience/ow_global_dark_off.gif';var navImg4true=new Image();navImg4true.src='/en_US/Media/images/Navigation/Sitenav/Experience/ow_global_dark_on.gif';var navImg5false=new Image();navImg5false.src='/en_US/Media/images/Navigation/Sitenav/Experience/mu_global_dark_off.gif';var navImg5true=new Image();navImg5true.src='/en_US/Media/images/Navigation/Sitenav/Experience/mu_global_dark_on.gif';var navImg6false=new Image();navImg6false.src='/en_US/Media/images/Navigation/Sitenav/Company/cov2_global_dark_off.gif';var navImg6true=new Image();navImg6true.src='/en_US/Media/images/Navigation/Sitenav/Company/cov2_global_dark_on.gif';
Poll();
//end scripts from page shell


YAHOO.util.Event.onDOMReady(function(){		

	home.initPage();

});

home = {
	
	initPage : function (){

		domLinks = YUD.getElementsBy(function(el){return true;},'a','home_source');
		
		for (var i=0; i<domLinks.length; i++) {
			linkArray[i] = {
				name: domLinks[i].name,
				href: domLinks[i].href,
				onclick: domLinks[i].onclick,
				target: domLinks[i].target
				};
			domLinks[i].href = "event:" + i;
			domLinks[i].onclick = "";
		}		
		
		home.initFlash();
		home.initFlashNav();
		home.profile.initProfile();		
		
	},
	
	initFlash : function (){
		
		flashvars = {};
		params = {
			wmode: "opaque"
		};
		attributes = {
			id: "home_flash_app",
			name: "home_flash_app"
		};
		
		//swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)
		swfobject.embedSWF('/en_US/Media/flash/Apps/US_homepage/HD_Homepage.swf', 'home_flash', '980', '630', '9.0.115.0', '',flashvars,params,attributes,home.embedCallback);	
		
	},
	embedCallback : function(response){
		
		if(response.success !== true){
			YUS('homeTemp').disable();
			for (var i=0; i<domLinks.length; i++) {
				domLinks[i].href = linkArray[i].href;
				domLinks[i].onclick = linkArray[i].onclick;
			}
		}
		
	},
	initFlashNav : function (){
		
		var hd_globalnav_0 = new SWFObj("globalnav_0_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_0.setAttribute("FlashVars","section=0&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_0.setAttribute("srcVars","section=0&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_0.setAttribute("style","z-index:10"); 
		hd_globalnav_0.outputHTML();
		document.getElementById("globalnav_0_container").style.visibility = "visible"; 
		postDetectionResults(hd_globalnav_0);
		
		var hd_globalnav_1 = new SWFObj("globalnav_1_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_1.setAttribute("FlashVars","section=1&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_1.setAttribute("srcVars","section=1&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_1.setAttribute("style","z-index:10"); 
		hd_globalnav_1.outputHTML();
		document.getElementById("globalnav_1_container").style.visibility = "visible"; 
		
		var hd_globalnav_2 = new SWFObj("globalnav_2_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_2.setAttribute("FlashVars","section=2&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_2.setAttribute("srcVars","section=2&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_2.setAttribute("style","z-index:10"); 
		hd_globalnav_2.outputHTML();
		document.getElementById("globalnav_2_container").style.visibility = "visible"; 
		
		var hd_globalnav_3 = new SWFObj("globalnav_3_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_3.setAttribute("FlashVars","section=3&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_3.setAttribute("srcVars","section=3&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_3.setAttribute("style","z-index:10"); 
		hd_globalnav_3.outputHTML();
		document.getElementById("globalnav_3_container").style.visibility = "visible"; 
		
		var hd_globalnav_4 = new SWFObj("globalnav_4_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_4.setAttribute("FlashVars","section=4&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_4.setAttribute("srcVars","section=4&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_4.setAttribute("style","z-index:10"); 
		hd_globalnav_4.outputHTML();
		document.getElementById("globalnav_4_container").style.visibility = "visible"; 
		
		var hd_globalnav_5 = new SWFObj("globalnav_5_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_5.setAttribute("FlashVars","section=5&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_5.setAttribute("srcVars","section=5&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_5.setAttribute("style","z-index:10"); 
		hd_globalnav_5.outputHTML();
		document.getElementById("globalnav_5_container").style.visibility = "visible"; 
		
		var hd_globalnav_6 = new SWFObj("globalnav_6_container","nav_EX_intl","/swf/","5","213","700","gray",false,"playerProductInstall","213","700"); 
		hd_globalnav_6.setAttribute("FlashVars","section=6&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_6.setAttribute("srcVars","section=6&bmLocale=en_US&id=0901473080648a64&tStamp=" + sTimestamp); 
		hd_globalnav_6.setAttribute("style","z-index:10"); 
		hd_globalnav_6.outputHTML();
		document.getElementById("globalnav_6_container").style.visibility = "visible"; 
		
	}	

};


home.profile = {
	
	/** 
	 * This method will look at the profile login state of the user and
	 * by that determine which navigation profile buttons to display, and
	 * what URL to attache to those buttons
	 * 
	 * @method initProfile
	 * @return none
	 */
	initProfile: function(){			
		
		// set environment options
		var profilePrefix;
		if(environment == "wip.wcm" || environment == "stage.wcm")
			profilePrefix = "stageprofile";		
		else 
			profilePrefix = "profile";			
		
		// login URL
		var loginURL = "https://" + profilePrefix + ".harley-davidson.com/cpapp/profile/indexPage.h-d?locale=en_US&bmLocale=en_US";
		loginURL += "&req_uri=http://" + environment + ".harley-davidson.com/en_US/Content/Pages/home.html";		
		loginURL += "&ret_uri=http://" + environment + ".harley-davidson.com/wcm/il/init_session.h-d";
		
		// already logged in URL
		var alreadyLoggedInURL = "https://" + profilePrefix + ".harley-davidson.com/cpapp/profile/indexPage.h-d?locale=en_US&bmLocale=en_US";
		alreadyLoggedInURL += "&req_uri=http://" + environment + ".harley-davidson.com/en_US/Content/Pages/home.html";
		alreadyLoggedInURL += "&ret_uri=http://" + environment + ".harley-davidson.com/wcm/il/init_session.h-d";
	
		// logout URL
		var logoutURL = "https://" + profilePrefix + ".harley-davidson.com/cpapp/profile/logoutPage.h-d?locale=en_US&bmLocale=en_US";
		logoutURL += "&req_uri=http://" + environment + ".harley-davidson.com/en_US/Content/Pages/home.html";
		logoutURL += "&ret_uri=http://" + environment + ".harley-davidson.com/wcm/il/kill_session.h-d";		
		
		// check the cookie value and forward to correct helper
		// function to change URL, and hide/display appropriate options
		if(document.cookie.match("WC_PROFILEUSER_AUTH=")){			
			home.profile.displayLogout(logoutURL, alreadyLoggedInURL);						
		}					
		else if(document.cookie.match("WC_PROFILEUSER_EMAIL=")){		
			home.profile.displaySoftLogin(alreadyLoggedInURL);			
		} 					
		else{				
			home.profile.displayLogin(loginURL);	
		} 				
		
	}, // end initProfile
	
	/** 
	 * This method will be exectuted when the user is in the 
	 * soft login state. We will reset the URL as well as hide 
	 * the logout button if not already
	 * 
	 * @method displaySoftLogin
	 * @return none
	 */
	displaySoftLogin: function(){
		
		// hide the logout button
		var hideEls = YAHOO.util.Dom.getElementsByClassName("logoutButton", "td");		
		for(var x=0; x<hideEls.length; x++){
			hideEls[x].style.display = "none";			
		}		
			
		// set the URL to the online profile button
		var profileLoginEl = document.getElementById("profileLogin");
		profileLoginEl.href = url;			
	}, // end displaySoftLogin
	
	/** 
	 * This method will be exectuted when the user is not logged in.
	 * We will reset the URL as well as hide the logout button if 
	 * not already
	 * 
	 * @method displayLogin
	 * @return none
	 */
	displayLogin: function(url){		
		
		// hide the logout button
		var hideEls = YAHOO.util.Dom.getElementsByClassName("logoutButton", "td");		
		for(var x=0; x<hideEls.length; x++){
			hideEls[x].style.display = "none";			
		}	
		
		// set the URL to the online profile button		
		var profileLoginEl = document.getElementById("profileLogin");
		profileLoginEl.href = url;	
						
	}, // end displayLogin
	
	/** 
	 * This method will be exectuted when the user is logged in.
	 * We will reset the URL as well as display the logout button if 
	 * not already
	 * 
	 * @method displayLogout
	 * @return none
	 */
	displayLogout: function(logoutURL, alreadyLoggedInURL){			
		
		// show the logout button
		var showEls = YAHOO.util.Dom.getElementsByClassName("logoutButton", "td");		
		for(var x=0; x<showEls.length; x++){
			showEls[x].style.display = "inline-table";			
		}			
		
		// set the URL to the logout button
		var profileLogoutEl = document.getElementById("profileLogout");
		profileLogoutEl.href = logoutURL;
		
		// set the URL to the online profile button
		var profileLoginEl = document.getElementById("profileLogin");
		profileLoginEl.href = alreadyLoggedInURL;		
	} // end displayLogout

};





