/*

Custom functions
	
	Created:	2008-05-22
	Modified:	2008-05-28
	Version:	1.2
	Auth:		Andrew Hamel - TorqueFKM

*/

var selind = 1;
var paused = false;
var seltarget = new Array('null','http://www.google.com','http://www.wm.com','http://www.thinkgreen.com','http://www.wm.com/wm/services/recycling.asp');
var bid = 1;
var btarget = new Array('','product_lamp.cfm', 'state_regulations.cfm', 'recycling_mercury.cfm', 'benefits.cfm', 'product_bulktracker.cfm');

/*function swap_img(id,img){
	document.getElementById(id).src = "images/"+img;
	return false;
}

function pic_switcher(ind){
	// image
	document.getElementById("pic_switch").src = "images/rotator/img"+ ind +".jpg";
	// buttons
	for(i=1;i<5; i++){
		if(ind == i){
			selind = i;
			document.getElementById("ctrl"+i).src = "images/ctrl"+ i +"_on.gif";
		}else{
			document.getElementById("ctrl"+i).src = "images/ctrl"+ i +"_off.gif";
		}
	}
	init_btns(ind);
	return false;
}

function pic_rotate(){
	if(!paused){
		var indn = parseInt(selind + 1) > 4 ? 1 : parseInt(selind + 1);
		
		// image
		document.getElementById("pic_switch").src = "images/rotator/img"+ indn +".jpg";
		// buttons
		for(i=1;i<5; i++){
			if(indn == i){
				selind = i;
				document.getElementById("ctrl"+i).src = "images/ctrl"+ i +"_on.gif";
			}else{
				document.getElementById("ctrl"+i).src = "images/ctrl"+ i +"_off.gif";
			}
		}
		init_btns(indn);
		}
	return false;
}

function init_btns(ind){
	for(j=1;j<5; j++){
		if(ind==j){
			document.getElementById("ctrl"+j).src = "images/ctrl"+ j +"_on.gif";
			document.getElementById("ctrl"+j).onmouseover = function(){ }
			document.getElementById("ctrl"+j).onmouseout = function(){ }
		}else{
			document.getElementById("ctrl"+j).ind = j;
			document.getElementById("ctrl"+j).onmouseover = function(){
				this.src = "images/ctrl"+this.ind+"_on.gif";
			}
			document.getElementById("ctrl"+j).onmouseout = function(){
				this.src = "images/ctrl"+this.ind+"_off.gif";
			}
		}
	}
	
	document.getElementById("pic_switch").onmouseover = function(){
		document.getElementById("pic_note").style.visibility = "visible";
	}
	document.getElementById("pic_switch").onmouseout = function(){
		document.getElementById("pic_note").style.visibility = "hidden";
	}
	document.getElementById("pic_switch").onclick = function(){
		//window.location = seltarget[ind];
		window.open(seltarget[ind],'','');
		//alert("window.location = seltarget("+ seltarget[ind] +")");
	}
}*/

function banner_rotate(){
	var arr = new Array('ban_welcome.jpg','ban_gov.jpg','ban_rec.jpg','ban_all.jpg','ban_bulktracker.jpg');
	document.getElementById("banner_tile").src = "images/" + arr[bid];
	document.getElementById("banner_tile").onclick = function(){
		document.location = btarget[bid];
	}
	bid = (bid+1) == 5 ? 0 : (bid+1);
	
}

function init_banner(){
	document.getElementById("banner_tile").onclick = function(){
		document.location = btarget[0];
	}
}

window.onload = function(){ 
	//init_btns('1'); 
	//init_banner('1');
	//setInterval(pic_rotate, 6000);
	setInterval(banner_rotate, 12000);
}

function show_tab(id){
	var tabs = new Array('4ft','6ft','8ft','ubent','hid','compact','uv');
	for(k=0; k< tabs.length; k++){
		if(tabs[k]==id){
			document.getElementById("tab_" + tabs[k]).style.display="block";
		}else{
			document.getElementById("tab_" + tabs[k]).style.display="none";
		}
	}
	return false;
}

function switch_panel(prod){
	// for now, just bring in another HTML file
	var url = "product_subpages/lamptracker_" + prod + ".html";
	process(url,'form_container');
}

/*
	
	Andrew's Own AJAX processor!
	
*/

function AJAX_CONN(){
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}else{
		return http_request;
	}
}

function process(url,div) {
	var conn = AJAX_CONN();
	conn.onreadystatechange = function() {
		if (conn.readyState == 4) {
			if (conn.status == 200) {
				document.getElementById(div).innerHTML = conn.responseText;
			} else {
				alert('GET failed?');
			}
		}
	}
	conn.open('GET', url, true);
	conn.send(null);
}

function activate(obj){
links = document.getElementById('product_list').getElementsByTagName('a');
 for(i=0;i<links.length;i++){
  //links[i].className = 'nav';
  if(links[i].id==obj){
   links[i].className='active';
  }
  if(links[i].id!=obj){
   links[i].className='';
  }
 }
}

