SC = {};//Sidecar namespace

SC.util = {
	pageLoad: function(){		
		SC.util.clickListener();
		SC.util.rollOver();
		SC.util.specsHide();
		SC.util.paintChipUno();
	},
	specsHide: function() {
		
		if(locale == "en_ca" || locale == "fr_ca" || locale == "es_mx"){
			
			document.getElementById("specTableMetric").style.display = "block";
			document.getElementById("specTableUS").style.display = "none";
			document.getElementById("usUnits").style.display = "none";
			
			if(locale == "en_ca"){
				var tab = YAHOO.util.Dom.getElementsByClassName('tabs','div','specColumn')[0];
				if(tab){
					tab.className = 'tabs tabs_en_ca';
				}
			}
			
		}else{
			document.getElementById("specTableMetric").style.display = "none";
		}
		
	},
	paintChipUno: function() {
		YAHOO.util.Event.purgeElement("color1",false,"mouseout");
		
	},
	clickListener: function(){		
		YAHOO.util.Event.on("usUnits","click",SC.util.unitUS);
		YAHOO.util.Event.on("metricUnits","click",SC.util.unitMetric);
		//YAHOO.util.Event.on("printer","click",SC.util.printMe);
		
	},
	
	/*
printMe: function() {
		//window.print();
		alert("Printing");
	},
*/
	unitUS: function() {
		//alert("US spec table switch");
		document.getElementById('specTableUS').style.display = "";
		document.getElementById('specTableMetric').style.display = "none";
		document.getElementById('usUnits').style.backgroundPosition = "0 0 ";
		document.getElementById('metricUnits').style.backgroundPosition = "0 -24px ";
	},
	unitMetric: function() {
		//alert("Metric spec table switch");
		document.getElementById('specTableMetric').style.display = "";
		document.getElementById('specTableUS').style.display = "none";
		document.getElementById('metricUnits').style.backgroundPosition = "0 0 ";
		document.getElementById('usUnits').style.backgroundPosition = "0 -24px ";
	},
	rowRollOff: function(e,f){
		document.getElementById(f.id).style.backgroundPosition = "0 1px";		
		/**var colorNames = YAHOO.util.Dom.getElementsByClassName('colorNames','p',f.id)[0];
		colorNames.style.display = "none";*/
	},
	//Roll on state for paintchips
	rowRollOn: function(e,f){
		document.getElementById(f.id).style.backgroundPosition = "0 -30px";
		/**var colorNames = YAHOO.util.Dom.getElementsByClassName('colorNames','p',f.id)[0];
		colorNames.style.display = "block";*/
	},
	//Listen for the hover over paintchips
	rollOver: function(){
		//Hunt down paintChips
		var paintChip = YAHOO.util.Dom.getElementsByClassName('paintchip','div','paintchips');
		for (i = 0; i < paintChip.length; i++) {
			//Handle mouseover on a results row
			YAHOO.util.Event.addListener(paintChip[i], "mouseover", SC.util.rowRollOn, paintChip[i]);			
			YAHOO.util.Event.addListener(paintChip[i], "mouseout", SC.util.rowRollOff, paintChip[i]);
			//Handle clicking on a results row
			
			YAHOO.util.Event.addListener(paintChip[i], "click", SC.util.changeColor, paintChip[i]);
			
		};
		
	},
	changeColor: function(e,f){
		var paintChip = YAHOO.util.Dom.getElementsByClassName('paintchip','div','paintchips');
		for (i=0; i<paintChip.length; i++) {
			if (f.id != paintChip[i].id) {
				document.getElementById(paintChip[i].id).style.backgroundPosition = "0 1px";
				YAHOO.util.Event.addListener(paintChip[i], "mouseover", SC.util.rowRollOn, paintChip[i]);			
				YAHOO.util.Event.addListener(paintChip[i], "mouseout", SC.util.rowRollOff, paintChip[i]);
			} else {
				
				var left = i * 360;
				if (left > 0) {
					left = "-" + left + "px";
				} else {
					left = left + "px";
				};
				document.getElementById("modelImage").style.left = left;
				document.getElementById(paintChip[i].id).style.backgroundPosition = "0 -30px";
				YAHOO.util.Event.purgeElement(paintChip[i].id,false,"mouseout");
			};
		};
	}

}; // end RE.search_util namespace
