/*-----------------------------------------------------------------------------
Primary Stellar computer Javascript

version:   1.0
author:    Weston Shaw
e-mail:    info@avallo.com
website:   http://www.avallo.com
-----------------------------------------------------------------------------*/

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

addLoadEvent(startList);
addLoadEvent(doNewWin);
addLoadEvent(hotNews);
addLoadEvent(homeImageChange);


/* =Open a new window
-----------------------------------------------------------------------------*/
function doNewWin() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].title.match("Opens in a New Window")) {
      links[i].onclick=function() {window.open(this.href);return false;
      }
    }
  }
}


/* =Home Image Changer
-----------------------------------------------------------------------------*/
function homeImageChange() {
  if (!document.getElementById) return false;
  if (!document.getElementById("navChanger")) return false;
  if (!document.getElementsByTagName) return false;
	// counter
	var x = 0;
	// create object
	imageObj = new Image();
	// set image list
	image = new Array();
	image[0]="App_Themes/HiHeatMasterCSS/heater1.jpg"
	image[1]="App_Themes/HiHeatMasterCSS/heater2.jpg"
	image[2]="App_Themes/HiHeatMasterCSS/heater3.jpg"
	image[3]="App_Themes/HiHeatMasterCSS/heater4.jpg"
	image[4]="App_Themes/HiHeatMasterCSS/heater5.jpg"
	image[5]="App_Themes/HiHeatMasterCSS/heater6.jpg"
	image[6]="App_Themes/HiHeatMasterCSS/heater7.jpg"
	// start preloading
	for(x=0; x<image.length; x++){
		imageObj.src=image[x];
	}
	var side = document.getElementById("side");
	var homeImage = document.getElementById("navChanger");
	// Get List
	for (j=0; j<side.childNodes.length; j++) {
		if(side.childNodes[j].nodeName=="UL"){
			var list = side.childNodes[j];
		}
	}
	// Get Links / Replace Image, Title, and Alt on mouseover
	for(k=0; k<list.childNodes.length; k++) {
		if(list.childNodes[k].nodeName=="LI"){
			var linkNode = list.childNodes[k].firstChild;
			linkNode.onmouseover=function(){
				var title = this.title;
				var imageNum = this.rel;
				homeImage.src="App_Themes/HiHeatMasterCSS/heater"+imageNum+".jpg";
				homeImage.alt=title;
				homeImage.title=title;
			}
		}
	}
}

/* =IE Menu dropdown support
-----------------------------------------------------------------------------*/
function startList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menuElem");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
/* =hotNews support mouse over
-----------------------------------------------------------------------------*/
function hotNews() {
	if (document.getElementById("news")&&document.getElementsByTagName) {
		var news = document.getElementById("news");
		var divs = news.getElementsByTagName("DIV");
		for (i=0; i<divs.length; i++) {
			div = divs[i];
			if(div.className!="newsBox"){
				div.onmouseover=function() {
					this.className=this.className="over";
				}
				div.onmouseout=function() {
					this.className=this.className="";
				}
				div.onclick=function(){
					var a = div.getElementsByTagName("A");
					for (n=0; n<a.length; n++) {
						var loc = a[n].href;
					}
					window.location = loc;
				}
			}
		}
	}
}
