﻿//// specs popup window
var checkPrintSpecs = setInterval(function(){

	if(!document.getElementById("my10PrintSpecs"))
		return false;
	document.getElementById("my10PrintSpecs").onclick = function(ev)
	{
		if(!ev) 
			ev = window.event;
		var el = ev.srcElement || ev.target;
		el = (el.tagName != "A") ? el.parentNode : el;
		var url = el.href;
		var params = "width=628, height=650, scrollbars=yes";
		window.open(url,"specs", params);
		return false;
	}
	clearInterval(checkPrintSpecs);
}, 100)

if (typeof MY10 == "undefined" || !MY10) {
    var MY10 = {};
}

if (typeof flashpath == "undefined" || !flashpath) {
    var flashpath;
}
// variables
var YUC = YAHOO.util.Connect;
var YUD = YAHOO.util.Dom;
var YUE = YAHOO.util.Event;
var YUS = YAHOO.util.StyleSheet;

// Default values
var locale;
var market;
var market_type;
var language;
var pricing_file_ext;
var pvsView = [0];
var dwp_price;
var dwp_active;
var dwp;
var flaDwpShowPrice;
var selectedFamily = "";
var selectedModel = "";
var pageView = "MY10-SEO";
var my10FinderInit = false;

var my10Wrapper = "my10_wrapper";
var my10Container = "my10_container";
var finderContainer = "my10_finder";
var finderWrapper = "my10_finder_wrapper";
var my10SideCar = "my10_sidecar_wrapper";
var my10MarketCookie = "my10Market_";
var marketSelectorData = "marketSelectorDataContainer";
var my10CompareContainer = "my10_compare_wrapper";
var my10EstimatePaymentContainer = "my10_estimatePayment_wrapper";
var my10Loader = "my10_loader";
var my10Promos = "MY10_Promos";

var objMy10;
var objFinder;
var idMy10 = "MY10_flash";
var idFinder = "MY10_finder";
var isFlashActive = false;

// Deep Links
var isCompareDeepLink;
var isEstPayDeepLink;

// SWFAddress
var prevSWFAddress;
var swfId = "MY10_flash";

//GLOBALS
var my10PromoData = "my10_promoData";
var my10Promos = "MY10_Promos";

YUS('MY10PromosTemp').set("#" + my10PromoData, {
    display: "none"
});
YUS('MY10PromosTemp').set("#" + my10Promos, {
    position: "relative"
});

// PROMOS link data
var linkArray = new Array();
var domLinks = new Array();
var docBody;

// set temp styles to hide main container
YUS('MY10Temp').set("#" + my10Container, {
    display: "none"
});

// locales that need a market selector
var marketSelectorLocales = ["en_xx", "en_au", "de_de", "nl_be", "fr_be", "en_aa"];

// hash table were key is locale and value
// is the market type of that locale
var localeHash = new Object();
localeHash["en_us"] = "dom";
localeHash["en_aa"] = "int";
localeHash["en_au"] = "int";
localeHash["en_ca"] = "dom";
localeHash["en_gb"] = "int";
localeHash["en_in"] = "int";
localeHash["en_xx"] = "int";
localeHash["en_zz"] = "int";
localeHash["en_nz"] = "int"; //added "en_nz" as "int" value
localeHash["da_dk"] = "int";
localeHash["de_de"] = "int";
localeHash["de_ch"] = "int";
localeHash["es_es"] = "int";
localeHash["es_mx"] = "dom";
localeHash["fr_be"] = "int";
localeHash["fr_ca"] = "dom";
localeHash["fr_ch"] = "int";
localeHash["fr_fr"] = "int";
localeHash["it_ch"] = "int";
localeHash["it_it"] = "int";
localeHash["nl_be"] = "int";
localeHash["no_no"] = "int";
localeHash["pt_br"] = "int";
localeHash["pl_pl"] = "int";

// market type hash
var marketTypeHash = new Object();
marketTypeHash["ca"] = "ca";
marketTypeHash["mx"] = "mx";  // changed camx to mx, WH QA issue 25560 - chad norwood
marketTypeHash["gb"] = "hde";
marketTypeHash["us"] = "us";
marketTypeHash["ar"] = "la";
marketTypeHash["aw"] = "la";
marketTypeHash["at"] = "hde";
marketTypeHash["bs"] = "la";
marketTypeHash["bh"] = "hde";
marketTypeHash["be"] = "hde";
marketTypeHash["bz"] = "la";
marketTypeHash["br"] = "la";
marketTypeHash["bn"] = "ap";
marketTypeHash["ky"] = "la";
marketTypeHash["cl"] = "la";
marketTypeHash["co"] = "la";
marketTypeHash["cr"] = "la";
marketTypeHash["hr"] = "hde";
marketTypeHash["cy"] = "hde";
marketTypeHash["cz"] = "hde";
marketTypeHash["dk"] = "hde";
marketTypeHash["do"] = "la";
marketTypeHash["ec"] = "la";
marketTypeHash["eg"] = "hde";
marketTypeHash["sv"] = "la";
marketTypeHash["fi"] = "hde";
marketTypeHash["fr"] = "hde";
marketTypeHash["de"] = "hde";
marketTypeHash["uk"] = "hde";
marketTypeHash["gr"] = "hde";
marketTypeHash["gu"] = "us";
marketTypeHash["gt"] = "la";
marketTypeHash["hn"] = "la";
marketTypeHash["hk"] = "ap";
marketTypeHash["hu"] = "hde";
marketTypeHash["is"] = "hde";
marketTypeHash["id"] = "ap";
marketTypeHash["ie"] = "hde";
marketTypeHash["il"] = "hde";
marketTypeHash["it"] = "hde";
marketTypeHash["jm"] = "la";
marketTypeHash["kp"] = "ap";
marketTypeHash["kw"] = "hde";
marketTypeHash["lv"] = "hde";
marketTypeHash["lu"] = "hde";
marketTypeHash["my"] = "ap";
marketTypeHash["ma"] = "hde";
marketTypeHash["nl"] = "hde";
marketTypeHash["nz"] = "nz"; //A.Dove 12-30-09:Changed "aunz" to "nz" 
marketTypeHash["ni"] = "la";
marketTypeHash["no"] = "hde";
marketTypeHash["om"] = "hde";
marketTypeHash["pa"] = "la";
marketTypeHash["pl"] = "hde";
marketTypeHash["pt"] = "hde";
marketTypeHash["pr"] = "us";
marketTypeHash["qa"] = "hde";
marketTypeHash["ru"] = "hde";
marketTypeHash["sa"] = "hde";
marketTypeHash["sg"] = "ap";
marketTypeHash["sk"] = "hde";
marketTypeHash["si"] = "hde";
marketTypeHash["za"] = "hde";
marketTypeHash["es"] = "hde";
marketTypeHash["se"] = "hde";
marketTypeHash["ch"] = "hde";
marketTypeHash["tw"] = "ap";
marketTypeHash["th"] = "ap";
marketTypeHash["tr"] = "hde";
marketTypeHash["ae"] = "hde";
marketTypeHash["ua"] = "hde";
marketTypeHash["uy"] = "la";
marketTypeHash["ve"] = "la";
marketTypeHash["vg"] = "la";
marketTypeHash["au"] = "au";
marketTypeHash["ap"] = "ap";
marketTypeHash["la"] = "la";
marketTypeHash["zz"] = "hde";

// Pricing Hash
var pricingHash = new Object();
pricingHash["ca"] = "ca";
pricingHash["mx"] = "default";
pricingHash["gb"] = "uk";
pricingHash["us"] = "us";
pricingHash["ar"] = "default";
pricingHash["aw"] = "default";
pricingHash["at"] = "at";
pricingHash["bs"] = "default";
pricingHash["bh"] = "default";
pricingHash["be"] = "be";
pricingHash["bz"] = "default";
pricingHash["br"] = "default";
pricingHash["bn"] = "default";
pricingHash["ky"] = "default";
pricingHash["cl"] = "default";
pricingHash["co"] = "default";
pricingHash["cr"] = "default";
pricingHash["hr"] = "default";
pricingHash["cy"] = "default";
pricingHash["cz"] = "default";
pricingHash["dk"] = "dk";
pricingHash["do"] = "default";
pricingHash["ec"] = "default";
pricingHash["eg"] = "default";
pricingHash["sv"] = "default";
pricingHash["fi"] = "default";
pricingHash["fr"] = "fr";
pricingHash["de"] = "de";
pricingHash["uk"] = "uk";
pricingHash["gr"] = "default";
pricingHash["gu"] = "default";
pricingHash["gt"] = "default";
pricingHash["hn"] = "default";
pricingHash["hk"] = "default";
pricingHash["hu"] = "default";
pricingHash["is"] = "default";
pricingHash["id"] = "default";
pricingHash["ie"] = "default";
pricingHash["il"] = "default";
pricingHash["it"] = "it";
pricingHash["jm"] = "default";
pricingHash["kp"] = "default";
pricingHash["kw"] = "default";
pricingHash["lv"] = "default";
pricingHash["lu"] = "default"; //A.Dove-changed from "lu" to "default"
pricingHash["my"] = "default";
pricingHash["ma"] = "default";
pricingHash["nl"] = "nl";
pricingHash["nz"] = "nz"; // temp set to nz
pricingHash["ni"] = "default";
pricingHash["no"] = "no";
pricingHash["om"] = "default";
pricingHash["pa"] = "default";
pricingHash["pl"] = "default";
pricingHash["pt"] = "default";
pricingHash["pr"] = "default";
pricingHash["qa"] = "default";
pricingHash["ru"] = "default";
pricingHash["sa"] = "default";
pricingHash["sg"] = "default";
pricingHash["sk"] = "default";
pricingHash["si"] = "default";
pricingHash["za"] = "default";
pricingHash["es"] = "es";
pricingHash["se"] = "default";
pricingHash["ch"] = "ch";
pricingHash["tw"] = "default";
pricingHash["th"] = "default";
pricingHash["tr"] = "default";
pricingHash["ae"] = "default";
pricingHash["ua"] = "default";
pricingHash["uy"] = "default";
pricingHash["ve"] = "default";
pricingHash["vg"] = "default";
pricingHash["au"] = "au"; // temp set to au
pricingHash["ap"] = "default";
pricingHash["la"] = "default";
pricingHash["zz"] = "default";

var familyNameHash = new Object();
familyNameHash["cv"] = "cvo";
familyNameHash["dy"] = "dyna";
familyNameHash["so"] = "softail";
familyNameHash["sp"] = "sportster";
familyNameHash["to"] = "touring";
familyNameHash["tr"] = "trike";
familyNameHash["vr"] = "vrsc";

/* temp fix for 48, CVO until file dependency can be fixed */
var checkObject = setInterval(function(){
	if(typeof shareURLHash == "object" && typeof shareTitleHash == "object" && typeof shareDescHash == "object" && typeof hashCheck == "object" )
	{
		shareURLHash["/home/NB"] = "2010_Motorcycles/2010_motorcycles";
		
		shareURLHash["/model/xl1200x"] = "bike/forty_eight";
		shareTitleHash["/model/xl1200x"] = "2010 Forty-Eight® | Harley-Davidson USA";
		shareDescHash["/model/xl1200x"] = "This urban brawler features a fat front tire, steel peanut tank, a low-slung saddle, and comes ready to rip through any scene. See it at the official H-D site.";				
		//linkHash['xr1200x'] = "/model/xr1200x";
		hashCheck['XR1200X'] = 'model';	
		

		shareURLHash["/model/flhtcuse5"] = "bike/ultra_classic_electra_glide";
		shareTitleHash["/model/flhtcuse5"] = "CVO Ultra Classic Electra Glide® | Harley-Davidson USA";
		shareDescHash["/model/flhtcuse5"] = "The Harley-Davidson Ultra Classic® Electra Glide motorcycle has long-haul comfort, convenience,&#34; storage capacity. See it at the official H-D site.";				
		//linkHash['flhtcuse5'] = "/model/flhtcuse5";
		hashCheck['flhtcuse5'] = 'model';	
		
		clearInterval(checkObject); 	
	}	
}, 250)




YAHOO.util.Event.onDOMReady(function(){

	//check if it's a dwp page
	var isDwp = MY10.util.getRequestParam('dwp_dealerid');
	if(!isDwp && YUD.get(finderWrapper)){
		// fix first click problem
		setTimeout(function(){
			YUD.get(finderWrapper).innerHTML = "<div id=\"" + finderContainer + "\"></div>";         
		}, 2000)
	}
	
    // get the locale param		
	if (MY10.util.getRequestParam("locale")) {
		// check if it is valid locale if not set to en_US					
		if (localeHash[MY10.util.getRequestParam("locale").toLowerCase()]) {
			locale = MY10.util.getRequestParam("locale").toLowerCase();
		} else {
			locale = "en_us";
		}
	} else if (location.href.indexOf('.html')) {
		var winurl = location.href;
		winurl	= winurl.substr(winurl.indexOf('://')+3);
		var loc	= winurl.substr(winurl.indexOf('/')+1,5);
		if (localeHash[loc.toLowerCase()]) {
			locale	= loc.toLowerCase();
		} else {
			locale	= "en_us";
		}
	} else {
		locale = "en_us";
	}
    if (locale != "en_us" || Boolean(dwp)) {
        YUE.addListener("seoHeaderEN", "click", function(){
            document.location = "/en_US/Content/Pages/2010_Motorcycles/2010_Motorcycles.html?locale=en_US";
        });
        
        var el = YUD.get('my10PrintSpecs');
        if (el) {
            var params = "width=628, height=650, scrollbars=yes";
            var url = el.href;
            encodeURI(url);
            el.href = "javascript: void(0);";
            el.target = "specs";
            
            YUE.addListener("my10PrintSpecs", "click", function(){
                MY10.util.pageLink(url, 'specs', params);
            });
        }
        
        MY10.initPage();
    }
});

MY10 = {

    /**
     * This method will determine whether a market selector is needed or not
     * and in turn display the appropiate content/flash
     *
     * @method initPage
     * @return none
     */
    initPage: function(){
		
        //initialize swfAddress event monitor
        
        
        //	var eSpotContainer = my10PromoData;
        //	
        //	// grabs links from promo div and stores for link/tracking
        //	domLinks = YUD.getElementsBy(function(el){return true;},'a',eSpotContainer);
        //
        //	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,
        //			section: YUD.get(eSpotContainer).id
        //			};
        //		domLinks[i].href = "event:" + i;
        //		domLinks[i].onclick = "";
        //	}		
        
       // get the locale param
        if (MY10.util.getRequestParam("locale")) {
            // check if it is valid locale if not set to en_US					
            if (localeHash[MY10.util.getRequestParam("locale").toLowerCase()]) {
                locale = MY10.util.getRequestParam("locale").toLowerCase();
            } else {
                locale = "en_us";
            }
        } else if (location.href.indexOf('.html')) {
			var winurl = location.href;
			winurl	= winurl.substr(winurl.indexOf('://')+3);
			var loc	= winurl.substr(winurl.indexOf('/')+1,5);
			if (localeHash[loc.toLowerCase()]) {
				locale	= loc.toLowerCase();
			} else {
				locale	= "en_us";
			}
        } else {
			locale = "en_us";
		}
        
        // set location parameters
        language = locale.substring(0, 2);
        if (language == "da" || language == "no" || language == "pt") {
            language = "en";
        }
        market = locale.substring(3, 5); // will get reset if in marketSelector locale					
        // check if the locale needs a market selector
        var displayMarketSelector = MY10.isDisplayMarketSelector(locale);
        
        // check if there is a compare deep link if so set true
        isCompareDeepLink = MY10.util.getRequestParam("compare");
        
        // check if there is a estimate payment deep link if so set true
        isEstPayDeepLink = MY10.util.getRequestParam("estPay");
        
        //check for dwp page variable and set pricing var in flash true if regex for msrp tests out
        if (typeof dwp == "undefined" || !dwp) {
            dwp = false;
            dwp_active = false;
            dwp_price = false; // set hide flag to show = yes
        }
        
        if (dwp) {
            dwp_active = true;
            dwp_price = false;
            flaDwpShowPrice = false;
        }
        
        if (/msrp/gi.test(dwp)) {
            dwp_price = true;
            flaDwpShowPrice = true;
        }
        //end dwp param set
        
        // if the locale needs a market selector display it, if not display the flash
        if (displayMarketSelector) {
            var cookieValue = MY10.getMarketCookie();
            
            if (cookieValue) {
                // remove temp styles added earlier
                YAHOO.util.StyleSheet('MY10Temp').unset("#" + my10Container, 'display');
                market = MY10.getMarketCookie(); // reset market
                market_type = marketTypeHash[market];
                pricing_file_ext = pricingHash[market];
                //MY10.initFlash(my10Container, locale);
				initView();
            }
            else {
                // make AJAX request to get the market selector data file
                var marketSelectorFileName = "/en_US/Media/data/Apps/2010_Motorcycles/utility/marketSelector_" + locale + ".webxml";
                YUC.asyncRequest('GET', marketSelectorFileName, getMarketSelectorDataCallback);
            }
            
        }
        else{
            // set global params
            market_type = marketTypeHash[market];
            pricing_file_ext = pricingHash[market];
            
            // check if we should open the compare bike section			
            if (isCompareDeepLink) {
                MY10.openCompareSpecs("");
            }
            else 
                if (isEstPayDeepLink && (locale == "en_us")) {
                    MY10.openEstimatePayments();
                }
            
            // init the view selection process
			
			initView();
			            
            // remove the temp stylesheet
            YAHOO.util.StyleSheet('MY10Temp').unset("#" + my10Container, 'display');
        }
    },
    
    /**
     * This method checks if the selected locale is a locale that
     * needs a market selector
     *
     * @method isDisplayMarketSelector
     * @param  {String} locale  current locale
     * @return {boolean} display marketSelector
     */
    isDisplayMarketSelector: function(locale){
    
        for (var x = 0; x < marketSelectorLocales.length; x++) {
            if (marketSelectorLocales[x] == locale.toLowerCase()) 
                return true;
        }
        return false;
        
    }, // end isDisplayMarketSelector
    /**
     * This method checks if there is cookie set to which country
     * the user has selected
     *
     * @method getMarketCookie
     * @return {string} cookie value
     */
    getMarketCookie: function(){
    
        var my10Market = document.cookie.indexOf(my10MarketCookie + locale);
        
        if (my10Market < 0) 
            return null;
        else 
            return document.cookie.substring(my10Market + 17, my10Market + 19);
        
    }, // end getMarketCookie			
    /**
     * initFlash runs flash detection via swfObject 2.2 and creates a page embed if successful.
     *
     * @method initFlash
     * @param (string)el - string of HTML element to fill with embed tag
     * @param (string)locale - locale
     * @return {string} cookie value
     */
    initFlash: function(el, locale){
        
        var strContainerId = el;
        
        //reset page vars to match flash data semantics
        var country = market;
        
        /*
         * flashParmHash controls flash params for problem locales
         */
        var flashParmHash = {};
        //array order locale,market,language,country
        flashParmHash["en_gb"] = ["en_uk", "uk", "en", "uk"];
        flashParmHash["da_dk"] = ["en_dk", "hde", "en", "dk"];
        flashParmHash["no_no"] = ["en_no", "hde", "en", "no"];
        flashParmHash["en_aa"] = ["en_aa", "hde", "en", "uk"];
        flashParmHash["en_zz"] = ["en_uk", "hde", "en", "uk"];
        
        var flMarket = "";
        var flLocale = "";
        var flCountry = "";
        var flLanguage = "";
        
        //check locale for match to hash table and reset params if found
        if (flashParmHash[locale]) {
            flMarket = flashParmHash[locale][1];
            flLanguage = flashParmHash[locale][2];
            flCountry = flashParmHash[locale][3];
            flLocale = flashParmHash[locale][0];
        }
        else {
            flMarket = market;
            flLanguage = language;
            flCountry = country;
            flLocale = locale;
        }
        
        var dwpPrice = "no";
        //set yes no based on true (true show price / no don't hide) or false (false hide price / yes hide price)
        switch (flaDwpShowPrice) {
            case true:
                dwpPrice = "no";
                break;
                
            case false:
                dwpPrice = "yes";
                break;
        }
        
        var flashvars = {
            locale: flLocale,
            market: flMarket,
            market_type: market_type,
            language: flLanguage,
            country: flCountry,
            dwp_price: dwpPrice,
            dwp: dwp_active
        };
        
        var params = {
            wmode: 'opaque',
            bgcolor: '#333333',
			allowfullscreen:'true',
            allowscriptaccess: "always"
        };
        
        var attributes = {
            id: idMy10,
            name: idMy10
        };
        
        var path = '/en_US/Media/flash/2010_Motorcycles/MY10.swf';
        
        if (true == flashpath) {
            path = 'MY10.swf';
        }
        
        //embed statement should follow the format
        //swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)
        swfobject.embedSWF(path, strContainerId, '812', '546', '9.0.115.0', '', flashvars, params, attributes, MY10.my10FlashCallback);
        
		// to fix chrome and safari issue that's not loading the flash on dwp
		/*var isDwp = MY10.util.getRequestParam('dwp_dealerid');
		var browser = navigator.userAgent;
		if(isDwp && browser){
			if(browser.indexOf('Safari') != -1 || browser.indexOd('Chrome') != -1){
				console.log("Browser", browser);
				console.log("url", location.href);
			}
		}*/
        
    }, // end initFlash	
    /**
     * my10FlashCallback responds to MY10 embed method and sends in deep link for SEO pages.
     * @param {Object} response
     */
    my10FlashCallback: function(response){
        //register MY10 flash object with swfAddress
        SWFAddress.setId(idMy10);
        
        //check for DWP before promo init, and display static promo if necessary
        switch (dwp_active) {
            case true:
                var dealerId = MY10.util.getRequestParam("dwp_dealerid");
                var dwpFormQry = '&cwpws/dwp/make=Harley-Davidson&cwpws/dwp/model=&cwpws/dwp/year=2010&cwpws/dwp/model-code=' + selectedModel + '&cwpws/dwp/redirecturl=%2Fwcm%2FContent%2FPages%2F2010_Motorcycles%2F2010_motorcycles.jsp%3Flocale%3Den_US%26dwp_dealerid%3D' + dealerId + '%3Ddwp_pg=nb_model';
                
                var strPromo = '<img id="dwp_promo" border="0" src="/en_US/Media/images/Apps/2010_Motorcycles/promos/img_dwp_promos_2.jpg" alt="Contact Us For Additional Information"/>';
                YUD.get('my10_promos').innerHTML = strPromo;
                
                YUE.onAvailable('dwp_promo', function(){
                    YUS('dwp_active').set("#" + 'dwp_promo', {
                        cursor: "pointer"
                    });
                    YUE.addListener('dwp_promo', 'click', function(){
                        var dwpFormQry = '&cwpws/dwp/make=Harley-Davidson&cwpws/dwp/model=&cwpws/dwp/year=2010&cwpws/dwp/model-code=' + selectedModel + '&cwpws/dwp/redirecturl=%2Fwcm%2FContent%2FPages%2F2010_Motorcycles%2F2010_motorcycles.jsp%3Flocale%3Den_US%26dwp_dealerid%3D' + dealerId + '%3Ddwp_pg=nb_model';
                        var url = "/wcm/Content/Pages/2010_Motorcycles/dwp_2010_form.jsp?locale=en_US&dwp_dealerid=" + dealerId + "&dwp_pg=nb_model" + dwpFormQry;
                        //window.open (url,"dwp_contact","location=0,scrollbars=0,toolbar=0,menubar=0,resizable=0,width=500,height=600");
                        document.location.href = url;
                    });
                });
                
                break;
            case false:
                //call promo flash
                //MY10.initPromos();
                break;
                
        }
        
        //set page view to MY10-main
        pageView = "MY10-main";
        //store flash object
        objMy10 = response.ref;
		

			if(!response.success && typeof isNonFlashTracked == "undefined")
			{
				_hbPageView("non+flash","/Products/Motorcycles/2010s");	
				isNonFlashTracked = true;				
			}	
        
    },
    
    /**
     * This method initializes the promo flash. Also set up a listener to re-init promos based on app view state changes
     * @method initPromos
     * @param {Boolean} init controls whether method acts as init or callback
     */
    initPromos: function(initSwitch){
        var strContainerId = "my10_promos";
        
        var flashvars = {
            promoContainerID: 'my10_promoData'
        };
        
        var params = {
            wmode: 'opaque',
            bgcolor: '#333333',
            allowscriptaccess: "always"
        };
        
        var attributes = {
            id: 'MY10_Promos',
            name: 'MY10_Promos'
        };
        
        var path = '/en_US/Media/flash/2010_Motorcycles/MY10_Promos.swf';
        
        //embed statement should follow the format
        //swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)
        switch (isFlashActive) {
            case false:
                swfobject.embedSWF(path, strContainerId, '817', '100', '9.0.115.0', '', flashvars, params, attributes, MY10.embedPromosCallback);
                
                if (YUD.get("BottomPromosMain")) {
                    YUD.setStyle('BottomPromosMain', 'display', 'none');
                }
                break;
            case true:
                break;
                
            
			
			    
        };
            },
    /**
     * callback function for initPromos method flash embed statement
     *
     * @method MY10.embedPromosCallback
     * @param {Object} response
     */
    embedPromosCallback: function(response){
        isFlashActive = response.success;
        if (response.success !== true) {
            YUS('MY10PromosTemp').disable();
            //		    for (var i = 0; i < domLinks.length; i++) {
            //		        domLinks[i].href = "javascript:void(0)";
            //		        domLinks[i].target = "";
            //		        domLinks[i].name = i;
            //		        domLinks[i].onclick = function(){
            //		            MY10.app.getLink(this.name, 'Javascript', '', '');
            //		        };
            //		    }
        }
    },
    
    /**
     * This method initializes the promo flash. Also set up a listener to re-init promos based on app view state changes
     * @method initPromos
     * @param {Boolean} init controls whether method acts as init or callback
     */
    initFinder: function(){
    
        var strContainerId = finderContainer;
        
        var flashvars = {
            configXML: "siteQuiz.webxml",
            locale: "en_XX",
            cmsPath: "/en_US/Media/flash/2010_Motorcycles/my-dream-harley/",
            useLocalPath: "true"
        };
        
        var params = {
            wmode: 'opaque',
            bgcolor: '#333333',
            allowscriptaccess: "always"
        };
        
        var attributes = {
            id: idFinder,
            name: idFinder
        };
        
        var path = '/en_US/Media/flash/2010_Motorcycles/my-dream-harley/main.swf';
        
        //embed statement should follow the format
        //swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)
        swfobject.embedSWF(path, strContainerId, '812', '546', '9.0.115.0', '', flashvars, params, attributes, MY10.finderFlashCallback);
    },
    /**
     * finderFlashCallback responds to flash embed from initFinder
     */
    finderFlashCallback: function(response){
        SWFAddress.setId(idFinder);
        pageView = "MY10-finder";
        my10FinderInit = true;
        //SWFAddress.setHistory(false);
        //setTimeout("SWFAddress.setHistory(true)",1000);
    },
    
    /**
     * This method will open up the printable specs popup
     *
     * @method openPrintableSpecs
     * @return none
     */
    openPrintableSpecs: function(model){
        var params = "width=628, height=650, scrollbars=yes";
        var url = "/en_US/Media/data/Apps/2010_Motorcycles/html/specs/printable_specs.html?model=" + model;
        url += "&lang=" + language + "&market=" + market + "&market_type=" + market_type;
        url += "&pricingExt=" + pricing_file_ext + "&dwp=" + dwp + "&dwp_price=" + dwp_price;
        MY10.util.pageLink(url, '', params);

    }, // end openPrintableSpecs
    /**
     * This method will open up the compare specs popup
     *
     * @method openCompareSpecs
     * @return none
     */
    openCompareSpecs: function(model){
        MY10.openLoader();
        MY10.initCompare(model);
        MY10.hbx.track.generateHbxCode("comparebikes", "", model);
    }, // end openCompareSpecs
    /**
     * This method close the compare overlay when the
     * actual browser back button is clicked
     *
     * @method closeCompareSpecs
     * @return none
     */
    closeCompareSpecs: function(e){
        YUD.setStyle(my10CompareContainer, "display", "none");
        YUD.setStyle(my10Wrapper, "display", "block");
        MY10.compareSpecs.resetPageData();
    }, // end compare listener
    /**
     * This method will write the estimate payments display
     * to the DOM
     *
     * @method writeEstimatePayment
     * @return none
     */
    writeEstimatePayment: function(){
        var src = "/wcm/en_US/Content/Layouts/Pages/payment_estimator/PE_MY10.jsp?locale=en_US";
		
        var html = '<iframe id="estimatePaymentIframe" src="' + src + '" height="1240px" width="812px" frameborder="0" scrolling="no"></iframe>';
        
        // write to DOM
        YUD.get('my10_estimatePayment_wrapper').innerHTML = html;
        
        // since we don't have a handle on when the iFrame finishes loading
        // we will set a timeout before we remove the overlay
        window.setTimeout(function(){
            MY10.closeLoader();
            YUD.setStyle(my10EstimatePaymentContainer, "display", "block");
        }, 3000);
        MY10.hbx.track.generateHbxCode("estimator");
    }, // end writeEstimatePayment
    /**
     * This method will open up the estimate payments display
     *
     * @method openEstimatePayments
     * @return none
     */
    openEstimatePayments: function(model){
        if (hashCheck[model] == 'model') {
            var iFrame = YUD.get('estimatePaymentIframe').src
            var src = iFrame.src;
            src += YUD.get('estimatePaymentIframe').src = ""
			
        }
        //YUD.setStyle(my10Wrapper, "display", "none");// hide MY10 Flash	
        MY10.openLoader(); // open the loader overlay		
        MY10.writeEstimatePayment(); // write the estimate payment text	
    }, // end openEstimatePayments
    /**
     * This method will close the estimate payments display
     * and open the flash
     *
     * @method closeEstimatePayments
     * @return none
     */
    closeEstimatePayments: function(){
        SWFAddress.setValue("home/NB"); // redirect swf back to the home of the swf
        YUD.setStyle(my10EstimatePaymentContainer, "display", "none");
        //YUD.setStyle(my10Wrapper, "display", "block");		
    }, // end backEstimatePayments
    /**
     * This method get the sidecar HTMl based on the args
     * passed to the method, write the HTML into the page
     * and init it
     *
     * @method openSideCar
     * @param args - sidecar type
     * @return none
     */
    openSideCar: function(args){
        //YUD.setStyle(my10Wrapper, "display", "none"); // hide MY10 flash
        MY10.openLoader(); // open the loader overlay
        // sidecar base url
        var getURL = "/en_US/Media/data/Apps/2010_Motorcycles/html/sidecar/";
        
        // determine which sidecar to get
        if ("tle" == args) 
            getURL += "tleSidecar.htm";
        else 
            getURL += "tleUltraSidecar.htm";
        
        // make ajax call to get sidecar html
        YUC.asyncRequest('GET', getURL, {
            success: function(o){
                YUD.get(my10SideCar).innerHTML = o.responseText;
                YUE.onContentReady(my10SideCar, function(){
                    SC.util.pageLoad();
                    YUD.setStyle(my10SideCar, "display", "block");
                    MY10.closeLoader(); // close the loader overlay
                    YUE.onContentReady("close", function(){
                        YUE.addListener("close", "click", function(){
                            SWFAddress.back();
                        });
                    });
                    
                });
            },
            failure: function(o){
                // failure code
                YUD.get(my10SideCar).innerHTML = "<p>An Error has occured. Please refresh the page.</p>";
            }
        }, null);
        
    }, // end openSidecar
    /**
     * This method close the side car
     * overlay
     *
     * @method closeSideCar
     * @return none
     */
    closeSideCar: function(){
        YUD.setStyle(my10SideCar, "display", "none");
        //YUD.setStyle(my10Wrapper, "display", "block");
    },
    
    /**
     * This method get the html content, via AJAX, of the compare bikes page
     * and write it into the 2010 motorcyles page, and init the compare
     * that content
     *
     * @method initCompare
     * @return none
     */
    initCompare: function(model){
        //compare bikes URL
        var getURL = "/en_US/Media/data/Apps/2010_Motorcycles/html/specs/compare_specs.htm";
        
        // make ajax call to get compare html
        YUC.asyncRequest('GET', getURL, {
            success: function(o){
                YUD.get(my10CompareContainer).innerHTML = o.responseText;
                YUE.onContentReady(my10CompareContainer, function(){
                    MY10.compareSpecs.init(model);
                    //YUD.setStyle(my10Wrapper, "display", "none");									
                });
            },
            failure: function(o){
                // failure code
            }
        }, null);
    }, // end initCompare
    /**
     * This method opent the dealer locator for non us locales
     *
     * @method initCompare
     * @return none
     */
    openDealerNonUS: function openDealerNonUS(initLocale){
        var url = "/jump/Dealer_Locator_jump.asp?locale=";
        var localLocale;
        
        if (!initLocale) {
            if (!locale) 
                localLocale = "en_US";
            else 
                localLocale = locale;
        }
        else {
            localLocale = initLocale;
        }
        
        var middle = "-";
        var pre = localLocale.substring(0, 2);
        var post = localLocale.substring(3, 5);
        var strURL = url + localLocale; //pre + middle + post;		
        MY10.util.pageLink(strURL, "locator", "width=620, height=500, scrollbars=yes");
    }, //end function openDealerNonUS
    /**
     * This method will open loader
     *
     * @method openLoader
     */
    openLoader: function(){
        loaderOpen = true;
        YUD.setStyle(my10Promos, 'display', 'none');
        YUD.setStyle(my10Loader, 'display', 'block');
    }, // end openLoader	
    /**
     * This method will close loader
     *
     * @method closeLoader
     */
    closeLoader: function(){
        loaderOpen = false;
        YUD.setStyle(my10Loader, 'display', 'none');
        YUD.setStyle(my10Promos, 'display', 'block');
    }, // end closeLoader
    /**
     * This method preload images
     *
     * @method preloadImages
     * @return none
     */
    preloadImages: function(){
        compareBkg = new Image();
        compareBkg.src = "/en_US/Media/images/Apps/2010_Motorcycles/specs/bkg_compare_data.gif";
        compareHdr = new Image();
        compareHdr.src = "/en_US/Media/images/Apps/2010_Motorcycles/specs/bkg_compare_header.jpg";
        compareBlankImg = new Image();
        compareBlankImg.src = "/en_US/Media/images/Apps/2010_Motorcycles/specs/empty_dom_c01_sws_s.jpg";
        compareRowBkg = new Image();
        compareRowBkg.src = "/en_US/Media/images/Apps/2010_Motorcycles/specs/bkg_dataRowHdr.gif";
        sideCarBkg = new Image();
        sideCarBkg.src = "/en_US/Media/images/Apps/2010_Motorcycles/sidecar/pnw_sidecar_bkgd.jpg";
        loaderImg = new Image();
        loaderImg.src = "/en_US/Media/images/Apps/2010_Motorcycles/shared/my10_loader.gif";
        stafBkg = new Image();
        stafBkg.src = "/en_US/Media/images/Apps/2010_Motorcycles/shared/my10_staf_bkg.png";
        stafBkgIE = new Image();
        stafBkgIE.src = "/en_US/Media/images/Apps/2010_Motorcycles/shared/my10_staf_bkg.jpg";
    }
    
};


/**
 * callback method for getting the market selector data file and writing
 * it into the container page
 */
var getMarketSelectorDataCallback = {
    success: function(o){
    
        YUE.onAvailable("marketSelector", function(){
        
            YUE.addListener("marketSelector", "change", function(){
                document.cookie = my10MarketCookie + locale + "=" + this.value;
                market = this.value; // reset market
                market_type = marketTypeHash[this.value];
                pricing_file_ext = pricingHash[market];
                //MY10.initFlash(my10Container, locale);
				initView();
            });
            
        });
        
        YUD.get(my10Container).innerHTML = o.responseText;
        
        // remove temp styles added earlier
        YAHOO.util.StyleSheet('MY10Temp').unset("#" + my10Container, 'display');
        
    },
    failure: function(o){
        // set failure logic if needed	
    }
};
/**
 * @method initView global method initializes the view selection process. called by market selector callbacks and standard page init.
 */
var initView = function(){
		
	   var url = SWFAddress.getBaseURL();
        
        expFam = /family/;
        expMod = /bike/;
        
        var urlPath = url.split("/");
        var viewLocation = "";
        var deepLocation = "";
        
        if (typeof urlPath[7] != "undefined" || urlPath[7]) 
            viewLocation = urlPath[7];
        
        if (typeof urlPath[8] != "undefined" || urlPath[8]) 
            deepLocation = urlPath[8];
        
        var linkVal;
        var curPath;
        
        var linkHash = {};
        
        //default case
        linkHash['default'] = "/home/NB";
        
        //family case
        linkHash['cvo'] = "/family/CV";
        linkHash['dyna'] = "/family/DY";
        linkHash['softail'] = "/family/SO";
        linkHash['sportster'] = "/family/SP";
        linkHash['touring'] = "/family/TO";
        linkHash['trike'] = "/family/TR";
        linkHash['vrsc'] = "/family/VR";
        
        //model case -- CVO
        linkHash['cvo_fat_bob'] = "/model/fxdfse2";
        linkHash['cvo_heritage_softail_convertible'] = "/model/flstse";
        linkHash['cvo_street_glide'] = "/model/flhxse";
        linkHash['cvo_ultra_classic'] = "/model/flhtcuse5";
        
        //model case -- DYNA
        linkHash['super_glide'] = "/model/fxd";
        linkHash['super_glide_custom'] = "/model/fxdc";
        linkHash['street_bob'] = "/model/fxdb";
        linkHash['low_rider'] = "/model/fxdl";
        linkHash['wide_glide'] = "/model/fxdwg";
        linkHash['fat_bob'] = "/model/fxdf";
        
        //model case -- SOFTAIL
        linkHash['softail_standard'] = "/model/fxst";
        linkHash['softail_custom'] = "/model/fxstc";
        linkHash['fat_boy'] = "/model/flstf";
        linkHash['softail_deluxe'] = "/model/flstn";
        linkHash['heritage_softail_custom'] = "/model/flst";
        linkHash['heritage_softail_classic'] = "/model/flstc";
        linkHash['rocker_c'] = "/model/fxcwc";
        linkHash['cross_bones'] = "/model/flstsb";
        linkHash['fat_boy_lo'] = "/model/flstfb";
        
        //model case -- SPORTSTER
        linkHash['1200_custom'] = "/model/xl1200c";
        linkHash['1200_low'] = "/model/xl1200l";
        linkHash['883_low'] = "/model/xl883l";
        linkHash['883_roadster'] = "/model/xl883r";
        linkHash['iron_883'] = "/model/xl883n";
        linkHash['nightster'] = "/model/xl1200n";
        linkHash['xr1200'] = "/model/xr1200";
        linkHash['forty_eight'] = "/model/xl1200x";
        linkHash['xr1200x'] = "/model/xr1200x";
        
        //model case -- TOURING
        linkHash['road_king'] = "/model/flhr";
        linkHash['road_king_classic'] = "/model/flhrc";
        linkHash['street_glide'] = "/model/flhx";
        linkHash['road_glide_custom'] = "/model/fltrx";
        linkHash['electra_glide_standard'] = "/model/flht";
        linkHash['electra_glide_classic'] = "/model/flhtc";
        linkHash['ultra_classic_electra_glide'] = "/model/flhtcu";
        linkHash['electra_glide_ultra_limited'] = "/model/flhtk";
        
        //model case -- TRIKE
        linkHash['tri_glide_ultra_classic'] = "/model/flhtcutg";
        linkHash['street_glide_trike'] = "/model/flhxxx";
        
        //model case -- VRSC
        linkHash['v-rod'] = "/model/vrscaw";
        linkHash['night_rod_special'] = "/model/vrscdx";
        linkHash['v-rod_muscle'] = "/model/vrscf";
        
        if (expFam.test(viewLocation) || expMod.test(viewLocation)) {
            linkVal = linkHash[deepLocation.split(".")[0].toLowerCase()];
        }
        if (typeof linkVal == "undefined" || !linkVal) {
            linkVal = linkHash["default"];
        }
        
        curPath = SWFAddress.getPath();
        
		// variable to fix the dwp flash issue on chrome and safari
		var isDwp = MY10.util.getRequestParam('dwp_dealerid');
		var browser = navigator.userAgent;
		
        switch (curPath) {
            case "/":
        		//if dwp page and safari or chrome
				if(isDwp && browser){
					if(browser.indexOf('Safari') != -1 || browser.indexOf('Chrome') != -1){
						MY10.app.handleStateChange();
					}
				}else{
					// for some reason, the code below is not working on chrome and safari for DWP page?
					try {
					// this call crashes on chrome and safari, wrapping it in try/catch to allow js to
					// continue anyways - WH QA issue 25604 - chad norwood
				    SWFAddress.setValue(linkVal);
				    } catch (err) {
				    }
				}
		
			break;
        }
		
		MY10.app.handleStateChange();
}


//fix bkg image for STAF for IE6
if (YAHOO.env.ua.ie > 0) {
    if (YAHOO.env.ua.ie < 7) {
        YUS('STAFtemp').set("#" + "hdStafOverlay_c", {
            background: "transparent url(/en_US/Media/images/Apps/2010_Motorcycles/shared/my10_staf_bkg.jpg) no-repeat"
        });
    }
    else {
        YUS('STAFtemp').set("#" + "hdStafOverlay_c", {
            background: "transparent url(/en_US/Media/images/Apps/2010_Motorcycles/shared/my10_staf_bkg.png) no-repeat"
        });
    }
}
else {
    YUS('STAFtemp').set("#" + "hdStafOverlay_c", {
        background: "transparent url(/en_US/Media/images/Apps/2010_Motorcycles/shared/my10_staf_bkg.png) no-repeat"
    });
}

// Preload Images
MY10.preloadImages();

