
var target;
function headerOverFlash(num){
		//menuAllOff(num);
		//document.getElementById("menu"+num).style.visibility = "visible";
		//menuStartMouseTrack();
		menu(num)
		
}
function headerOutFlash(num){
		//menuAllOff(-1);
}


function menuCheckPos(){
	//
}
//document.onmousemove = menuCheckPos;
// START SETUP CODE
var NS = (navigator.appName == "Netscape");
var IE4 = document.all; // checks for IE 5.X as well
var NS4 = document.layers;
mac = navigator.appVersion.indexOf("Mac");
if (mac>=0) {mac=1} else {mac=0}
NS6a = document.getElementById;
if(NS6a && NS) {NS6=true} else {NS6=false}

var compliant = document.getElementById;
if (compliant) {dhtml=1} else {dhtml=0}


var menuHeight=24;
var numMenus=9;
var menuOn=-1;
var flashPresent=0;
var gatewayLock=-1;
var num=0;
var holderRef=refConstructor("Holder");

//Show Layer
function showlay(name){
	if (NS4) document.layers[name].visibility='show';
	if (IE4) document.all[name].style.visibility='visible';
	if (compliant) document.getElementById(name).style.visibility='visible';
} 
//Hide Layer 
function hidelay(name){
	if (NS4) document.layers[name].visibility='hide';
	if (IE4) document.all[name].style.visibility='hidden';
	if (compliant) document.getElementById(name).style.visibility='hidden';
}
//Does Layer Exist? 
function layExist(name){
	if (NS4 && (document.layers[name] != null)) return true;
	if (IE4 && (document.all[name] != null)) return true;
	if (compliant && (document.getElementById(name) != null)) return true;
}

function MakeArray(n){
   this.length = n
   for (var i = 1; i<=n; i++) {
	  this[i] = new Image()
   }
   return this;
}

var minPos_x = new Array;
var maxPos_x = new Array;
var minPos_y = new Array;
var maxPos_y = new Array;

/***********************/
//var imageName = new Array("mtvcom","music","news","movies","onair","community","shop","mtv2","mtvu");
/***********************/

//var imageName = new Array("mtv","music","news","movies","shows","community","shop","mtv2","mtvu");
var imageName = new Array("mtv","music","news","movies","shows","community","shop","mtv2","mtvu");


if (document.images) {
	header_Over = new MakeArray(numMenus);
	header_Out = new MakeArray(numMenus);
	
	for (imgX=0;imgX<numMenus;imgX++){
	
		//header_Out[imgX] = new Image(); 
		//header_Over[imgX] = new Image();
	
		/*********************************/
		//header_Out[imgX].src = "/sitewide/headerfooter/images/btn_nav_" + imageName[imgX] + ".gif";
		/********************************/	
		
		//header_Out[imgX].src = "/sitewide/headerfooter/nav_and_menus/images/btn_nav_" + imageName[imgX] + ".gif";
		
	
		/*********************************/
		//header_Over[imgX].src = "/sitewide/headerfooter/images/btn_nav_" +imageName[imgX] + "_f2.gif";
		/********************************/
		
		//header_Over[imgX].src = "/sitewide/headerfooter/nav_and_menus/images/btn_nav_" +imageName[imgX] + "_f2.gif";
		
	
	}
	
}

function imgFlip(imageName,imageSrc) {
 // if (document.images)
   // document.images[imageName].src = eval(imageSrc + ".src");
}

function headerOver(num){
	if ((document.images) && (num != gatewayLock)){
		//eval ("document." + imageName[num] + ".src ='" + header_Over[num].src +"'");
	}
	return true;
}
function headerOut(num){
	if ((document.images) && (num != gatewayLock)){
	//eval ("document." + imageName[num] + ".src ='" + header_Out[num].src +"'")
	}
}

function headerOutX(num){
	if (document.images){
		if(dhtml==0 && (num != gatewayLock)) {
		//	eval ("document." + imageName[num] + ".src ='" + header_Out[num].src +"'")
		}
	}
}

// MENU FUNCTIONS

function refConstructor(menuId) {
	var prefix = "document.getElementById('menu" + menuId + "')";
	return prefix;
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}
	
function menuInit() {
	//alert('starting menuInit function');
	for (layerInit = 1;layerInit<numMenus;layerInit++) {
		var layerRef =  refConstructor(layerInit);
		
		var layerDim_y  = eval(layerRef + ".offsetHeight + menuHeight");
		var layerDim_x  = eval(layerRef + ".offsetWidth");
		var layerPos_y = findPosY(eval(layerRef));
		var layerPos_x = findPosX(eval(layerRef));
		
		minPos_y[layerInit] = (layerPos_y);
		maxPos_y[layerInit] = (layerPos_y + layerDim_y);
		minPos_x[layerInit] = (layerPos_x);
		maxPos_x[layerInit] = (layerPos_x + layerDim_x);		
		
	}
	if (flashPresent==1){ toggleFlash("visible") }
}

function reportEvent(e) 
{
	var posx = 0;
	var posy = 0;
	var layerRef =  refConstructor(menuOn)

	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		mousePos_x = e.pageX;
		mousePos_y = e.pageY + menuHeight;
	}
	else if ((e.clientX || e.clientY) && !mac)
	{
		mousePos_x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		mousePos_y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop + menuHeight;
	}
	else if ((e.clientX || e.clientY) && mac)
	{
		mousePos_x = e.clientX + document.body.scrollLeft;
		mousePos_y = e.clientY + document.body.scrollTop + menuHeight;
	}

	if ((mousePos_y > maxPos_y[menuOn]) || (mousePos_x < minPos_x[menuOn]) || (mousePos_x > maxPos_x[menuOn]) ||(mousePos_y < minPos_y[menuOn]))
	{
		eval(layerRef + ".style.visibility = 'hidden'");
		v= menuOn;
		if (menuOn != gatewayLock) {headerOut(v);};
		
		menuOn=-1;
		
		if (flashPresent==1){
			toggleFlash("visible") 
		}		
		document.onmousemove = null;
	}
}

function move() {
	if (dhtml==1){
		if (IE4) { document.onmouseover = null }
		else{ document.releaseEvents(Event.MOUSEOVER)};
		if (flashPresent==1){ toggleFlash("hidden") }
		var layerRef =  refConstructor(menuOn);
		eval(layerRef + ".style.visibility = 'visible'");
	}
}

function xx() {
	move();
	if(document.layers) {document.captureEvents(Event.MOUSEMOVE)};
	document.onmousemove = reportEvent;
}

// FIRST CALL TO THE MENU FUNCTIONS
function menu(m) {
	if (m != menuOn) {
		v = m; 
		headerOver(v);
		//if(dhtml==1){
			//alert.('doing dhtml menus');
			var layerRef =  refConstructor(menuOn)
			if (menuOn != m && menuOn!=-1){
				v2 = menuOn;
				if (menuOn+1 != (gatewayLock)) {headerOut(v2);};
				eval(layerRef + ".style.visibility = 'hidden'");
			}
			menuOn = m ;
		xx();
		//};
	}
}
// END MENU CALLS



//for publishing
gatewayLock = null;
window.onload = menuInit;
window.onresize = menuInit;
	