// JavaScript Document

//set the onload function to initPage
window.onload = initPage;

/* window 'load' attachment */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


function printPage() {
	print(document);
	}
	
function selectThis(obj,state){
	
	if(state){
		
		obj.className="subNavItemSelected";
		
	} else {
		obj.className="subNavItem";
	}
}


function clickThis(obj){
window.location.href=obj.firstChild.href;
}

function closeFeatures (obj){
	for (var x=0; x < arrFeatures.length; x++){
		if (arrFeatures[x] != obj){
		
		arrFeatures[x].className = "featureTitle";
		
		console.debug(arrFeatures[x].className);
		arrDivs = arrFeatures[x].parentNode.getElementsByTagName('Div');
			console.debug(arrDivs.length);
			
			for (var n=0; n < arrDivs.length; n++){
				tkObj = arrDivs[n]
				
				if (tkObj.className == "featureDesc"){
				 //we've got an tkoddetail panel. 
				  
					 tkObj.style.display = "none";
					
				 }
				 
			}
		
		
		
		}
	}
}

function initNav(){

dNav = document.getElementById('divNav');

arrLinkDivs = dNav.getElementsByTagName('div');
	
	//loop through returned array of div elements and add mouseover/out and click events if they are subnavitems
	for (n=0; n < arrLinkDivs.length; n++){
	
		if (arrLinkDivs[n].className=="subNavItem" || arrLinkDivs[n].className=="subNavItem lastNav"){
		
			//add the on mouseover /out functionality
			arrLinkDivs[n].onmouseover = function(){this.style.cursor="pointer";selectThis(this,true)};
			arrLinkDivs[n].onmouseout = function(){this.style.cursor=null;selectThis(this,false)};
			
			//get the a tag href and make the onclick event for this div
			aArr = arrLinkDivs[n].getElementsByTagName("a");
			arrLinkDivs[n].href = aArr[0].href;
			arrLinkDivs[n].onclick = function(){ window.location = this.href; }
			
		}
		
	}
	
	//finallay, preload the bg image
	preload = new Image();
    preload.src = "/images/layout/nav_hover.jpg";
}


function initProductBoxes(arrProductBoxes){
	
	//loop through DIVS ,and add mouseover/out and onclic events to any product boxes
	for (n=0; n< arrProductBoxes.length; n++){
		
		//set obj to [n]th object in array for shorthand
		obj = arrProductBoxes[n];
	
		if (obj.className=="productBox"){
			
			//mouseOver
			obj.onmouseover = function() {
				
				this.className = "productBox productBoxOver";
			}
			
			//mouseout
			obj.onmouseout = function() {
				
				this.className = "productBox";
			}
			
			//onclick
			//first get handle on the more info link
			arrLinks = obj.getElementsByTagName('A');
			if (arrLinks.length > 0){
				obj.linkTarget = arrLinks[0].href;
			
			obj.onclick = function(){
			window.location = this.linkTarget;	
			};
			
			}
		
			
		}
	
	}

	//finallay, preload the bg image
	preload = new Image();
    preload.src = "/images/layout/product-boxes/bg-red.jpg";
}

function initTKoDPanels(arrPanels){
	
	//loop through DIVS ,and add mouseover/out and onclic events to any product boxes
	for (n=0; n< arrPanels.length; n++){
		
		//set obj to [n]th object in array for shorthand
		obj = arrPanels[n];
	
		if (obj.className=="TKoDTab"){
			
			//mouseOver
			obj.onmouseover = function() {
				
				//this.className = "productBox productBoxOver";
				this.style.cursor = "pointer";
			}
			
			//mouseout
			obj.onmouseout = function() {
				
				//this.className = "productBox";
				this.style.cursor = null;
			}
			
			//onclick
			//first get handle on the more info link
			obj.onclick = function(){
			
			arrDivs = this.parentNode.getElementsByTagName('Div');
			
			for (x=0; x < arrDivs.length; x++){
				tkObj = arrDivs[x]
				
				if (tkObj.className == "TKoDDetails"){
				 //we've got an tkoddetail panel. let's set it's display property
				 if (tkObj.style.display != "none"){
					
					tkObj.style.display = "none";
				 } else {
					 tkObj.style.display = "block";
				 }
					
				 }
				 
				}
			
			}
			
			}
		
			
	}
	
	

	//finallay, preload the bg image
	preload = new Image();
    preload.src = "/images/layout/product-boxes/bg-red.jpg";
}

function initSeriesFeatures(arrPanels){
	
	arrFeatures = new Array();
	
	//loop through DIVS ,and add mouseover/out and onclic events to any product boxes
	for (n=0; n< arrPanels.length; n++){
		
		//set obj to [n]th object in array for shorthand
		obj = arrPanels[n];
		
		
	
		if (obj.className=="featureTitle" || obj.className=="featureTitleCollapse"){
			
		arrFeatures.push(obj);	
			
			//mouseOver
			obj.onmouseover = function() {
				
				//this.className = "productBox productBoxOver";
				this.style.cursor = "pointer";
			}
			
			//mouseout
			obj.onmouseout = function() {
				
				//this.className = "productBox";
				this.style.cursor = null;
			}
			
			//onclick
			//first get handle on the more info link
			obj.onclick = function(){
			
			
			
			arrDivs = this.parentNode.getElementsByTagName('Div');
			
			for (x=0; x < arrDivs.length; x++){
				tkObj = arrDivs[x]
				
				if (tkObj.className == "featureDesc"){
				 //we've got an tkoddetail panel. 
				 
				 // now let's set it's display property
				 if (tkObj.style.display != "block"){
					
					tkObj.style.display = "block";
					this.className="featureTitleCollapse";
					//close the other feature blocks
			closeFeatures (this);
				 } else {
					 tkObj.style.display = "none";
					 this.className="featureTitle";
				 }
					
				 }
				 
				}
			
			}
			
			}
		
			
	}
	
	

	//finallay, preload the bg image
	preload = new Image();
    preload.src = "/images/layout/product-boxes/bg-red.jpg";
}



function initPage(){
	
//we know there's anav on every page, so do that	
	initNav();
	
	//look to see if there are any productBoxes divs on this page
	bodyContentDivs = document.getElementById('divBodyContent');

	arrDivs = bodyContentDivs.getElementsByTagName('div');
	if (arrDivs.length > 0) {
		//init any product boxes
		initProductBoxes(arrDivs);
		initTKoDPanels(arrDivs);
		
		
	}
	
	//look to see if there are any productBoxes divs on this page
	bodyRightDivs = document.getElementById('divBodyRight');
	
	arrDivs = bodyRightDivs.getElementsByTagName('div');
	if (arrDivs.length > 0) {
		//init any product boxes
		initSeriesFeatures(arrDivs);
		
		
	}

	
}