//This function preloads the global navigation elements
var navRoll = false;
//Set this variable to false so no global rollovers will work until all preloading is done.
function plGnav()
{
	plImages();
	navRoll = true;
	sfHover();
	randomNum(4);
	IEtlHack();
}

//This function preloads rollover images with a & i suffixes for active and inactive
//The function can preload any number of images.
//usage: uPreload( object name, directory of image, extension of image )
var imgSuffix = new Array('i', 'a');
function uPreload(imgName, imgPath, imgExt)
{
	for (i=0; i < imgSuffix.length; i++) {
		eval( imgName + imgSuffix[i] + " = new Image();" );
  		eval( imgName + imgSuffix[i] + ".src = '" + imgPath + '/' + imgName + imgSuffix[i] + imgExt + "';" );
    }
}
 
function plImages()
{
	var linkArray = document.getElementsByTagName("img");
    for (var loop=0; loop<linkArray.length; loop++)
    {
    	imgClassArray = linkArray[loop].className.split(' ');
        for (var i=0; i<imgClassArray.length; i++)
        {
         	if (imgClassArray[i] == "pl")
         	{
    			var imgPath = linkArray[loop].src.substring( 0, linkArray[loop].src.lastIndexOf( '/' ));
    			uPreload( linkArray[loop].id, imgPath, linkArray[loop].src.substring( linkArray[loop].src.lastIndexOf( '.' ) ) );
         	}
        }
    }
}
 
//This function is for navigation rollover images; uName is name of graphic, uState is on, off or over state
function nr(uName, uState)
{
   if(navRoll)
   {
      document.images[uName].src = self[uName + uState].src;
   }
}

function sfHover() 
{
	var browserName=navigator.appName;
	if (browserName=="Microsoft Internet Explorer" && document.getElementById("brndslct"))
	{
		var sfEls = document.getElementById("brndslct").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

function randomNum(max)
{
	var random_num = (Math.round((Math.random()* (max - 1) )+1))
	return(random_num);
}

function embdFlashWxml(flashWidth, flashHeight, flashSwf, swfBase, mXml)
{
	if(!mXml)
	{
		var mXml = 'null';
	}
	var mPc = '';
   	{
   		var flshUrl1 = '<param name="movie" value="' + flashSwf + '?' + mXml + '" />';
     	var flshUrl2 = '<embed src="' + flashSwf + '?' + mXml + '" base="' + swfBase + '" quality="high" width="' + flashWidth + '" height="' + flashHeight + '" wmode="transparent" name="tl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
     	mPc += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + flashWidth + '" height="' + flashHeight + '" id="tl" align="middle">';
	  	mPc += '<param name="allowScriptAccess" value="sameDomain" />';
	  	mPc += '<param name="base" value="' + swfBase + '"/>';
	 	mPc += flshUrl1;
	  	mPc += '<param name="quality" value="high" />';
	  	mPc += '<param name="wmode" value="transparent" />';
	  	mPc += flshUrl2;
	 	mPc += '</object>';
   	}
	//alert(mPc);
	document.write(mPc);
}

function hmPgFlash()
{
	var rndm = randomNum(4);
	var HmXml = 'xmlPath=../xml/homepagedata' + rndm + '.xml';
	embdFlashWxml(756, 495,'swf/swf/homepage1.swf','swf/swf',HmXml);
}

function tlFlash(webRoot,pageKey,mode)
{
	var tSwf = webRoot+'/swf/swf/timeline.swf';
	var tBase = webRoot+'/swf/swf';
	var tKey = 'timelineName='+pageKey;
	var tXmlPath = 'xmlPath=../xml/timelinedata.xml';
	var tImgPath = 'imagePath=../images';
	var tmode = 'mode='+mode;
	var tQString = tKey+'&'+tXmlPath+'&'+tImgPath+'&'+tmode;
	embdFlashWxml(314, 573,tSwf,tBase,tQString);
}

//Had to add the following function (aka HACKJOB) because IE intermittenly decided to not show the timeline and associated elements
//This function ensures that it will show up.
function IEtlHack()
{
	var browserName=navigator.appName;
	if (browserName=="Microsoft Internet Explorer" && document.getElementById('timeline'))
	{
		document.getElementById('timeline').style.display="block";
		if (document.getElementById('timeline_shadow'))
		{
			document.getElementById('timeline_shadow').style.display="block";
		}
	}
}

function lpAnim(imgRoot)
{
	if (document.body.id)
	{
		var bId = document.body.id;
		imgRoot = imgRoot + '/i/'
		var anim = '';
		switch(bId)
		{
			case "BR" :
			anim += imgRoot + 'brands/';
			break
			case "CO" :
			anim += imgRoot + 'company/';
			break
			case "CA" :
			anim += imgRoot + 'careers/';
			break
			case "HE" :
			anim += imgRoot + 'heritage/';
			break
			case "CI" :
			anim += imgRoot + 'citizenship/';
			break
			case "NE" :
			anim += imgRoot + 'news/';
			break
			case "FI" :
			anim += imgRoot + 'financials/';
			break
		}
		document.write('<img src="'+anim+'lp_anim.gif" alt="" />');
	}
}

function openPopupWindow(strURL, intWidth, intHeight,scrll)
{	
	var scrollB;
	if(!scrll)
	{
		scrollB = 'no';
	}
	else 
	{
		scrollB = scrll;
		intWidth = parseInt(intWidth) + 25;
	}
	var today = new Date();
	var timestamp = today.getTime();
	var iMyWidth;
	var iMyHeight;
	//Added twelve pixels to ALL popup heights to compensate for newer/larger popup header logo. 
	iMyWidth =(window.screen.width / 2) - (intWidth / 2 + 10);
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyHeight =(window.screen.height /2) - (intHeight / 2 + 15);
	//half the screen height minus half the new window height (plus title and status bars).
	window.open(strURL,timestamp,"width="+intWidth+",height="+intHeight+",left="+iMyWidth+",top="+iMyHeight+",screenX="+iMyWidth+",screenY="+iMyHeight+ ",scrollbars=" + scrollB);
}

function wPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
   }
   else 
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
   }
   var iMyWidth;
   var iMyHeight;
   wHeight = wHeight;
   //Added twelve pixels to ALL popup heights to compensate for newer/larger popup header logo. 
   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
   zWin.focus();
}

function openBrowserWindow(strURL)
{	
	if(strURL.length > 0)
	{
		window.open(strURL);
	}
}