// Display #SUBNAV_[on] & Hide all other #SUBNAVs __________________________________________________________________________
function SUBNAVIZ(on)	
{
	POS_DIVS();	/* Re-position before pulldown: window size may change after page load */
	
	var sum = 1;	/* Total amount of Subnavs */
	var i;
	for(i=1;i<=sum;i++)
	{			
		if(i == on)		{ document.getElementById("SUBNAV_"+i).style.display = "block"; }
		else			{ document.getElementById("SUBNAV_"+i).style.display = "none"; }
	}
}



// Determine position of #SUBNAV[1-n]  ______________________________________________________________________________________
function POS_DIVS()	 
{
	var totW = document.body.clientWidth;
	var pageW = document.getElementById("PAGE").clientWidth;
	var bordW = (totW-pageW)/2;									// Left/Right spacing to #PAGE 
	var midPos = totW/2;										// body center
		
	// Position #SUBNAVs
	var pos2 = bordW+160;
	var pos3 = bordW+322;		
	if(document.getElementById("SUBNAV_2"))	{ document.getElementById("SUBNAV_2").style.left = pos2+"px"; }
	if(document.getElementById("SUBNAV_3"))	{ document.getElementById("SUBNAV_3").style.left = pos3+"px"; }
}


// Replace #MAINPIC  by new source [ns] _______________________________________________________________________________________
function SWIMG(id,ns)	
{
	document.getElementById('MAINPIC_'+id).src = "img/"+ns;
}


// Set #PAGETOPLINK visible if #PAGE.height > window.innerHeight _______________________________________________________________
function PAGETOPLINK_VIZ()	
{
	// Client window innerHeight:
	var WIN_hght;
			
		// All except MSIE:
		if(window.innerHeight)	{ WIN_hght = window.innerHeight; }

		// Explorer 6 Strict Mode:
		else if (document.documentElement && document.documentElement.clientHeight)	{ WIN_hght = document.documentElement.clientHeight; }

		// Other MSIE
		else	{ WIN_hght =  document.body.clientHeight; }

		// Height of #PAGE
		var P_hght = document.getElementById('PAGE').clientHeight;

		// Adapt if necessary
		if(P_hght > WIN_hght)	
		{ 
			document.getElementById('PAGETOPLINK').style.display = "block"; 
			document.getElementById('MAIN').style.borderBottom = "none";
		}
}


function HideBoxes()	// Hide boxes, change icon if JS enabled. Max value is a high guess.
{
	for(i=0;i<200;i++)	
	{ 
		if(document.getElementById(i))	
		{ 
			document.getElementById(i).style.display = "none"; 				
			if(document.getElementById("PM_"+i))	{ document.getElementById("PM_"+i).src = "img/plus.gif"; } // Plus-minus 
		}
	}
}


function ToggleBox(id)	// Show/hide boxes with [id]
{
	var dis = document.getElementById(id).style.display;

	if(dis == "block")	{ inv = "none"; sym = "plus.gif"; }
	else				{ inv = "block"; sym = "minus.gif"; }
		
	document.getElementById(id).style.display = inv;
	document.getElementById("PM_"+id).src = "img/"+sym;
}



function SwitchProds(sel,max,prod_id)	// Custype-display: hide all prods, show selected
{
	for(i=1;i<=max;i++)	
	{ 
		document.getElementById("PROD_"+i).style.display = "none";					// hide all prodsheets
		document.getElementById("POS_"+i).style.borderColor = "RGB(242,242,242)";	// reset highlighted
	}

	document.getElementById("PROD_"+sel).style.display = "block"; 
	document.getElementById("POS_"+sel).style.borderColor = "RGB(92,96,91)";

	// Reload:
	PAGETOPLINK_VIZ()

	document.getElementById("CTNavBox").style.margin = "50px 0px 0px 0px";		// reset bottom margin
	document.getElementById("PRODPIX_"+prod_id).style.border = "solid 1px RGB(242,242,242)";	// adapt border of pix in prodsheet
}





function CT_ProdNav(dir,max)	// Custype-display: move prods +/- (req direction & limit)
{
	// Find 3 CURRENTLY displayed prods, where i is left one.
	var i = 1;
	for(i=1;i<=max;i++)
	{
		var j = i+1;		// middle box
		var k = i+2;		// right box	
		
		if(		document.getElementById("POS_"+i) && document.getElementById("POS_"+i).style.display == "block" 
			&&	document.getElementById("POS_"+j) && document.getElementById("POS_"+j).style.display == "block" 
			&&	document.getElementById("POS_"+k) && document.getElementById("POS_"+k).style.display == "block")
		{
			var leftProd = i;
			var midProd = j;
			var rightProd = k;
		}	
	}
		
	var prevProd = leftProd-1;	
	var nextProd = rightProd+1;	
	
	// Move in direction "dir"
	if(dir == "fwd" && document.getElementById("POS_"+nextProd) )
	{
		document.getElementById("POS_"+leftProd).style.display = "none";
		document.getElementById("POS_"+nextProd).style.display = "block";
	}

	if(dir == "rew" && document.getElementById("POS_"+prevProd) )
	{
		document.getElementById("POS_"+rightProd).style.display = "none";
		document.getElementById("POS_"+prevProd).style.display = "block";
	}


	
	// Toggle Nav Btns: find 3 NEWLY displayed prods, where a is left one
	var a = 1;
	for(a=1;a<max;a++)
	{
		var b = a+1;		// middle box
		var c = a+2;		// right box	
		
		if(		document.getElementById("POS_"+a) && document.getElementById("POS_"+a).style.display == "block" 
			&&	document.getElementById("POS_"+b) && document.getElementById("POS_"+b).style.display == "block" 
			&&	document.getElementById("POS_"+c) && document.getElementById("POS_"+c).style.display == "block")
		{
			if(a != 1)		{ document.getElementById("RewBtn").style.visibility = "visible"; }
			else			{ document.getElementById("RewBtn").style.visibility = "hidden"; }
			
			if(c == max)	{ document.getElementById("FwdBtn").style.visibility = "hidden"; }
			else			{ document.getElementById("FwdBtn").style.visibility = "visible"; }	
		}	
	}
}
