// <![CDATA[

var W3CDOM = (document.createElement && document.getElementsByTagName);

var mouseOvers = new Array();
var mouseOuts = new Array();

window.onload = init;

function init() {
	initMouse();
	fixInputs(); // elimate borders around radio buttons/checkboxes
	if (document.getElementById('faqs')) initFaqs(); // this only pertains faqs page
	if (document.getElementById('resultsSeparator')) initResults(); // this only pertains to product listings, see products.js
	if (document.getElementById('tooltips')) initTooltips(); // this only pertains to search by specifics final page, see products.js
}

function initMouse(){
	if (!W3CDOM) return;
	var imgs = document.getElementsByTagName('img');
	for (var i = 0; i < imgs.length; i++) {
		if (imgs[i].className.indexOf('mouseover') != -1){
			imgs[i].onmouseover = mouseGoesOver;
			imgs[i].onmouseout = mouseGoesOut;
			var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
			mouseOuts[i] = new Image();
			mouseOuts[i].src = imgs[i].src;
			mouseOvers[i] = new Image();
			mouseOvers[i].src = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_over" + suffix;
			imgs[i].number = i;
		}
		if (imgs[i].className.indexOf('bannermouseover') != -1){
			imgs[i].onmouseover = mouseGoesOver;
			imgs[i].onmouseout = mouseGoesOut;
			var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
			mouseOuts[i] = new Image();
			mouseOuts[i].src = imgs[i].src;
			mouseOvers[i] = new Image();
			var rollimg = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_over" + suffix;
			rollimg = rollimg.replace("banners/","banners/over/");
			mouseOvers[i].src = rollimg;
			imgs[i].number = i;
		}
	}
}

function mouseGoesOver() {
	this.src = mouseOvers[this.number].src;
}

function mouseGoesOut() {
	this.src = mouseOuts[this.number].src;
}

// Faqs Specific

var currentFaq = -1;

function initFaqs(){
	var faqs = document.getElementById('faqs');
	var j = 0;
	for (var i = 0; i < faqs.childNodes.length; i++){
		var d = faqs.childNodes[i];
		if (d.nodeName == 'DT'){			
			var t = d.firstChild;
			while(t.nodeType != 3) t = t.nextSibling;
			var a = document.createElement('A');
			a.id = 'dt_' + j;
			a.href = '#';
			a.onclick = function(){ viewFaqs(this.id); return false; };
			a.appendChild(t);
			d.appendChild(a);
			j++;
		} else if (d.nodeName == 'DD'){
			d.id = 'dd_' + (j - 1);
			d.style.display = 'none';
		}
	}
}

function viewFaqs(which){
	which = which.substring(3, which.length);
	if (currentFaq >= 0) document.getElementById('dd_' + currentFaq).style.display = 'none';
	if (currentFaq != which){
		document.getElementById('dd_' + which).style.display = 'block';
		currentFaq = which;
	} else {
		currentFaq = -1;
	}
}

function fixInputs(){
	var inputs = document.getElementsByTagName('INPUT');
	for (i = 0; i < inputs.length; i++){
		var inp = inputs[i];
		if (inp.type == 'radio' || inp.type == 'checkbox'){
			if(inp.className) inp.className += ' radio';
			else inp.className = 'radio';
		}
	}
}

// THUMBNAIL ROLLOVER
function borderit(which,color){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
which.style.borderColor=color
}
}


// ]]>
