//maked all added functions work onload. at the end of each function you want to work onload add addLoadEvent(function); to the end of the function.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// The following two functions make it possible to have web standard popups
window.onload = function() {
  if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) {
    if (lnks[i].className == "popup") {
      lnks[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
    else if (lnks[i].className == "popup2") {
      lnks[i].onclick = function() {
        popUp2(this.getAttribute("href"));
        return false;
      }
    }
    else if (lnks[i].className == "popupNews") {
      lnks[i].onclick = function() {
        popupNews(this.getAttribute("href"));
        return false;
      }
    }
    else if (lnks[i].className == "popupAppl") {
      lnks[i].onclick = function() {
        popupAppl(this.getAttribute("href"));
        return false;
      }
    }
  }
}

function popUp(winURL) {
  window.open(winURL,"popup");
}
function popUp2(winURL) {
  window.open(winURL,"popup2","width=520,height=460,scrollbars=yes");
}
function popupNews(winURL) {
  window.open(winURL,"popupNews","width=642,height=700,scrollbars=yes");
}
function popupAppl(winURL) {
  window.open(winURL,"popupNews","width=520,height=460,scrollbars=yes");
}

//-- Create a :Hover psuedo attribute for IE -- //
hdrHover = function() {
	if (document.getElementById('mnlnks') != null) {
		if((document.all)&&(document.getElementById)) {
			var hdrCat = document.getElementById("mnlnks").getElementsByTagName("li");
			for (var i=0; i<hdrCat.length; i++) {
				hdrCat[i].onmouseover=function() {
					this.className+=" hdrhover";
				}
				hdrCat[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hdrhover\\b"), "");
				}
			}
		}	
	}
}
addLoadEvent(hdrHover);

//-- Create a :Hover psuedo attribute for IE i am looking for... -- //
hdrUtHover = function() {
	if (document.getElementById('utlnks') != null) {
		if((document.all)&&(document.getElementById)) {
			var hdrUtCat = document.getElementById("utlnks").getElementsByTagName("li");
			for (var i=0; i<hdrUtCat.length; i++) {
				hdrUtCat[i].onmouseover=function() {
					this.className+=" hdruthover";
				}
				hdrUtCat[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hdruthover\\b"), "");
				}
			}
		}	
	}
}
addLoadEvent(hdrUtHover);

//make the title changes on rollover on the all gas home page
function prepareTitles() {
	//Make sure the browser understands the DOM methods
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	//Make sure the element exists
	if (!document.getElementById ("gshmtr")) return false;
	if (!document.getElementById("sctnttl")) return false;
	//Change the image
	var list = document.getElementById("gshmtr");
	var links = list.getElementsByTagName("a");
	links[0].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gaswaterheater.gif)';
	}
	links[1].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_patioheater.gif)';
	}
	links[2].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gasgrill.gif)';
	}
	links[3].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gaslogs.gif)';
	}
	links[4].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_codetector.gif)';
	}
	links[5].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gasrange.gif)';
	}
	links[6].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gasdryers.gif)';
	}
	links[7].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_heaters.gif)';
	}
	links[8].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gaslight.gif)';
	}
	links[9].onmouseover = function() {
		document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_gaswaterheater.gif)';
	}
	for (var i=0; i<links.length; i++) {
		links[i].onmouseout = function() {
			document.getElementById('sctnttl').style.backgroundImage = 'url(images/gh_head.gif)';
		}
	}
}
addLoadEvent(prepareTitles);

//css background replacement method
/*function rplcImg() {
	if (!document.getElementById) return false;
	if (!document.getElementById('hmlogo')) return false;
	var number = 3;
	var random_number="";
	var number = Math.random()*number;
	var random_number = Math.ceil(number);
	
	if (random_number==1) {
		document.getElementById('hmlogo').style.backgroundImage = 'url(images/bg-hm-hdr01.jpg)';
	}
	if (random_number==2) {
		document.getElementById('hmlogo').style.backgroundImage = 'url(images/bg-hm-hdr02.jpg)';
	}
	if (random_number==3) {
		document.getElementById('hmlogo').style.backgroundImage = 'url(images/bg-hm-hdr03.jpg)';
	}
}
addLoadEvent(rplcImg);*/

//*****Extend the footer to the bottom of the page**************************************************//
function cycle() {// redefine Cycle's updateActivePagerLink function 
  $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    newCurrSlideIndex = currSlideIndex+1;
    $(pager).find('a').removeClass('selected').filter('a:eq('+newCurrSlideIndex+')').addClass('selected'); 
  }; 
  $('#hdr #homeLogo ul#homeLogoImages').cycle({
    fx: 'fade',
    speed: 'slow',
    timeout: 5000,
    prev: '#prev',
    next: '#next',
    pager: '#homeLogoNavigation',
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) {
      newIdx = idx+1;
      return '#homeLogoNavigation li:eq(' + newIdx + ') a';
    }
  });
}
//*****Load all functions**************************************************//
$(document).ready(function(){
  cycle();
});