var selectedColor= null
bw = (document.all && document.getElementById)?'ie5':''; 
if(bw == '') bw = (!document.all && document.getElementById)?'ns6':''; 
agent = navigator.userAgent;

var g_colorcode=null;
var g_prod_code=null;
var g_pID=null;
var g_catTXT=null;
var g_colorID=null;
var g_fID=null;
var g_price=null;
var g_color=null;
var wasClicked = false;

function openWindow(openHref,width,height){
	var windowHandle = window.open(openHref, 'window', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height);
	windowHandle.focus();
}

function cPC(prod_image,price, color, colorID, pID, fID,colorcode,prod_code,catTXT){
	g_colorcode=colorcode;
	g_prod_code=prod_code;
	g_pID=pID;
	g_colorID=colorID;	
	g_fID=fID;
	g_price=price;
	g_color=color;
	g_catTXT=catTXT
	wasClicked = true;
	setCbarsToDef();
	document.getElementById('c_'+colorID).style.borderTop = '5px solid #888481';
	selectedColor = document.getElementById('c_'+colorID);
	document.getElementById('prel').style.display = 'inline';
	document.getElementById('ppimg').style.display = "block";
	document.getElementById('ppimg').src = document.getElementById('pimg').src
	document.getElementById('prel').innerHTML = 'loading image';
	document.getElementById('pimg').src = 'i/products/'+prod_image;
	loadingPoints();
}

function setCbarsToDef(){
	if(selectedColor != null){
		selectedColor.style.border = '0';
	}
}

//FADE and Preloader functions

function changeIt(){
	if(wasClicked){
		document.getElementById('prel').style.display = "";
		if((bw == 'ie5' && agent.indexOf('Mac')==-1) || (bw == 'ns6' && agent.indexOf('Safari')==-1)){
			if(bw == 'ie5'){
				fadeOutIE(60,-10,'ppimg');
				fadeInIE(30,110,'pimg');
			}
			else{
				fadeOutNS(60,-10,'ppimg');
				fadeInNS(30,110,'pimg');
			}
		}
		else{
			document.getElementById('ppimg').style.display = 'none';
		}
		document.getElementById('clrdesc').innerHTML = 'Color: '+g_color;
		document.getElementById('adif').innerHTML = '<a href="index.cfm?pid='+g_pID+g_catTXT+'&pcode='+g_prod_code+'&fid='+g_fID+'&colid='+g_colorID+'&colcode='+g_colorcode+'"><img src="i/addtocart.gif" border="0" id="addToCart" name="addToCart"></a>Price: '+g_price;
		wasCliked = false;
	}
}

function loadingPoints(){
	if(document.getElementById('prel').innerHTML != 'loading image_____________' && agent.indexOf('Safari') == -1){
		document.getElementById('prel').innerHTML = document.getElementById('prel').innerHTML + '_';
		setTimeout("loadingPoints()", 200);
	}
}

function fadeInIE(i,j,fadeObject,bw){
	document.getElementById(fadeObject).filters.alpha.opacity=i
	i+=2;
	if (i<j) setTimeout("fadeInIE("+i+","+j+",'"+fadeObject+"')",0);
}

function fadeOutIE(i,j,fadeObject,bw){
 	document.getElementById(fadeObject).filters.alpha.opacity=i;
	i-=2;
  if (i>j) setTimeout("fadeOutIE("+i+","+j+",'"+fadeObject+"')", 0);
}
		
function fadeInNS(i,j,fadeObject,bw){
	document.getElementById(fadeObject).style.MozOpacity = i/100
	i+=2;
	if (i<j) setTimeout("fadeInNS("+i+","+j+",'"+fadeObject+"')",0);
}

function fadeOutNS(i,j,fadeObject,bw){
	document.getElementById(fadeObject).style.MozOpacity = i/100;
	i-=2;
  if (i>j) setTimeout("fadeOutNS("+i+","+j+",'"+fadeObject+"')", 0);
}

function fadeInSF(i,j,fadeObject,bw){
	document.getElementById(fadeObject).style.KhtmlOpacity = i/100
	i+=2;
	if (i<j) setTimeout("fadeInSF("+i+","+j+",'"+fadeObject+"')",0);
}

function fadeOutSF(i,j,fadeObject,bw){
	document.getElementById(fadeObject).style.KhtmlOpacity = i/100;
	i-=2;
  if (i>j) setTimeout("fadeOutSF("+i+","+j+",'"+fadeObject+"')", 0);
}