/*
Title:      BRP Javascript Framework
Content:
            Base namespace setup BRP
                Events
                Language Selection
                Other Products
                Cookie Manager
                QueryUrl
            Menu
            Sea-Doo : Init + PopUp
                Base namespace setup SeaDoo 
                Initialize Share Options Pop up page
                Initialize Payment Calculator Pop up page
                Initialize Promotions Pop up page
                Initialize Send to a Friend Pop up page
                Initialize Send Brochure Pop up page
                Initialize Popup features
            Main Navigation for IE/Win
            Generic Popup Window
            Showroom : Model Selector
            Showroom : Tool Tip
            Showroom /Overview - Videos Images Slider
            Payment Calculator - Open/Close
*/

window.BRP = window.BRP || {};

BRP = {
	// Main function call (page init)
	Init : function() {	
		document.body.className += " hasJS";
		
		if(typeof MCMSConsoleInit == "function") {
			AdvancedHTMLToolsLoad = false;
			MCMSConsoleInit();
			}
		if(typeof initAdvancedHTMLTools == "function") 
		{
			if (AdvancedHTMLToolsLoad)	initAdvancedHTMLTools();		
		}
	}
		
};

YAHOO.util.Event.addListener(window, "load", BRP.Init, BRP, true);


// ------[ Events ]------------------------------------------------- //	
BRP.Events = {
	id : null,
	table : null,
	tr : null,
	
	Init : function() {
		this.table = document.getElementById(this.id);
		var tbody = this.table.getElementsByTagName("tbody")[0];	
		var tr = tbody.getElementsByTagName("tr");
		
		for(x=0; x<tr.length; x++) {
			var event = tr[x+1].getElementsByTagName("a")[0];
			tr[x].id = "event_" + x;
			tr[x].detail = tr[x+1];
			tr[x+1].bt = tr[x];
			tr[x].isVisible = false;
			tr[x].detail.getElementsByTagName("td")[0].innerHTML = "";
			tr[x].event = event.href;
			tr[x].onclick = BRP.Events.Show;
			tr[x].onmouseover = function() { 
				YAHOO.util.Dom.addClass(this, 'over');		
			}
			tr[x].onmouseout = function() { 
				YAHOO.util.Dom.removeClass(this, 'over');		
			}			
			YAHOO.util.Dom.addClass(tr[x], 'link');						
			x++;		
		}
	},
	
	Close : function(obj) {
		YAHOO.util.Dom.setStyle(obj.parentNode, 'display', 'none');	
		obj.innerHTML = "";	
		obj.parentNode.bt.isVisible = false;
	},
	
	Show : function() {
		if(this.isVisible) {			
			YAHOO.util.Dom.setStyle(this.detail, 'display', 'none');	
			this.detail.getElementsByTagName("td")[0].innerHTML = "";			
			this.isVisible = false;
		} else {		
			document.location = "#" + this.id;
			var iFrame = document.createElement('iframe');
			var td = this.detail.getElementsByTagName("td")[0];
			iFrame.scrolling = 'no';
			iFrame.setAttribute('src',this.event);
			iFrame = td.appendChild(iFrame);			
			YAHOO.util.Dom.setStyle(iFrame, 'width', '100%');
			YAHOO.util.Dom.setStyle(iFrame, 'border', '0');
			YAHOO.util.Dom.setStyle(iFrame, 'height', '540px');	
			YAHOO.util.Dom.setStyle(this.detail, 'display', '');	
			YAHOO.util.Dom.setStyle(td, 'padding', '0px');
			YAHOO.util.Dom.setStyle(td, 'margin', '0px');
			this.isVisible = true;
		}
	}
	
	
};


// ------[ Language Selection ]---------------------------------- //	
BRP.Language = {
	lang : null,
	
	Set : function(lang) {
		BRP.Cookie.Save('SeaDooLanguage', lang, true);
		this.lang = lang;
	},
	
 	Get : function() {	
	 	this.lang = BRP.Cookie.Load("SeaDooLanguage");
		if(this.lang) { 				
			return this.lang;
		} else {			
			return null;		
		}  	 	 	 				 		 	  
 	},
	
	Check : function(path) {
		this.Get();
		
		if((BRP.QueryUrl.Get('reset') != 'true') && (this.lang != null))
		{
		    document.location = path.replace("{lang}", this.lang).replace("{root}", TRYSPYDER.globals.RootDirectory);	
		}
	}
};

// ------[ Other Products ]------------------------------------------------- //	
BRP.OtherProducts = {
	IsShow : false,
	Timer : null,
	DivElement : null,
	strCrossContentHref : null,
	strCrossContentPage : null,
	
	Init : function() {		
		this.DivElement = document.getElementById("other-brp-products");
		if(this.DivElement) {
			this.DivElement.onmouseover = this.Show;
			this.DivElement.onmouseout = this.Hide;
			}
		//Keep the div "other-brp-products" open in the cross-content web page
			strCrossContentHref = window.location.href;
			strCrossContentPage = strCrossContentHref.indexOf("cross-content.htm");			
			if(strCrossContentPage >= 0) {
				BRP.OtherProducts.DivElement.style.display = "block";
			}
		},
	
	Show : function() {
		clearTimeout(BRP.OtherProducts.Timer);
		BRP.OtherProducts.Timer = false;
		BRP.OtherProducts.DivElement.style.display = "block";
		BRP.OtherProducts.IsShow = true;
		window.scrollTo(0,10000000);		
		},
		
	Hide : function() {
			if(strCrossContentPage <= 0) { 
				//console.log("Function Hide strCrossContentPage = " + strCrossContentPage);
				BRP.OtherProducts.Timer = setTimeout('BRP.OtherProducts.HideTimer()',500);
			}
		},

	HideTimer : function() {
		BRP.OtherProducts.Timer = false;
		BRP.OtherProducts.DivElement.style.display = "none";
		BRP.OtherProducts.IsShow = false;			
		},
	
	Display : function() {
		if(this.DivElement) {
			if(!this.IsShow) {
				this.Show();
				//this.Timer = setTimeout('BRP.OtherProducts.HideTimer()',1500);
				}
			else this.Hide();
			}
		}
};
YAHOO.util.Event.addListener(window, "load", BRP.OtherProducts.Init, BRP.OtherProducts, true);


// ------[ Cookie Manager ]---------------------------------- //	
BRP.Cookie = {

	Load: function (id) {
		var search = id + "=";  
		var cookie = null;
		if (document.cookie.length > 0) { 					// if there are any cookies      
			offset = document.cookie.indexOf(search);       
			if (offset != -1) { 							// if cookie exists          
				offset += search.length; 					// set index of beginning of value         
				end = document.cookie.indexOf(";", offset);	// set index of end of cookie value         
				if (end == -1) end = document.cookie.length;
				cookie = unescape(document.cookie.substring(offset, end));   
				}    
			}	
		return cookie;	
	},

	Save: function (id, data, session) {
		if(session) {
			var now = new Date();
			var expires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
			var expires = new Date(expires);
			session = "; expires=" + expires.toGMTString();
		} else session = "";

		document.cookie = id + "=" + escape(data) + session + "; path=/";
	}			


};


// ------[ QueryUrl ]---------------------------------- //
BRP.QueryUrl = {
	
	Search : function(q) {
		if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
		this.keyValuePairs = new Array();
		
		if(q) {
			for(var i=0; i < this.q.split("&").length; i++) {
				this.keyValuePairs[i] = this.q.split("&")[i];
				}
			}
		
		this.getKeyValuePairs = function() { return this.keyValuePairs; }
		this.getValue = function(s) {
			for(var j=0; j < this.keyValuePairs.length; j++) {
				if(this.keyValuePairs[j].split("=")[0] == s) return this.keyValuePairs[j].split("=")[1];
				}
			return;
			}
		
		this.getParameters = function() {
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) {
				a[j] = this.keyValuePairs[j].split("=")[0];
				}
			return a;
			}
		
		this.getLength = function() { return this.keyValuePairs.length; }		
		},
	
	Get : function(key) {
		var page = new this.Search(window.location.search);
		return unescape(page.getValue(key));		
		}
};

// ------[ Menu ]------------------------------------------------- //
YAHOO.util.Event.onContentReady("main-nav", function () {  

	/**
	* Initialize the Menu
	* Ul Navigation: Display 'block' to show nav after Loading
	*/

	function MenuInit(){
		var UlNavObject = document.getElementById("main-nav-container");
		YAHOO.util.Dom.setStyle(UlNavObject, "display", "block");				
	};
	
	MenuInit();
	
});

// ------[ Sea-Doo : Init + PopUp ]------------------------------------------------- //

/**
 * Base namespace setup
 */
var SeaDoo = {
    globals: {
		labels: {}
	},
    pages: {
        all: {},
        modelOverview: {},
        paymentCalculator: {}        
    },
    widgets: {}
}

/**
 * Init for all pages
 */
SeaDoo.pages.all.init = function() {

    /**
    * Initialize Share Options Pop up page
    */
    SeaDoo.globals.shareOptions = new YAHOO.widget.Panel(
		"shareoptions",
		{
		    width: "260px",
		    height: "120px",
		    context: ["linkShare", "bl", "tr"],
		    constraintoviewport: false,
		    close: true,
		    visible: false,
		    draggable: false,
		    zIndex: 5
		}
	);
    //Render the panel for screen
    SeaDoo.globals.shareOptions.render(document.body);

    //Create an array with all anchor with the classname "shareoptions"
    var el = YAHOO.util.Dom.getElementsByClassName('shareoptions', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            var pnl = SeaDoo.globals.shareOptions;
            pnl.setBody("<iframe allowtransparency='true' width='260' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='120' src='" + this.href + "'></iframe>");
            pnl.render();
            pnl.show();
            return false;
        }
        el[i].style.visibility = "visible";
    }

    /**
    * Initialize Payment Calculator Pop up page
    */
    //    SeaDoo.globals.calculator = new YAHOO.widget.Panel(
    //		"calculatepayment",
    //		{
    //		    width: "255px",
    //		    height: "345px",
    //		    constraintoviewport: true,
    //		    underlay: "shadow",
    //		    close: true,
    //		    visible: false,
    //		    fixedcenter: true,
    //		    draggable: false,
    //		    zIndex: 5,
    //		    modal: true //Window bkg
    //		}
    //	);
    //Render the panel for screen
    //    SeaDoo.globals.calculator.render(document.body);

    //Create an array with all anchor with the classname "calculatepayment"
    //    var el = YAHOO.util.Dom.getElementsByClassName('calculatepayment', 'a');

    //    for (var i = 0; el[i]; i++) {
    //        el[i].onclick = function() {
    //            var sURL = new String(document.location);
    //            sURL = sURL.substring(sURL.lastIndexOf('.com')+5,9999);
    //            
    //            var sCulture = sURL.substring(0,5);
    //            pageTracker._trackPageview('/'+sCulture+'/Payment_Calculator');
    //            
    //            var pnl = SeaDoo.globals.calculator;
    //            pnl.setBody("<iframe allowtransparency='true' width='255' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='345' src='" + this.href + "'></iframe>");
    //            pnl.render();
    //            pnl.show();
    //            return false;
    //        }
    //        el[i].style.visibility = "visible";
    //    }

    /**
    * Initialize Promotions Pop up page
    */
    SeaDoo.globals.promotions = new YAHOO.widget.Panel(
		"popupPromotions",
		{
		    width: "470px",
		    height: "670px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: false,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);
    //Render the panel for screen
    SeaDoo.globals.promotions.render(document.body);

    //Create an array with all anchor with the classname "popupPromotions"
    var el = YAHOO.util.Dom.getElementsByClassName('popupPromotions', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            var pnl = SeaDoo.globals.promotions;
            pnl.setBody("<iframe allowtransparency='true' width='470' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='670' src='" + this.href + "'></iframe>");
            pnl.render();
            pnl.center();
            pnl.show();
            return false;
        }
        el[i].style.visibility = "visible";
    }

    //Redirection du bouton "Get a Quote" dans la popup "popupPromotions"
    var btn = YAHOO.util.Dom.getElementsByClassName('rightButton', 'a');
    for (var i = 0; btn[i]; i++) {
        btn[i].onclick = function() {
            parent.SeaDoo.globals.promotions.hide();
            parent.window.location = btn[i].href;
            return false;
        }
        btn[i].style.visibility = "visible";
    }


    /**
    * Initialize Send to a Friend Pop up page
    */
    SeaDoo.globals.sendEmail = new YAHOO.widget.Panel(
		"sendtofriend",
		{
		    width: "655px",
		    height: "315px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);
    //Render the panel for screen
    SeaDoo.globals.sendEmail.render(document.body);

    //Create an array with all anchor with the classname "sendfriend"
    var el = YAHOO.util.Dom.getElementsByClassName('sendfriend', 'a');
    var el2 = YAHOO.util.Dom.getElementsByClassName('shareoptions', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            var pnl = parent.SeaDoo.globals.sendEmail;
            parent.SeaDoo.globals.shareOptions.hide();
            pnl.setBody("<iframe allowtransparency='true' width='655' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='315' src='" + this.href + "'></iframe>");
            pnl.render();
            pnl.show();
            return false;
        }
        el[i].style.visibility = "visible";
    }

    /**
    * Initialize Send Brochure Pop up page
    */
    SeaDoo.globals.brochure = new YAHOO.widget.Panel(
		"sendBrochure",
		{
		    width: "665px",
		    height: "335px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);
    //Render the panel for screen
    SeaDoo.globals.brochure.render(document.body);

    //Create an array with all anchor with the classname "sendBrochure"
    var el = YAHOO.util.Dom.getElementsByClassName('sendBrochure', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            var pnl = SeaDoo.globals.brochure;
            pnl.setBody("<iframe allowtransparency='true' width='665' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='335' src='" + this.href + "'></iframe>");
            pnl.render();
            pnl.show();
            return false;
        }
        el[i].style.visibility = "visible";
    }

    /**
    * Initialize Popup features
    */
    SeaDoo.globals.featuresH = new YAHOO.widget.Panel(
		"popupFeaturesH",
		{
		    width: "577px",
		    height: "265px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);

    SeaDoo.globals.featuresV = new YAHOO.widget.Panel(
		"popupFeaturesV",
		{
		    width: "527px",
		    height: "341px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);

    SeaDoo.globals.featuresSWF = new YAHOO.widget.Panel(
		"popupFeaturesSWF",
		{
		    width: "758px",
		    height: "290px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg,
		}
	);
    //Render the panel for screen
    SeaDoo.globals.featuresH.render(document.body);
    SeaDoo.globals.featuresV.render(document.body);
    SeaDoo.globals.featuresSWF.render(document.body);

    //Create an array with all anchor with the classname "popupFeatures"
    var el = YAHOO.util.Dom.getElementsByClassName('popupFeatures', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            LoadPanelFeatures(this);
            return false;
        }
        el[i].style.visibility = "visible";
        //el[i].style.display = "none";
    }

    /* 
    *   SeaDoo.globals.featuresSWF :
    *       Hack to shutdown the Sound in the SWF.
    *       Removed the div element
    */
    var containerPanelSWF = YAHOO.util.Dom.get("popupFeaturesSWF");
    var btnClosePanelFlashSWF = YAHOO.util.Dom.getElementsByClassName("container-close", "a", containerPanelSWF);
    if (btnClosePanelFlashSWF) {
        for (i = 0; i < btnClosePanelFlashSWF.length; i++) {
            YAHOO.util.Event.addListener(btnClosePanelFlashSWF[i], "click",
               function(that) {
                   return function(e) {
                       YAHOO.util.Event.preventDefault(e);
                       this.contentPanel = YAHOO.util.Dom.getElementsByClassName("bd", "div", containerPanelSWF);
                       containerPanelSWF.removeChild(containerPanelSWF.childNodes.item(1));
                   }
               } (this));
        }
    }

    SeaDoo.globals.overviewVideo = new YAHOO.widget.Panel(
		"overview-video",
		{
		    width: "555px",
		    height: "350px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);
    SeaDoo.globals.overviewVideoLarge = new YAHOO.widget.Panel(
		"overview-video",
		{
		    width: "730px",
		    height: "530px",
		    constraintoviewport: true,
		    underlay: "shadow",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: true //Window bkg
		}
	);
    //Render the panel for screen
    SeaDoo.globals.overviewVideo.render(document.body);
    SeaDoo.globals.overviewVideoLarge.render(document.body);

    //Create an array with all anchor with the classname "overview-video"
    var el = YAHOO.util.Dom.getElementsByClassName('overview-video', 'a');
    var el2Link = YAHOO.util.Dom.getElementsByClassName('overview-video-open', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            LoadPanelOverviewVideo(this);
            return false;
        }
        el[i].style.visibility = "visible";
    }

    for (var i = 0; el2Link[i]; i++) {
        YAHOO.util.Event.on('overview-video-open', 'load', LoadPanelOverviewVideo(el2Link[0]));
        el2Link[i].onclick = function() {
            LoadPanelOverviewVideo(this);
            return false;
        }
        el2Link[i].style.visibility = "visible";
    }

    //Create an array with all anchor with the classname "openPVA"
    var elPVA = YAHOO.util.Dom.getElementsByClassName('openPVA', 'a');
    var elGetaQuote = YAHOO.util.Dom.getElementsByClassName('openGetaQuote', 'a');
    var elClose = YAHOO.util.Dom.getElementsByClassName('closePanel', 'span');
    var blockPVA = YAHOO.util.Dom.getElementsByClassName('panelPVA', 'div');
    var blockGetaQuote = YAHOO.util.Dom.getElementsByClassName('panelGetAQuote', 'div');
    var blockContentPage = YAHOO.util.Dom.getElementsByClassName('panelContentPage', 'div');

    if (elPVA.length >= "1" && blockPVA.length >= "1") {
        for (var i = 0; elPVA[i]; i++) {
            elPVA[i].onclick = function() {
                trackPageviewWithPrefix("", "/compare-to-competition");
                if (elPVA[0].className == "openPVA") {
                    elPVA[0].className = elPVA[0].className.replace("openPVA", "openPVAOn");
                }
                if (elGetaQuote.length >= "1") {
                    elGetaQuote[0].className = elGetaQuote[0].className.replace("openGetaQuoteOn", "openGetaQuote");
                    blockGetaQuote[0].style.display = "none";
                }
                blockPVA[0].style.display = "block";
                blockContentPage[0].style.display = "none";
                return false;
            }
        }
    }

    if (elGetaQuote.length >= "1" && blockGetaQuote.length >= "1") {
        for (var i = 0; elGetaQuote[i]; i++) {
            elGetaQuote[i].onclick = function() {
                trackPageviewWithPrefix("", "/get-a-quote");
                if (elGetaQuote[0].className == "openGetaQuote") {
                    elGetaQuote[0].className = elGetaQuote[0].className.replace("openGetaQuote", "openGetaQuoteOn");
                }
                if (elPVA.length >= "1") {
                    elPVA[0].className = elPVA[0].className.replace("openPVAOn", "openPVA");
                    blockPVA[0].style.display = "none";
                }
                blockGetaQuote[0].style.display = "block";
                blockContentPage[0].style.display = "none";
                return false;
            }
        }
    }

    for (var i = 0; elClose[i]; i++) {
        elClose[i].onclick = function() {
            if (elPVA.length >= "1") {
                elPVA[0].className = elPVA[0].className.replace("openPVAOn", "openPVA");
                blockPVA[0].style.display = "none";
            }
            if (elGetaQuote.length >= "1") {
                elGetaQuote[0].className = elGetaQuote[0].className.replace("openGetaQuoteOn", "openGetaQuote");
                blockGetaQuote[0].style.display = "none";
            }
            blockContentPage[0].style.display = "block";
            return false;
        }
    }

    //IE6 Only patch Navigation : onmouseover level
    MainNavigationInit();
};

function LoadPanelOverviewVideo(elementToLoad) {
    var style = new BRP.QueryUrl.Search(elementToLoad.href).getValue("Style");
    LoadVideo(elementToLoad.href, style);
}

function LoadPanelFeatures(elementToLoad) {
    var style = new BRP.QueryUrl.Search(elementToLoad.href).getValue("Style");

    var pnl, width, height;
    if (style.toLowerCase() == "swf") {
        pnl = SeaDoo.globals.featuresSWF;
        width = 758;
        height = 290;
    }
    else if (style.toLowerCase() == "h") {
        pnl = SeaDoo.globals.featuresH;
        width = 577;
        height = 265;
    }
    else {
        pnl = SeaDoo.globals.featuresV;
        width = 527;
        height = 341;
    }

    pnl.setBody("<iframe allowtransparency='true' width='" + width + "' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='" + height + "' src='" + elementToLoad.href + "'></iframe>");
    pnl.render();
    pnl.show();
}

function LoadVideo(videoToLoad, style) {

    if (!style) {
        style = "";
    }

    var pnl, width, height;
    if (style.toLowerCase() == "large") {
        pnl = SeaDoo.globals.overviewVideoLarge;
        width = 730;
        height = 530;
    }
    else {
        pnl = SeaDoo.globals.overviewVideo;
        width = 555;
        height = 350;
    }

    pnl.setBody("<iframe allowtransparency='true' width='" + width + "' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='" + height + "' src='" + videoToLoad + "&Style=" + style + "'></iframe>");
    pnl.render();
    pnl.subscribe("hide", function() {
        this.setBody("");
    });

    pnl.show();
}

// ------[ Main Navigation for IE/Win ]------------------------------------------------- //
function MainNavigationInit() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("main-nav-container");
		if(navRoot) MainNavigationLoop(navRoot, 2);
		}
	}	
	function MainNavigationLoop(obj, level) {
		for (var i=0; i<obj.childNodes.length; i++) {
			node = obj.childNodes[i];		
			if(node.nodeName=="LI") {
				node.level = level;
				node.onmouseover = MainNavOver;
				node.onmouseout = MainOut;	
				}
			if(node.childNodes.length > 2) {
				node2 = node.childNodes[2];
				MainNavigationLoop(node2, level + 1)
				}
			}
		}
function MainNavOver() {
    if (this.level.toString() == "2") {
        if (this.className != "") {
            this.className = this.className.replace("selectedNode", "");
            this.className += "selectedNode navOver";
        }
        else {
            this.className += "navOver";
        }
        }
    else {
        this.className += "navOver";
        }

    }	
	function MainOut() {
	    if(this.level.toString() == "2"){
	        if (this.className == "selectedNode navOver") {
	            this.className = this.className.replace("selectedNode navOver", "selectedNode");
	        }
	        else {
	            this.className = this.className.replace("navOver", "");
	        }
	    }
	    else {
	        this.className = this.className.replace("navOver", "");
	    }
	}
// ------[ Generic Popup Window ]------------------------------------------------- //
function popWin(url,w,h,scroll,tools,name,center,baseUrl) {
	var str = "height=" + h + ",innerHeight=" + h;
	str += ",width=" + w + ",innerWidth=" + w;
	if(baseUrl) url = webSiteCMSUrl + url;
	if(!center) var center = false;
	if(!scroll) scroll = 0;
	if(!tools) tools = 0;
	if(!name) name = "pop";

	if((window.screen) && (center)) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - w) / 2;
		var yc = (ah - h) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		}

	pop = window.open(url,name,'toolbar=' + tools + ',location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=1,' + str).focus();
}

// ------[ Showroom : Model Selector ]--------------------------------------------- //
//this class is called by the flash to track which options were selected in the models selector showroom
BRP.ModelSelector = {

	modelselectorTracker : null, 

	Create: function(channelName)
	{
		if (channelName.toLowerCase() == "watercraft")
		{
		    modelselectorTracker = pageTracker._createEventTracker('Model%20Selector%20PWC');
		}
		else
		{
		    modelselectorTracker = pageTracker._createEventTracker('Model%20Selector%20SB');
		}		
	},
	TrackEvent: function(action, value) {        
        modelselectorTracker._trackEvent(action, value);
    }	
};

// ------[ Showroom : Tool Tip ]--------------------------------------------- //

BRP.ModelToolTip = {
	Create: function(modelContainerId, toolContainerId)
	{
		//Show only the Main Div Element
		YAHOO.util.Dom.setStyle("models-tooltip", "display", "block")
		this.ModelsContainerId = modelContainerId;
		this.ToolContainerId = toolContainerId;
		BRP.ModelToolTip.ActionModelsHover(this.ModelsContainerId,this.ToolContainerId);
	},	

	ActionModelsHover: function(elAllModels, elModelsSeaDoo)
	{
		var containerModels = YAHOO.util.Dom.get(elAllModels);
		var modelsSeaDooElement = elModelsSeaDoo;	

		if(containerModels && modelsSeaDooElement) {
			/* aArray == All a Element */
			var aArray = containerModels.getElementsByTagName('a');	
			var aCount = aArray.length;
			/* toolArray == Parent Element */
			var toolArray = YAHOO.util.Dom.getElementsByClassName(modelsSeaDooElement,null,containerModels);		

			for (i=0; i < aCount; i++) {
				//Create all "SeaDoo Info Tool" ID
				var toolId = toolArray[i].id+"Info";			

				//Hide all SeaDoo Info Tool
				//YAHOO.util.Dom.setStyle(toolId, "display", "none");
				//Moves "tool tip" element to the xy position of "a" element
				var xPosition = YAHOO.util.Dom.getX(aArray[i]);
				var yPosition = YAHOO.util.Dom.getY(aArray[i]);
				var aElementWidth = aArray[i].offsetWidth;
				//round = Arrondit à l'entier le plus proche la valeur donnée.
				var maxWidth = Math.round((107 - aElementWidth) / 2);
				//floor = Retourne le plus grand entier inférieur ou égal à la valeur donnée en paramètre.
				xPosition = Math.floor(xPosition + aElementWidth + maxWidth - 10);
				yPosition = Math.floor(yPosition - 80);

				//Set the "tool tip" element position
				YAHOO.util.Dom.setX(toolId, xPosition);
				YAHOO.util.Dom.setY(toolId, yPosition);

				//Create Fade in Tool element
				BRP.ModelToolTip.SEADOOID =  
					new YAHOO.widget.Overlay(toolId,
						{
						    visible: false,
						    zIndex: 6,
						    effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}
						}
				);			

				/* Call Action on Element */
				
				YAHOO.util.Event.addListener(toolArray[i], "mouseover", BRP.ModelToolTip.SEADOOID.show, BRP.ModelToolTip.SEADOOID, true);
				YAHOO.util.Event.addListener(toolArray[i], "mouseout", function () {
					var container = toolArray[i];
					return function (e) {
						e = e || event;
						relatedTarget = YAHOO.util.Event.getRelatedTarget(e);
						if (typeof relatedTarget === "undefined") 
						{/*If Outside ViewPort*/
							this.hide();
						}
						else 
						{
							/*Look if we are inside the Parent Element*/
							var isInside = YAHOO.util.Dom.getAncestorBy(relatedTarget, function (el) {
									if (el.id === container.id) 
									{
										return true;
									}
									return false;
							});
							if (!isInside) 
							{
								this.hide();
							}
						}
					}
				}(), BRP.ModelToolTip.SEADOOID, true);

				//Create href on Parent DIV element 
				var alinks = function(e, params) {
					var url = params.links || event;
					YAHOO.util.Event.preventDefault(e);
					
					//Check to see if we clicked on an DIV element
					//console.log("params.caller.tagName = " + params.caller.tagName);
					if (params.caller && params.caller.tagName && (params.caller.tagName.toLowerCase() == 'div'))
					{
						window.location = url;
					}
				}
				
				YAHOO.util.Event.addListener(toolArray[i], 'click', alinks, {caller:toolArray[i], links:aArray[i]});
			}
		}
	}
};

// ------[ Showroom /Overview - Videos Images Slider ]------------------------------------------------- /

SeaDoo.pages.modelOverview.init = function() {
    // Initialize video images slideshow
    SeaDoo.globals.slideShow = new SeaDoo.widgets.Slideshow();
};
/**
* Creates a slideshow with previous/next buttons and slides in between representing
* the current slide among the total number of slides in the show
*/
SeaDoo.widgets.Slideshow = function() {
    // Video Player Element
    this.slidesEl = YAHOO.util.Dom.get("video-player");
    // Slider Controls Element
    this.controlBarEl = YAHOO.util.Dom.get("pics-indicator");
    if (!this.slidesEl || !this.controlBarEl) return;

    // Find all THUMBNAILS Slider Images
    this.slides = this.controlBarEl.getElementsByTagName("div");

    this.slidesPtr = 0;
    this.currentSlide = function() { return this.slidesPtr + 1 }

    /*
    *   Initial States :
    *       Show the Slider details box
    *       Allow to view all the elements after the content is load
    */
    var elProductsDetailsContent = YAHOO.util.Dom.get("products-images");
    elProductsDetailsContent.style.display = "block";

    /*
    * Only create slideshow if there is more than 0 slide
    */
    if (this.slides.length > 0) {
        /*
        *  Set all THUMBNAILS Slider Images for the CLICK action
        */
        for (var i = 0; i < this.slides.length; i++) {
            YAHOO.util.Event.addListener(this.slides[i], 'click', function(that, num) {
                return function(e) {
                    YAHOO.util.Event.preventDefault(e);
                    //If the current slide click == to same click, do nothing
                    if (that.slidesPtr != num) {
                        that.slidesPtr = num;
                        that.setCurrentEl();
                        //Set the video
                        SeaDoo.widgets.Slideshow.StartVideo(this.attributes["videoUrl"].nodeValue, this.attributes["productid"].nodeValue, this.attributes["applicationPath"].nodeValue);
                    }
                }
            } (this, i));
        }
        /*
        * Set the Current Thumbnails Class
        */
        this.setCurrentEl = function() {
            if (this.controlBarEl) {
                for (var i = 0; this.slides[i]; i++) {
                    if ((i + 1) === this.currentSlide()) {
                        this.slides[i].className = "current";
                    } else {
                        this.slides[i].className = "";
                    }
                }
            }
        }
        /*
        *  Initialize the first Current slide
        */
        this.setCurrentEl();
        /*
        *  Initialize the SlideShow Selector
        */
        this.ImageSelectorScroll.Init();
    }
}         //init

SeaDoo.widgets.Slideshow.StartVideo = function(videoUrl, productId, applicationPath) {
    var params = {};
    params.wmode = "transparent";
    params.quality = "high";
    params.scale = "noscale";
    params.allowfullscreen = "true";

    var attributes = {};
    attributes.id = "inner-video";
    attributes.name = "inner-video";

    videoFlashvars.videoName = videoUrl;
    videoFlashvars.productId = productId;

    swfobject.embedSWF(applicationPath + "/_Static/neutral/flash/mainLoader.swf", "inner-video", "438", "285", "9.0.0", applicationPath + "/_Static/Neutral/Flash/expressInstall.swf", videoFlashvars, params, attributes);
};

SeaDoo.widgets.Slideshow.prototype.ImageSelectorScroll = {
    picActualPosition: 0,
    listId: 'main-indicator',
    itemsList: 'pics-indicator',
    scrollPrevious: 'pics-left',
    scrollNext: 'pics-right'
};

SeaDoo.widgets.Slideshow.prototype.ImageSelectorScroll.Init = function() {
    // Find ID element
    this.scrollableListContainer = document.getElementById(this.listId);
    this.scrollableList = document.getElementById(this.itemsList);
    this.lnkPrevious = document.getElementById(this.scrollPrevious);
    this.lnkNext = document.getElementById(this.scrollNext);
    
    this.picsArray = this.scrollableList.getElementsByTagName('div');
    this.picsWidth = this.picsArray[0].offsetWidth;
    this.picsCount = this.picsArray.length;

    // Set the correct "width" for the list : ignoring the scrollableListContainer width
    this.scrollableList.style.width = this.picsWidth * this.picsCount + "px";
    this.ViewablePics = parseInt(this.scrollableListContainer.offsetWidth / this.picsWidth);

    YAHOO.util.Event.addListener(this.lnkPrevious, 'click', this.Scrolling, { caller: this, direction: -1 });
    YAHOO.util.Event.addListener(this.lnkNext, 'click', this.Scrolling, { caller: this, direction: 1, pics: this.ViewablePics, count: this.picsCount });

    //Show the Slider Scroll button if 4 products and more
    if (this.picsCount > "3") {
        YAHOO.util.Dom.setStyle(this.lnkPrevious, 'display', 'block');
        YAHOO.util.Dom.setStyle(this.lnkNext, 'display', 'block');
        this.RefreshNavigation();
    }
};

SeaDoo.widgets.Slideshow.prototype.ImageSelectorScroll.RefreshNavigation = function() {
    if (this.picActualPosition > 0) {    
        YAHOO.util.Dom.setStyle(this.lnkPrevious, 'opacity', 1);
    }
    else {
        YAHOO.util.Dom.setStyle(this.lnkPrevious, 'opacity', 0.2);
    }

    if ((this.picActualPosition + this.ViewablePics) < this.picsCount) {
        YAHOO.util.Dom.setStyle(this.lnkNext, 'opacity', 1);
    }
    else {
        YAHOO.util.Dom.setStyle(this.lnkNext, 'opacity', 0.2);
    }
};

SeaDoo.widgets.Slideshow.prototype.ImageSelectorScroll.Scrolling = function(e, params) {

    if (params.direction == "1") {
        // Next
        if ((params.caller.picActualPosition + params.pics) >= params.count) {
            //Stop the Click Event if we are in maximum in RIGHT position
            return false;
        } else {
            // Set the new position counter
            params.caller.picActualPosition += params.direction;
        }
    } else {
        // Previous
        if (params.caller.picActualPosition <= 0) {
            //Stop the Click Event if we are in maximum in LEFT position
            return false;
        } else {
            // Set the new position counter
            params.caller.picActualPosition += params.direction;
        }
    }

    // Get the actual XY position of the scroller DIV;
    var originalXY = YAHOO.util.Dom.getXY(params.caller.scrollableList);
    
    // Calculate the new coordinates
    var elContainerXY = YAHOO.util.Dom.getXY(params.caller.scrollableListContainer);
    var newXY = [elContainerXY[0] + ((params.caller.picActualPosition * -1) * params.caller.picsWidth), originalXY[1]];
    
    /* 
    * Anim subclass for moving elements along a path
    * Defined by the "opacity" and "points" member of "attributes"
    * Set the Duration (0.5) and Method (EaseOut) for the animation
    */
    var animSlide = new YAHOO.util.Motion(params.caller.scrollableList, { opacity: { from: 0.3, to: 1 }, points: { to: newXY} }, 0.5, YAHOO.util.Easing.EaseOut);
    animSlide.animate();

    // Set Style of Navigation button 
    params.caller.RefreshNavigation();
}

// ------[ Payment Calculator - Open/Close ]------------------------------------------------- /

SeaDoo.pages.paymentCalculator = {

    init: function(divContainerId, divButton, divContent) {

        var containerList = YAHOO.util.Dom.get(divContainerId);
        var buttonList = YAHOO.util.Dom.get(divButton);
        var divBoxArray = YAHOO.util.Dom.get(divContent);

        if (containerList && buttonList && divBoxArray) {
            var currentLinkElement;
            var divLinkArray = buttonList.getElementsByTagName('div');
            var spanBoxArray = YAHOO.util.Dom.getElementsByClassName("closed", null, divBoxArray);
            var aLinkArrayShow = YAHOO.util.Dom.getElementsByClassName("show", null, buttonList);
            var aLinkArrayHide = YAHOO.util.Dom.getElementsByClassName("hide", null, buttonList);

            if (divLinkArray && spanBoxArray) {

                // Add Click on "INPUT" Element and change the background image to BIG
                var buttonSubmitArray = YAHOO.util.Dom.getElementsByClassName("submit", null, divBoxArray);
                if (buttonSubmitArray) {
                    for (i = 0; i < buttonSubmitArray.length; i++) {                    
                        YAHOO.util.Event.addListener(buttonSubmitArray[i], "click",
                           function(that) {
                               return function(e) {
                                   YAHOO.util.Event.preventDefault(e);
                                   if (YAHOO.util.Dom.hasClass(divBoxArray, 'bkg-sml')) {
                                       YAHOO.util.Dom.replaceClass(divBoxArray, 'bkg-sml', 'bkg-big');
                                   }
                               }
                           } (this));
                       }
                }
               
                // Add Click on "DIV" Element and open the box being selected and switch the text button (Show/Hide)
                for (i = 0; i < divLinkArray.length; i++) {
                    YAHOO.util.Event.addListener(divLinkArray[i], "click",
                        SeaDoo.pages.paymentCalculator.ClickLinkEvents,
                            { buttonList: buttonList,
                                callersArray: divLinkArray, callerElement: divLinkArray[i],
                                showElementArray: aLinkArrayShow, showElement: aLinkArrayShow[i],
                                hideElementArray: aLinkArrayHide, hideElement: aLinkArrayHide[i],
                                boxDetailsArray: spanBoxArray, boxDetailsElement: spanBoxArray[i],
                                boxContainer: divBoxArray
                            }
                    );
                }

                // Initialized the first TAB to OPENED
                YAHOO.util.Event.on(window, "load",
                        SeaDoo.pages.paymentCalculator.ClickLinkEvents,
                        { callersArray: divLinkArray, callerElement: divLinkArray[0],
                            showElementArray: aLinkArrayShow, showElement: aLinkArrayShow[0],
                            hideElementArray: aLinkArrayHide, hideElement: aLinkArrayHide[0],
                            boxDetailsArray: spanBoxArray, boxDetailsElement: spanBoxArray[0],
                            boxContainer: divBoxArray
                        });
            }
        }
    }, //Init

    ClickLinkEvents: function(e, params) {

        e = e || event;
        YAHOO.util.Event.preventDefault(e);
        var buttonList = params.buttonList;
        var callersArray = params.callersArray;
        var callerElement = params.callerElement;
        var showElementArray = params.showElementArray;
        var showElement = params.showElement;
        var hideElementArray = params.hideElementArray;
        var hideElement = params.hideElement;
        var boxContainer = params.boxContainer;
        var boxDetailsArray = params.boxDetailsArray;
        var boxDetailsElement = params.boxDetailsElement;

        //Check to see if we clicked on an "DIV" element
        if (callerElement.tagName.toLowerCase() == 'div') {

            /*
            * If the "DIV" element is the one being cliked, set current box as display:none and reset the current click element
            */
            if (SeaDoo.pages.paymentCalculator.currentLinkElement == callerElement) {
                YAHOO.util.Dom.replaceClass(callerElement, 'opened', 'closed');
                YAHOO.util.Dom.replaceClass(boxContainer, 'opened', 'closed');
                YAHOO.util.Dom.setStyle(showElement, 'display', 'block');
                YAHOO.util.Dom.setStyle(hideElement, 'display', 'none');
                // Added line under all buttons 
                YAHOO.util.Dom.addClass(buttonList, 'button-line');

                SeaDoo.pages.paymentCalculator.currentLinkElement = "";
            } else {
                /*
                * Close all "DIV" & "A (Show/Hide)" & "SPAN" before opening the current click element.
                */
                for (i = 0; i < boxDetailsArray.length; i++) {
                    YAHOO.util.Dom.replaceClass(callersArray[i], 'opened', 'closed');
                    YAHOO.util.Dom.replaceClass(boxDetailsArray[i], 'opened', 'closed');
                    YAHOO.util.Dom.setStyle(showElementArray[i], 'display', 'block');
                    YAHOO.util.Dom.setStyle(hideElementArray[i], 'display', 'none');
                }
                YAHOO.util.Dom.replaceClass(callerElement, 'closed', 'opened');
                YAHOO.util.Dom.replaceClass(boxContainer, 'closed', 'opened');
                YAHOO.util.Dom.replaceClass(boxDetailsElement, 'closed', 'opened');
                YAHOO.util.Dom.setStyle(showElement, 'display', 'none');
                YAHOO.util.Dom.setStyle(hideElement, 'display', 'block');
                // Removed line under all buttons 
                YAHOO.util.Dom.removeClass(buttonList, 'button-line');

                SeaDoo.pages.paymentCalculator.currentLinkElement = callerElement;
            }
        }
    } //ClickLinkEvents

};