// JavaScript Document

function AddEventListener(element, eventType, handler, capture)
{
	if (element.addEventListener)
		element.addEventListener(eventType, handler, capture);
	else if (element.attachEvent)
		element.attachEvent("on" + eventType, handler);
}
//the changed copy for the left bar
homeHTML='<p>The Historic Division of MARS was established in 2006, with the vision of becoming the undisputed leader in chocolate history.  Our mission is to relentlessly pursue and share chocolate\'s rich past, by creating authentically historic chocolate experiences that allow our consumers to enjoy the fusion of chocolate history and MARS Chocolate excellence.</p>'
window.onload = function() {
	// saves the height of the original Links area
	origH = document.getElementById('lLinks').offsetHeight;
	//saves the HTML in the side bar
	var origHTML = document.getElementById('lLinks').innerHTML;
	//the logo
	homeLink=document.getElementById("logo");
	//Assigns rollovers to the logo to show the home copy
	AddEventListener(homeLink, "mouseover", function(e)
	{
		document.getElementById('lLinks').innerHTML=homeHTML;
		document.getElementById("lLinks").style.minHeight=origH-24+"px";
	}, false);
	AddEventListener(homeLink, "mouseout", function(e)
	{
		document.getElementById('lLinks').innerHTML=origHTML;
	}, false);
};



//determines the scoll position... used for placing popup images
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}


//shows the video popup
function videoPop(videoName,basePath,size) {
	if(!size) {size='sm';}
	bodyH=document.body.offsetHeight;
	var blackBack=document.getElementById("blackBack");
	//creates/scales the blackBackground/container to fill the entire page.
	if(!blackBack) {
		document.body.innerHTML+='<div id="blackBack" class="fullScreen"></div><div id="popContainer" class="fullScreen" onclick="hideFull();"><div id="popCenter"><div id="videoContainer"></div></div></div>';
	}
	//size must be lowercase
	size=size.toLowerCase(); 
	//videoName=videoName.parentNode.parentNode.id;
	//scales the blackBackground/container to fill the entire page.
	var videoContainer=document.getElementById("videoContainer");
	var blackBack=document.getElementById("blackBack");
	var popContainer=document.getElementById("popContainer")
	blackBack.style.display="block";
	popContainer.style.display="block";
	//adds the video container... to be replaced by swf embedd
	var popCenter=document.getElementById("popCenter");
	//Finds the height of the content container
	var container = document.getElementById("shell");
	var contY = container.offsetHeight;
	//resizes the two DIV's based on the container size + menu elements (134px)
	popContainer.style.height=contY+38+"px";
	blackBack.style.height=contY+38+"px";
	
	//decides the size
	if(size=='sm'){vWidth=320; vHeight=240;}
	if(size=='med'){vWidth=480; vHeight=360;}
	//scales center/white border based on size
	var popCenter=document.getElementById("popCenter");
	popCenter.style.width=vWidth+"px";
	popCenter.style.height=vHeight+"px";
	//Close button
	var imgX = new Image();
	imgX.onload = function() {
		popCenter.innerHTML+='<img src="'+imgX.src+'" id="closeX" name="closeX" onclick="hideFull();" />';
		//middle of the screen, unless image > screen height
		var pageScroll =getPageScroll();
		bodyH=document.body.offsetHeight;
		if(bodyH>vHeight+20) {
			var centerPic=(bodyH-vHeight)/2;
			popCenter.style.top=pageScroll[1]+centerPic+"px"; 
		} else {
			popCenter.style.top=pageScroll[1]+"px"; 
		}
	//sets/inserts the video
	//inits
	var flashvars = {
		MM_ComponentVersion: "1",
		skinName: basePath+"scripts/Clear_Skin_2",
		autoPlay: "true",
		autoRewind: "true",
		streamName: "../"+basePath+'media/video/'+videoName
	};
	//var flashvars = false;
	var params = {
		scale: "noscale",
		salign: "tl"
	};	
	var attributes = {
		id: "Vid",
		name: "Vid"
	};
	swfobject.embedSWF(basePath+"scripts/FLVPlayer_Progressive.swf", "videoContainer", vWidth, vHeight, "8.0.0", false, flashvars, params, attributes);
	}
	imgX.src = "http://www.pulsefactors.com/img/closebox.png";
}
function hideFull() {
	var blackBack=document.getElementById("blackBack");
	var popContainer=document.getElementById("popContainer");
	var popCenter=document.getElementById("popCenter");
	blackBack.style.display="none";
	popContainer.style.display="none";
	video=document.getElementById('Vid');
	if(video) {popCenter.innerHTML='<div id="videoContainer"></div>';}
}



















