var PageLoad = false;
var MCMSConsoleLoad = false;
var AdvancedHTMLToolsLoad = false;
var InPageGBLoad = false;
var BannerAd = false;

// ------[ Main function call (page init) ]------------------------------------------------- //
function main()	{
	if(MCMSConsoleLoad) MCMSConsoleInit();
	if(AdvancedHTMLToolsLoad) initAdvancedHTMLTools();
	if(InPageGBLoad) InPageGBInit();
	MainNavigationInit();
	if(BannerAd) BannerAdInit();
	PageLoad = true;
	}

// ------[ Dealer Locator pop up ]------------------------------------------------- //

/**
 * Base namespace setup
 */
var INTERNATIONAL = {
    globals: {
		labels: {}
	},
    pages: {
        all: {},
        home: {}        
    },
    widgets: {}
}

/**
 * Init for all pages
 */
INTERNATIONAL.pages.all.init = function () {
      
	/**
	* Initialize Dealer Locator Pop up page
	*/
	INTERNATIONAL.globals.dealerlocator = new YAHOO.widget.Panel(
		"dealerlocator",
		{ 
			width: "850px",
			height: "615px",
			constraintoviewport: true,  
			underlay:"shadow",  
			close:true,  
			visible:false,  
			fixedcenter: true,  
			draggable:false,
			zIndex: 10000,
			modal: true //Window bkg
		}
	);
	//Render the panel for screen
	INTERNATIONAL.globals.dealerlocator.render(document.body);
 
	//Create an array with all anchor with the classname "dealer-locator"
     var el = YAHOO.util.Dom.getElementsByClassName('dealer-locator','a');

     for (var i=0; el[i]; i++) {
		el[i].onclick = function() {
			var pnl = INTERNATIONAL.globals.dealerlocator;
			pnl.setBody("<iframe width='850' height='615'marginwidth='0' marginheight='0' scrolling='no' frameborder='0' src='" + this.href + "'></iframe>");
			pnl.render();
			pnl.show();
	        return false;
			}
		el[i].style.visibility = "visible";
    }

    /**
    * Initialize INTERNATIONAL Innovation popup page
    */
    INTERNATIONAL.globals.innovation = new YAHOO.widget.Panel(
	        "innovation",
		    {
		        width: "555px",
		        height: "400px",
		        constraintoviewport: true,
		        underlay: "shadow",
		        close: true,
		        visible: false,
		        fixedcenter: true,
		        draggable: false,
		        zIndex: 6,
		        modal: true //Window bkg
		    }
	    );
    //Render the panel for screen
    INTERNATIONAL.globals.innovation.render(document.body);

    //set the body to Nothing on Close
    INTERNATIONAL.globals.innovation.beforeHideEvent.subscribe(function() {
        INTERNATIONAL.globals.innovation.setBody("");
    });

    //Create an array with all anchor with the classname "overview-media"
    var el = YAHOO.util.Dom.getElementsByClassName('overview-media', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            var pnl = INTERNATIONAL.globals.innovation;
            pnl.setBody("<iframe width='555' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='400' src='" + this.href + "'></iframe>");
            pnl.render();
            pnl.show();
            return false;
        }
        el[i].style.visibility = "visible";
    }
}

// ------[ 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();
	}

// ------[ Generic Popup Window ]------------------------------------------------- //
function popWinDHTML(url,w,h,scroll,tools,name,center,baseUrl) {
	var xc = 150;
	var yc = 150;
	var str = "height=" + h + ",innerHeight=" + h;
	str += ",width=" + w + ",innerWidth=" + w;
	if(baseUrl) url = webSiteCMSUrl + url;
	if(!center) var center = false;
	if(!scroll) scroll = "auto";
	if(!tools) tools = 0;
	if(!name) name = "pop";

	if((window.screen) && (center)) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		xc = (aw - w) / 2;
		yc = (ah - h) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		}
		
		var oDiv=document.createElement("DIV");
		document.body.appendChild(oDiv);
		
		oDiv.style.position = "absolute";
		oDiv.style.top = xc + "px";
		oDiv.style.left = yc + "px";
		
		if ( scroll == 1 )
			scroll = "auto";
		else 
			scroll = "none";
		
		oDiv.innerHTML = "<div style='background:black;color:white;border: 1px solid silver;' align=right ><div style='cursor:hand;' onclick='document.body.removeChild(this.parentElement.parentElement)';>CLOSE</div></div><iframe id='"+name+"' style='width:"+w+";height:"+h+"' src='"+url+"' scrolling='"+scroll+"'></iframe>";
	}
	
// ------[ Cookie Handle ]------------------------------------------------- //
var now = new Date();
var expires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
var expires = new Date(expires)
function WriteCookie(name, value) {
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
	}

function ReadCookie(Name) {   
	var search = Name + "="   
	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         
			return unescape(document.cookie.substring(offset, end))      
			}    
		}
	}	

// ------[ Main Navigation for IE/Win ]------------------------------------------------- //
function MainNavigationInit() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("main-nav-level1");
		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() {
	this.className+=" navOver" + this.level.toString();
	}
	
function MainOut() {
	this.className=this.className.replace(" navOver" + this.level.toString(), "");
	}	

// ------[ resize Popup image ]------------------------------------------------- //

function popLargeImage(url) {
popL = window.open('','LargeImage','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=10,height=10');
popL.document.write('<html><head><title>Bombardier Recreational Products</title>');
popL.document.write('<scr'+'ipt language="JavaScript">');
popL.document.write('function resizeWin() { window.resizeTo(document.images[0].width+9,document.images[0].height+29); self.focus(); }');
popL.document.write('</scr'+'ipt>');
popL.document.write('</head>');
popL.document.write('<body onblur="self.close();" onload="resizeWin();" bgcolor="#ffffff" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0">');
popL.document.write('<img src="'+url+'" border="0">');
popL.document.write('</body></html>');
popL.document.close();
}