// Declare and set variables ----------------------------
var ie4 = (document.all)? true:false;
var ie5_ns6 = (document.getElementById)? true:false;

var mlCurrentID = 0;
var mbInSubMenu = false;
var mbInMenu = false;
var timerID = 0;
var loImageWindow = null;
var lsBGName = '';

/* Array used in creating the popup submenu - [[Menu Text, Menu Page Link],[Menu Text, Menu Page Link]... */
var SubPages = new Array();
// SubPages[1] = [['Powell Peralta','PowellDecks.htm'],['Santa Cruz','SantaCruzDecks.htm'],['SMA','SMADecks.htm'],['Blind','BlindDecks.htm'],['Birdhouse','BirdhouseDecks.htm'],['Bulldog','BulldogDecks.htm'],['Serial Killer','SerialKillerDecks.htm'],['Current Riders','CurrentRiders.htm']];
SubPages[1] = [['Powell Peralta','PowellDecks.htm'],['Santa Cruz','SantaCruzDecks.htm'],['Birdhouse','BirdhouseDecks.htm'],['Bulldog','BulldogDecks.htm'],['Serial Killer','SerialKillerDecks.htm'],['Current Riders','CurrentRiders.htm']];
SubPages[2] = [['Powell Peralta','PowellStickers.htm'],['Santa Cruz','SantaCruzStickers.htm']];
//,['Misc. Stickers','MiscStickers.htm']

/*
Page Background image arrays - Each brand has an ID to determine the BG image array item used on the page (lnBrandID is set on page and can be mixed)
[['BGImageName1'],[BGImageName2]...
Key ----------
0 - Home
1 - PP
2 - SC
3 - SMA
4 - Blind
5 - Birdhouse
6 - Bulldog
7 - Links
8 - DotC
9 - GuyGrand
10 - Sims	
*/

var loBGImage = new Array();
	loBGImage[0] = [['NS_NeuronLogo_BG']];
	loBGImage[1] = [['PP_CabBearingDragon_BG'],['PP_GelfandTank_BG'],['PP_HawkBird_BG'],['PP_HawkSkull_BG'],['PP_McGillPlane_BG'],['PP_McGillSS_BG'],['PP_MullenChess_BG'],['PP_RipperSkull_BG'],['PP_SteadhamSpade_BG'],['PP_WelinderSkull_BG']];
	loBGImage[2] = [['SC_SalbaVoodoo_BG'],['SC_GrossoDevil_BG'],['SC_GrossoRagdoll_BG'],['SC_JesseeNeptune_BG'],['SC_JesseeSungod_BG'],['SC_ObrienReaper_BG'],['SC_SalbaWitch_BG'],['SC_ScreamingHand_BG'],['SC_SCSkull_BG'],['SC_Roskopp1_BG'],['SC_Roskopp2_BG'],['SC_Roskopp3_BG'],['SC_Roskopp4_BG'],['SC_StreetCreep_BG']];
	loBGImage[3] = [['SMA_NatasPanther1_BG']];
	loBGImage[4] = [['BD_SkullBanana_BG'],['BD_LeeDodo_BG']];
	loBGImage[5] = [['BH_HawkApe_BG'],['BH_KlienApe_BG'],['BH_LasekApe_BG'],['BH_SantosApe_BG'],['BH_SumnerApe_BG'],['BH_VegasApe_BG']];
	loBGImage[6] = [['BS_Bulldog_BG']];
	loBGImage[7] = [['NS_NeuronLogo_BG'],['PP_CabBearingDragon_BG'],['PP_GelfandTank_BG'],['PP_HawkBird_BG'],['PP_HawkSkull_BG'],['PP_RipperSkull_BG'],['PP_SteadhamSpade_BG'],['SC_JesseeNeptune_BG'],['SC_JesseeSungod_BG'],['SC_SalbaVoodoo_BG'],['SC_ScreamingHand_BG'],['SC_GrossoRagdoll_BG'],['SC_GrossoDevil_BG'],['SC_Roskopp1_BG'],['SC_Roskopp2_BG'],['SC_Roskopp3_BG'],['SC_Roskopp4_BG'],['SC_StreetCreep_BG']];
	loBGImage[8] = [['PP_CabDragon_BG'],['PP_CabDragonBats_BG'],['PP_HawkClaw_BG'],['PP_VallelyElephant_BG'],['PP_HawkBird_BG'],['PP_HawkSkull_BG'],['PP_SteadhamSpade_BG'],['PP_McGillSS_BG'],['PP_MullenChess_BG'],['PP_GuerreroMask_BG'],['SC_JesseeNeptune_BG'],['Sims_StaabScientist_BG'],['PP_McGillFish_BG'],['PP_CabCDragon_BG']];
	loBGImage[9] = [['SMA_NatasPanther1_BG'],['SC_GrossoDevil_BG'],['PP_McGillPlane_BG'],['PP_HawkBird_BG'],['PP_HawkBird_BG'],['PP_SteadhamSpade_BG'],['PP_McGillSS_BG'],['PP_GelfandTank_BG'],['BD_SkullBanana_BG'],['PP_RipperSkull_BG'],['PP_HawkSkull_BG'],['PP_CabBearingDragon_BG']];
	//loBGImage[10] = [['Sims_StaabScientist_BG']];
	// ,['SC_RoskoppFace_BG'],

function getBGImage(pBrandID){
// there are n-1 images in the array therefore need to generate random number between 0 and (n - 1)
	var lnRandNum = Math.round((loBGImage[pBrandID].length-1)*Math.random());
	lsBGName = loBGImage[pBrandID][lnRandNum];
}

function DoNav(pID,pTop,pNavigate) {
	mbInSubMenu = false;
	HideMenus(false);
	mbInMenu = true;
	
	mlCurrentID = pID;
	if (SubPages[pID] && !pNavigate){
		//requires submenu
		DisplayMenu(GetNavTable(SubPages[pID]),pID);
	}
	return true;
}

function DisplayMenu(pText,pX) {
	var loFrame = top.frames['NS_Main'];
	var loDiv;
	lsDiv = 'SubMenu';

	if(ie4 || ie5_ns6){
		if(document.all){
			//ie4 + ie5
			if (loFrame.document.all(lsDiv)){
				loDiv = loFrame.document.all(lsDiv);
				loDiv.innerHTML = pText;
				loDiv.style.top = loDiv.offsetParent.scrollTop;
				loDiv.style.left = (pX  * 60 + 200) + loDiv.offsetParent.scrollLeft;
				loDiv.style.width = 210;
			}
		}
		else{
			//ns6
			if (loFrame.document.getElementById(lsDiv)){
				loDiv = loFrame.document.getElementById(lsDiv);
				loDiv.innerHTML = pText;
				loDiv.style.top = loFrame.pageYOffset;
				loDiv.style.left = (pX  * 60 + 200) + loFrame.pageXOffset;
				loDiv.style.width = 210;
			}
		}
		var loFunction = new Function('mbInSubMenu = true');
		loDiv.onmouseover = loFunction;
		loFunction = new Function('mbInSubMenu = false;this.visibility = "hidden";');
		loDiv.onmouseout = loFunction;
		loDiv.style.display = 'block';
		loDiv.style.visibility = 'visible';
	}
	else {
		// NS 4x
		loDiv = loFrame.document.layers[lsDiv];
		loDiv.document.open();
		loDiv.document.write(pText);
		loDiv.document.close();
		var loFunction = new Function('if (!mbInSubMenu) {DoNav(' + mlCurrentID +',true);mbInSubMenu = true}');
		loDiv.onmouseover = loFunction;
		loFunction = new Function('mbInSubMenu = false;HideMenus(true,0);');
		loDiv.onmouseout = loFunction;
		loDiv.top = loFrame.pageYOffset;
		loDiv.left = (pX  * 60 + 200) + loFrame.pageXOffset;
		loDiv.visibility = 'show';
	}
}

function HideMenus(pDelay,pOutofMenu){
	var i=0;
	if (pDelay){
			if(timerID) {
				clearTimeout(timerID);
			}
			if (SubPages[mlCurrentID]) {
				timerID = setTimeout("HideMenus()",1000);
				mbInMenu = false;
				return true;
			}
			mbInMenu = false;
	}
	var loFrame = top.frames['NS_Main'];
	if (loFrame) {
		if(ie4 || ie5_ns6){
			var loMenu = (document.all) ? loFrame.document.all['SubMenu'] : loFrame.document.getElementById('SubMenu');
			if (loMenu) {
				if (!mbInSubMenu && !mbInMenu) {
					loMenu.style.visibility = 'hidden';
					loMenu.style.display = 'none';
				}
			}
		}
		else {	
			var loMenu = loFrame.document.layers['SubMenu'];
			if (!mbInSubMenu && !mbInMenu) {
				if (loMenu) {
					loMenu.visibility = 'hide';
				}
			}
		}
	}
}

function GetNavTable(pArray){
	var lsText = '';
	var lsText2;
	if(ie5_ns6 || ie4){
		var lsMargin = 'style="margin:2;"';
	}
	else{
		var lsMargin = '';
	}
	for (var i=0;i<pArray.length;i++){
		lsText2 = '';

			//requires submenu
			if (ie5_ns6 || ie4) {
				lsText = lsText + '<tr><td nowrap onclick="window.location.href=\'' + pArray[i][1] + '\';parent.frames[\'NS_Header\'].DoNav(' + mlCurrentID + ',true, true);" onmouseover="this.className=\'NoULNavLinkHover\'" onmouseout="this.className=\'NoULNavLinkEmpty\';	top.frames[\'NS_Header\'].HideMenus(true,2);">';
				lsText2 = lsText2 + '<a class="NoUL">';
				lsText = lsText + lsText2 + '&nbsp;' + pArray[i][0] + '</a>'
				lsText = lsText + '</td></tr>';
			}
			else {
				lsText = lsText + '<tr><td><ilayer width="100%"><layer width="100%" onmouseover="this.bgColor=window.document.classes[\'NoULNavLinkHover\'].all[\'backgroundColor\'];" onmouseout="this.bgColor=window.document.classes[\'NoULNavLinkEmpty\'].all[\'backgroundColor\'];">';
				lsText2 = lsText2 + '<a href="' + pArray[i][1] + '" onclick="parent.frames[\'NS_Header\'].DoNav(' + mlCurrentID + ',true, true)" class="NSNoUL">';
				lsText = lsText + lsText2 + '&nbsp;' + pArray[i][0] + '</a>'
				lsText = lsText + '</layer></ilayer></td></tr>';
			}

		}		
	if (ie5_ns6 || ie4) {
		return '<table ' + lsMargin + ' width="100%" cellspacing="0" cellpadding="0">' + lsText + '</table>';
	}
	else {
		return '<layer class="NSSubMenu"><table width="100%" cellspacing="0" cellpadding="0">' + lsText + '</table></layer>';	
	}
}

//----Pop Window -------------------
function CalculateDimensions(pImageName) {
	var loDetailImage = new Image();
	loDetailImage.src ='images/' + lvImageType + '/' + pImageName + '.jpg';
  if (loDetailImage.width==0 || loDetailImage.height==0 ){
		setTimeout("CalculateDimensions('"+pImageName+"')",500);
  }
  else{
		display(loDetailImage.src,loDetailImage.width,loDetailImage.height);
  }
}

function display(pImagePath,pImageWidth,pImageHeight) {
// if the image is larger than 750x550 only display those dimentions and scroll the rest
// 18 for the scroll bar 62 for the button and padding
  var lvWinWidth = pImageWidth>750 ? 750 : pImageWidth;
  var lvWinHeight = pImageHeight>550 ? 550 : pImageHeight+62;
  var lsVScrollWidth = pImageHeight>550 ? 18 : 0;
  
  CloseDetailWin();
  loImageWindow = window.open("","","width="+(lvWinWidth+lsVScrollWidth)+",height="+lvWinHeight+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0");
  loWinDoc = loImageWindow.document;
  loWinDoc.open("text/html");
  loWinDoc.writeln('<HTML><HEAD><meta http-equiv="imagetoolbar" CONTENT="no"><TITLE>Neuron Skates Detail Window</TITLE></HEAD>');
  loWinDoc.writeln('<BODY marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bgcolor="#000000" scroll="auto">');
  loWinDoc.writeln('<p align="center"><IMG SRC="'+pImagePath+'" WIDTH='+pImageWidth+' HEIGHT='+pImageHeight+'><br><br>');
  loWinDoc.writeln('<a href="javascript: void(0);" onClick="top.close()"><IMG SRC="images/NS_Button_Close.jpg" border="0" width="56" height="26"></a>');
  loWinDoc.writeln('</p></BODY></HTML>');
  loWinDoc.close();
}

//Close image detail window
function CloseDetailWin() {
	if (loImageWindow && !loImageWindow.closed){
		loImageWindow.close();
  }
}