// JavaScript Document

function goNextSlideNew () {
	nextSlide = currentSlide + 1;
	if (nextSlide > maxSlides) {
		nextSlide = 1;
	}
	goSlideNew (nextSlide);
}
function goSlideNew (which){
	if (counter == 0) {
		window.clearTimeout (slideShow);
		currentSlide = which;
		endPos = (which - 1) * -635;
		var slideObj = window.setTimeout("slide()", ticks);
	}
	for (f=1;f<=maxSlides;f++) {
		if (f==currentSlide) {
			document.getElementById("slide_"+f+"_button").className="over";	
		} else { 
			document.getElementById("slide_"+f+"_button").className="";
		}
		document.getElementById("slideButtons").style.display="block";						
	}
	return false;
}
function slide() {
	counter++;	
	propor = ((Math.sin((((counter / steps) * 2) - 1) * (Math.PI/2))) + 1) / 2;
	currentPos = parseInt (((endPos - startPos) * propor) + startPos);
	document.getElementById("slider").style.left = currentPos+"px";
	if (counter < steps) {
		var slideObj = window.setTimeout("slide()", ticks);
	} else {
		startPos = endPos;
		counter = 0;
		slideShow = window.setTimeout("goNextSlideNew()", 15000)
	}		
}


function initLP (productCountArray){
	thisArray = new Array();
	for (f=0;f<productCountArray.length;f++){
		thisObj=new Object();
		thisObj.startPosition = 0;
		thisObj.endPosition = 0;
		thisObj.moveCount = 0;
		thisObj.productCount = productCountArray[f];
		thisObj.timeObj = false;
		thisArray.push (thisObj);
	}
	return thisArray;
}
function moveLandingSection (pos, move){
	if (landingPageArray[pos - 1].moveCount==0) {
		if (landingPageArray[pos - 1].startPosition + move > -1 && landingPageArray[pos - 1].startPosition + move < landingPageArray[pos - 1].productCount -3) {
			landingPageArray[pos - 1].endPosition = landingPageArray[pos - 1].startPosition + move;
			landingPageArray[pos - 1].timeObj = window.setTimeout("updateLandingSection("+pos+")", 40);
		}
	}
	return false;
}
function updateLandingSection(pos) {
	productGroupWidth = 137;
	landingPageArray[pos - 1].moveCount++;
	start = landingPageArray[pos - 1].startPosition * productGroupWidth;
	end = landingPageArray[pos - 1].endPosition * productGroupWidth;
	propor = ((Math.sin((((landingPageArray[pos - 1].moveCount / 10) * 2) - 1) * (Math.PI/2))) + 1) / 2;
	document.getElementById("lc_"+pos).style.left = (-1 * (((end - start) * propor) + start - 25))+"px";
	if (landingPageArray[pos - 1].moveCount < 10) {
		landingPageArray[pos - 1].timeObj = window.setTimeout("updateLandingSection("+pos+")", 40);
	} else {
		landingPageArray[pos - 1].moveCount = 0;
		landingPageArray[pos - 1].startPosition = landingPageArray[pos - 1].endPosition;
		if (landingPageArray[pos - 1].startPosition > 0) {
			document.getElementById("landingLeftArrowLeft_"+pos).className="landingLeftArrow";
		} else {
			document.getElementById("landingLeftArrowLeft_"+pos).className="landingLeftArrowDead";
		}
		if (landingPageArray[pos - 1].startPosition < landingPageArray[pos - 1].productCount -4) {
			document.getElementById("landingLeftArrowRight_"+pos).className="landingRightArrow";
		} else {
			document.getElementById("landingLeftArrowRight_"+pos).className="landingRightArrowDead";
		}	
	}
}
function initBrands (brandCount){
	var thisObj=new Object();
	thisObj.startPosition = 0;
	thisObj.endPosition = 0;
	thisObj.moveCount = 0;
	thisObj.brandCount = brandCount;
	thisObj.timeObj = false;
	return thisObj;
}
function moveBrands (move){
	if (brandObject.moveCount==0) {
		if (brandObject.startPosition + move > -1 && brandObject.startPosition + move < brandObject.brandCount - 3) {
			brandObject.endPosition = brandObject.startPosition + move;
			brandObject.timeObj = window.setTimeout("updateBrandPositions()", 40);
		}
	}
	return false;
}
function updateBrandPositions() {
	brandGroupWidth = 108;
	brandObject.moveCount++;
	start = brandObject.startPosition * brandGroupWidth;
	end = brandObject.endPosition * brandGroupWidth;
	propor = ((Math.sin((((brandObject.moveCount / 10) * 2) - 1) * (Math.PI/2))) + 1) / 2;
	document.getElementById("brandsInner").style.left = (-1 * (((end - start) * propor) + start - 25))+"px";
	if (brandObject.moveCount < 10) {
		brandObject.timeObj = window.setTimeout("updateBrandPositions()", 40);
	} else {
		brandObject.moveCount = 0;
		brandObject.startPosition = brandObject.endPosition;
		if (brandObject.startPosition > 0) {
			document.getElementById("brandArrowLeft").className="brandArrowLeft";
		} else {
			document.getElementById("brandArrowLeft").className="brandArrowLeftDead";
		}
		if (landingPageArray.startPosition < brandObject.brandCount -4) {
			document.getElementById("brandArrowRight").className="brandArrowRight";
		} else {
			document.getElementById("brandArrowRight").className="brandArrowRightDead";
		}	
	}
}



function mailpage(){
	mail_str = "mailto:?subject=Check out the " + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at, " + location.href; 
	location.href = mail_str;
}
var clearedFields = new Array();
function clearDefault(ID){
	var found = false;
	for (f=0;f<clearedFields.length;f++) {
		if (clearedFields[f]==ID){
			found = true;
		}
	}
	if (found==false) {
		document.getElementById(ID).value="";
		clearedFields.push (ID);
	}
}
var newsletterFieldCleared = false;
function clearNewsFooterDefault(){
	if (newsletterFieldCleared==false) {
		document.getElementById("newsletterInput").value="";
		document.getElementById("newsletterInput").className="newsletterInputFocused";
		newsletterFieldCleared = true;
	}
}
	
function showQtySelect(ID, qty){
	selectField = document.getElementById("qtySelect_"+ID);
	maxVal = (Math.ceil(qty / 10)) * 10;
	for (f=1;f<=maxVal;f++) {
		if (f==qty) {
			selectField.options[f - 1] = new Option(f, f, true, true);
		} else {
			selectField.options[f - 1] = new Option(f, f, false, false);
		}
	}
	selectField.options[maxVal] = new Option(maxVal+"+", "+", false, false);
	document.getElementById("qtyStatic_"+ID).style.display = "none";
	selectField.style.display = "inline";	
	return false;
}
function updateQtySelect(ID){
	selectField = document.getElementById("qtySelect_"+ID);
	if (selectField.value=="+") {
		currentLength = selectField.options.length - 1;
		selectField.options[currentLength] = new Option(1 + currentLength, 1 + currentLength, true, true);
		for (f=1;f<10;f++) {
			selectField.options[currentLength + f] = new Option(f + 1 + currentLength, f + 1 + currentLength, false, false);
		}
		selectField.options[currentLength + 10] = new Option((currentLength+10)+"+", "+", false, false);
	} else {
		document.getElementById("qtyForm_"+ID).submit();
	}
}
function updateRating(which){
	document.getElementById("rating").value=which;
	document.getElementById("ratingDisplay").innerText = which+ " / 10";
	for (f=1;f<=10;f++) {
		if (which >= f){
			document.getElementById("rating"+f).className="starOver";
		} else {
			document.getElementById("rating"+f).className="star";
		}
	}
	return false;
}
////////////////////////////////////
	var XMLHttpArray = [
		function() {return new XMLHttpRequest()},
		function() {return new ActiveXObject("Msxml2.XMLHTTP")},
		function() {return new ActiveXObject("Msxml2.XMLHTTP")},
		function() {return new ActiveXObject("Microsoft.XMLHTTP")}
	];
	var theUploadKey = "";
	function createXMLHTTPObject(){
		var xmlhttp = false;
		for(var i=0; i<XMLHttpArray.length; i++){
			try{xmlhttp = XMLHttpArray[i]();}
			catch(e){continue;						}
			break;
		}
		return xmlhttp;
	}
	function AjaxRequest(url,callback,method){
		var req = createXMLHTTPObject();
		req.onreadystatechange= function(){
			if(req.readyState != 4) {return;}
			if(req.status != 200) {return;}
			callback(req);
		}
		req.open(method,url,true);
		req.setRequestHeader('User-Agent', 'My XMLHTTP Agent');
		req.send(null);
	}
	var autoSearchListCount = 0;
	var autoSearchListActive = -1;	
	var autoSearchDelay = false;
	function autoSearch(evt) {
		var charCode = (evt.which) ? evt.which : event.keyCode
		switch (charCode) {			
			case 38:
				if (autoSearchListCount>0) {
					if (autoSearchListActive<=0) {
						autoSearchListActive = autoSearchListCount;
					} else {
						autoSearchListActive--;
					}
					renderArrows();
				}
				break;				
			case 40:
				if (autoSearchListCount>0) {
					if (autoSearchListActive>autoSearchListCount || autoSearchListActive==-1) {
						autoSearchListActive = 1;
					} else {
						autoSearchListActive++;
					}
					renderArrows();
				}
				break;
			default:
				url = "/autoSearch.html?xSearch="+encodeURIComponent(document.getElementById("topSearchField").value)+"&topSearchField=";
				AjaxRequest(url,renderSearchList,"get");
				break;
		}
	}
	function goAutoSearchArrow(){
		if (autoSearchListActive>-1) {
			self.location.href=document.getElementById("autoSearch_"+autoSearchListActive).href;
			return false;
		} else {
			return true;
		}
	}
	function renderSearchList(req) {
		if (req.responseText!="") {
			document.getElementById("autoSearchContent").style.display = "block"
			document.getElementById("autoSearchContent").innerHTML = req.responseText;
			autoSearchListCount = parseInt (document.getElementById("autoSearchProductCount").value);
			autoSearchListActive = -1;		
		} else { 
			document.getElementById("autoSearchContent").style.display = "none";
			autoSearchListCount = 0;
			autoSearchListActive = -1;
		}
	}
	function renderArrows(){
		for (f=1;f<=autoSearchListCount;f++) {
			if (autoSearchListActive==f) {
				document.getElementById("autoSearch_"+f).className="productGroupSearchActive";
			} else { 
				document.getElementById("autoSearch_"+f).className="productGroupSearch";
			}
		}
		if (autoSearchListActive == parseInt (autoSearchListCount) + 1) {
			document.getElementById("autoSearch_All").className="productGroupSearchAllActive";				
		} else {
			document.getElementById("autoSearch_All").className="productGroupSearchAll";
		}
	}
	function hideAutoSearch(){
		autoSearchDelay = window.setTimeout("hideAutoSearchDelayed()", 250)
	}
	function hideAutoSearchDelayed(){
		document.getElementById("autoSearchContent").style.display = "none";
		autoSearchListCount = 0;
		autoSearchListActive = -1;		
	}
	function clearAutoSearchDelay(){
		clearTimeout(autoSearchDelay);
		return true;
	}
	function submitAutoSearch() {
		document.getElementById("autoSearchForm").submit();
		return false;
	}
