// JavaScript Document
cartAddPop = function(groupID)
	{	
		/*ColdFusion.Window.create("cartPopUp", "Window Header", "includes/addToCartPop.cfm?groupID={gridProducts:groupIDInput}",
			{ height:500,width:580,modal:true,closable:true, draggable:true,resizable:false,center:true,initshow:true});
		//ColdFusion.Window.onHide("myWindow", doThis);
		document.getElementById(ColdFusion.Window.getWindowObject("cartPopUp").header.id).className = "windowHdr";*/

		var hf_gID = document.getElementById('groupIDInput')
		hf_gID.value=groupID;
		
		//on IE
		if(hf_gID.fireEvent)
		{
			hf_gID.fireEvent('onchange');
		}
		
		//on Gecko based browsers
		if(document.createEvent){
			var evt = document.createEvent('HTMLEvents');
			
			if(evt.initEvent){
			evt.initEvent('change', true, true);
			}
		
			if(hf_gID.dispatchEvent){
				hf_gID.dispatchEvent(evt);
			}
		
		}
		
		myWindow = ColdFusion.Window.getWindowObject('cartPopUp');
		myWindow.on('beforeshow', centerWindow);
		ColdFusion.Window.show('cartPopUp');
		
	}
	
	centerWindow = function(myWindow){
		myWindow.center();
	}
	
	function submitSelection() {
		ColdFusion.navigate("cfcs/addToCartPop.cfm","cartPopUp","","","POST","prodForm"); 
		ColdFusion.Window.show("cartPopUp"); 
	}



/* DETAILS PAGE FUNCTIONS */
function loadProduct(arrID, totalID){
	thisProd = eval("productObj"+arrID);
	
	curSel = arrID;
	curID = thisProd[0];
	
	var imgDiv = document.getElementById("imageHolder");
	var retailDiv = document.getElementById("JPrice");
	var msrpDiv = document.getElementById("JMsrp");
	var saveDiv = document.getElementById("JSave");
	var saleDiv = document.getElementById("JSale");
	LgImgPath = baseDir + thisProd[6];
	var retail = thisProd[2];
	var msrp = thisProd[3];
	var save = thisProd[4];
	var salePrice = thisProd[8];
	var salePerc = thisProd[9];
	var onSale = false;
	
	if(salePrice > 0){
		onSale = true;
		saleDiv.innerHTML = '<h1>Sale Price</h1> ' + '$' + salePrice.toFixed(2) + '<br/>';
		retailDiv.className = 'dPrice hasSale';
	}
	
	if(onSale){
		retailDiv.innerHTML = '<h1>Regularly</h1> ';
	} else {
		retailDiv.innerHTML = '';
	}
	retailDiv.innerHTML += '$' + retail.toFixed(2);
	
	
	if(retail < msrp){
		msrpDiv.innerHTML = 'MSRP <s>$' + msrp.toFixed(2) + '</s>';
		saveDiv.innerHTML = 'You Save ' + save + '%';
	} else {
		saveDiv.innerHTML = '';
	}
	
	
	
	
	document.images.productImage.src = LgImgPath;
	var prodImg = document.images.productImage;
	
	if(prodImg.width > prodImg.offsetParent.offsetWidth){
		var dx = Math.round( (prodImg.width - prodImg.offsetParent.offsetWidth) / 2 );
		prodImg.style.marginLeft = -dx + 'px';
	}	
		

	//Clear Swatch borders
	for(var i = 1; i <= totalID; i++){
		tempSwatch = document.getElementById("swatch"+i);
		tempSwatch.className = "colorSwatchImg";
		}
	tempSwatch = document.getElementById("swatch"+arrID);
	tempSwatch.className = "isOn";
	
	var sel = document.getElementById("colorSelID");
	sel.selectedIndex = arrID - 1;
	document.prodForm.currentProdID.value = thisProd[0];
	document.shipForm.shipProdID.value = thisProd[0];
	//imgDiv.innerHTML = '<img src="' + LgImg + '">';
}

function hoverSwatch(who){
	sw = document.getElementById(who);
	if(who != 'swatch'+curSel){
		sw.className = 'colorSwatchImgHover';
	}
}
function hoverOutSwatch(who){
	sw = document.getElementById(who);
	if(who != 'swatch'+curSel){
		sw.className = 'colorSwatchImg';
	}
}

function hoverOptSwatch(who){
	sw = document.getElementById(who);
	if(who != 'optswatch'+curOptSel){
		sw.className = 'colorSwatchImgHover';
	}
}
function hoverOptOutSwatch(who){
	sw = document.getElementById(who);
	if(who != 'optswatch'+curOptSel){
		sw.className = 'colorSwatchImg';
	}
}

function loadOption(arrID,totalID){
	thisOpt = eval("optObj"+arrID);
	curOptSel = arrID;
	
	for(var i = 1; i <= totalID; i++){
		var tempSwatch = document.getElementById("optswatch"+i);
		tempSwatch.className = "colorSwatchImg";
		}
	var tempSwatch = document.getElementById("optswatch"+arrID);
	tempSwatch.className = "isOn";
	
	var sel = document.getElementById("optSelID");
	sel.selectedIndex = arrID - 1;
	
	document.shipForm.prodOpt.value = thisOpt[0];

}


function addToFavorites() { 
	if (window.external) { 
		window.external.AddFavorite(location.href, document.title); 
	} else { 
		alert("Sorry! Your browser doesn't support this function."); 
	} 
}

function printPage(URL) {
	day = new Date();
	id = day.getTime();
	URL += '?groupID=' + groupID + '&curSel=' + curSel;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=1024,left = 240,top = 0');");
}


/* MAIN PAGE / SHARED FUNCTIONS */
function showPopProds(parent){
	var cont = document.getElementById("popularContent");
	var posX = findPosX(parent);
	var posY = findPosY(parent);

	cont.style.left = posX + 'px';
	cont.style.top = posY + 18 + 'px';
	
	cont.style.display = 'block';
}

function hidePopProds(parent){
	var cont = document.getElementById("popularContent");
	cont.style.display = 'none';
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
  }
  

/* NAVIGATION FUNCTIONS */
function toggleAtt(n){
	var attHead = document.getElementById('attHead_' + n);
	var listContain = document.getElementById('listContain_' + n);
	if(attHead.className == 'navHeadline close'){
		attHead.className = 'navHeadline open';
		listContain.style.display = 'block';
	} else {
		attHead.className = 'navHeadline close';
		listContain.style.display = 'none';
	}
}

function openMore(n){
	tDiv = document.getElementById('HL'+n);
	hList = document.getElementById('IL'+n).offsetHeight;
	mbtn = document.getElementById('ML_'+n);
	if(tDiv.isOn == true){
		tDiv.isOn = false;
		mbtn.innerHTML = 'more...';
		omi = setInterval("doCollapse(tDiv)", 25);
	} else {
		tDiv.isOn = true;
		tDiv.myHeight = 0;
		mbtn.innerHTML = 'less...';
		omi = setInterval("doExpand(tDiv, hList)", 25);
	}
}

var doExpand = function(who, listHeight){
	if(who.myHeight <= listHeight+5){
		who.myHeight += 20;
		who.style.height = who.myHeight + 'px';
	} else {
		who.style.height = '100%';
		clearInterval(omi);
	}
}

var doCollapse = function(who){
	if(who.myHeight >= 1){
		who.myHeight -= 20;
		who.style.height = who.myHeight + 'px';
	} else {
		who.style.height = '1px';
		clearInterval(omi);
	}
}

/* POPUP HANDLER / EVENT FIRE */
var divName = 'trailimageid'; // div that is to follow the mouse
                       // (must be position:absolute)
var offX = 15;          // X offset from mouse position
var offY = 15;          // Y offset from mouse position

function mouseX(evt) {
	if (!evt) evt = window.event; 
	if (evt.pageX) return evt.pageX; 
	else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); 
	else return 0;
	}
	
function mouseY(evt) {
	if (!evt) evt = window.event;
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); 
	else return 0;
	}

function follow(evt) {
	if (!evt) evt = window.event;
	
	if (document.getElementById) {
		var obj = document.getElementById(divName).style;

		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		
		var scObj = document.getElementById(divName);
		//off screen check ff
		if(evt.pageY){
			if( evt.pageY + scObj.offsetHeight > myHeight ){
				offScreen = scObj.offsetHeight;
				offsetMult = -1;
			} else {
				offScreen = 0;
				offsetMult = 1;
			}
		}	
		//off screen check ie
		if(evt.clientY){
			if( evt.clientY + scObj.offsetHeight > myHeight ){
				offScreen = scObj.offsetHeight;
				offsetMult = -1;
			} else {
				offScreen = 0;
				offsetMult = 1;
			}
		}

		obj.left = (parseInt(mouseX(evt))+offX) + 'px';
		obj.top = (parseInt(mouseY(evt))-offScreen+(offY*offsetMult)) + 'px';
		
	}
	
}


var overID = 0;
var thisOver = 0;

function showDetailPop(){
	var obj = document.getElementById(divName).style;
	obj.visibility = 'visible'
	//document.onmousemove = follow;
	}
function hideDetailPop(){
	var obj = document.getElementById(divName).style;
	obj.visibility = 'hidden'
	document.onmousemove = '';
	clearTimeout(thisOver);
	}


detailPop = function(){
	var hf_dgID = document.gridProducts.groupIDInput;
	if(hf_dgID.value == overID){ doRefresh = false } else { doRefresh = true }
	
	hf_dgID.value=overID;
	
	//on IE
	if(hf_dgID.fireEvent && doRefresh)
	{
		hf_dgID.fireEvent('onchange');
	}
	
	//on Gecko based browsers
	if(document.createEvent && doRefresh){
		var evt = document.createEvent('HTMLEvents');
		
		if(evt.initEvent){
		evt.initEvent('change', true, true);
		}
	
		if(hf_dgID.dispatchEvent){
			hf_dgID.dispatchEvent(evt);
		}
	
	}
		
}
	
function startPopTime(groupID){
	overID = groupID;
	document.onmousemove = follow;
	thisOver = setTimeout("openDPop();", 700);
}

function openDPop(){
	detailPop();
	showDetailPop();
}
       