//-- Preload images to cure the browser flickering issue
if (document.images) {
	var aryImages = new Array(
		"images/spacer.gif",
		"images/btn_aqua.png",
		"images/btn_blue.png",
		"images/btn_disabled.png",
		"images/btn_gray.png",
		"images/btn_green.png",
		"images/btn_orange.png",
		"images/btn_red.png",
		"images/btn_yellow.png",
		"images/item_glow2.png",
		"images/item_glow2_top.png",
		"images/item_glow2_bot.png"
	);
	var aryPreload = new Array();
	for (var img=0; img<aryImages.length; img++) {
		aryPreload[img] = new Image();
		aryPreload[img].src = aryImages[img];
	}
}

Array.prototype.contains = function(obj) {
	var i = this.length;
	while (i--) {
		if (this[i] === obj) {
			return true;
		}
	}
	return false;
}

function formatPhone(field, event) {
	//------ KOA DOESN'T NEED FORMATTING ------//
	return true;
	//-----------------------------------------//
	if (field.value.replace(/^\s+|\s+$/g, "") == "") {
		return true;
	}
	try {
		if (field.value.substr(0,1) == "+") {
			return true;
		}
	} catch (er) { }
	var code = 0;
	if (event) {
		event = event || window.event;
		code = event.which || event.keyCode;
	}
	//-- ignore backspace, tab, shift, ctrl, home, end, arrows, del
	var aryCodes = [ 8, 9, 16, 17, 35, 36, 37, 38, 39, 46 ];
	if (!aryCodes.contains(code)) {
		if (field.value.match(/^[01]?\s?\(\d{1,2}$/) ||
			field.value.match(/^[01]?\s?\(\d{3}\)\s\d{1,2}$/) ||
			field.value.match(/^[01]?\s?\(\d{3}\)\s\d{3}-\d{1,4}$/) || 
			field.value.match(/^[01]?\s?\(\d{3}\)\s\d{3}-\d{4}\s[x]{1}\s[\d]{1,5}$/)
		) {
			return true;
		}
		var proceed = true;
		if (proceed) proceed = !field.value.match(/^([01])\s$/);
		if (proceed) proceed = !field.value.match(/^([01]?\s?)(\()$/);
		if (proceed) proceed = !field.value.match(/^([01]?\s?)(\([0-9]{3}\))\s$/);
		if (proceed) proceed = !field.value.match(/^([01]?\s?)(\([0-9]{3}\))\s([0-9]{3})\-$/);
		if (proceed) proceed = !field.value.match(/^([01]?\s?)(\([0-9]{3}\))\s([0-9]{3})\-([0-9]{4})([ex\s])$/);
		if (proceed) {
			var temp = field.value.replace(/[^0-9]/g, "");
			var cursor = temp.length;
			var prefix = temp.replace(/^([01]?)([0-9]*)$/, "$1").length;
			temp = temp.replace(/^([01]?)([0-9]{0,3})([0-9]{0,3})([0-9]{0,4})([0-9]*)$/, "$1 ($2) $3-$4 x $5");
			if (cursor < (11+prefix)) temp = temp.replace(/\s*x\s*$/, "");
			if (cursor < (6+prefix)) temp = temp.replace(/\-\s*$/, "");
			if (cursor < (3+prefix)) temp = temp.replace(/\)\s*$/, "");
			if (cursor < (1+prefix)) temp = temp.replace(/\s\(*$/, "");
			if (!cursor) temp = "";
			if (cursor > (15+prefix)) temp = temp.substring(0,temp.length-(cursor-(15+prefix)));
			temp = temp.replace(/^\s+|\s+$/g, "");
			field.value = temp;
		} else {
			if (field.value.match(/^([01]?\s?)(\([0-9]{3}\))\s([0-9]{3})\-([0-9]{4})([ex\s])$/)) {
				field.value = field.value.replace(/([ex\s])$/, " x ");
			} else {
				field.value = field.value;
			}
		}
		//field.focus();
	}
	return true;
}

function formatNumeric(field, event) {
	// Usage: onkeyup="formatNumeric(this,event)"
	event = event || window.event;
	code = event.which || event.keyCode;
	//-- ignore backspace, tab, shift, ctrl, home, end, arrows, del
	var aryCodes = [ 8, 9, 16, 17, 35, 36, 37, 38, 39, 46 ];
	if (!aryCodes.contains(code)) {
		field.value = field.value.replace(/[^0-9\-]/g, "");
		field.value = field.value.replace(/^([-][1-9]\d*|\d+)(.*?)$/g, "$1");
	}
	return true;
}

function formatAlphaNumeric(field, event) {
	// Usage: onkeyup="formatAlphaNumeric(this,event)"
	event = event || window.event;
	code = event.which || event.keyCode;
	//-- ignore backspace, tab, shift, ctrl, home, end, arrows, del
	var aryCodes = [ 8, 9, 16, 17, 35, 36, 37, 38, 39, 46 ];
	if (!aryCodes.contains(code)) {
		field.value = field.value.replace(/[^a-fA-F0-9]/g, "");
		field.value = field.value.replace(/^([a-fA-F0-9]{0,6})(.*?)$/g, "$1");
	}
	return true;
}

function formatZipCode(field, event) {
	// Usage: onkeyup="formatZipCode(this,event)"
	if (field.value.replace(/^\s+|\s+$/g, "") == "") {
		return true;
	}
	event = event || window.event;
	code = event.which || event.keyCode;
	//-- ignore backspace, tab, shift, ctrl, home, end, arrows, del
	var aryCodes = [ 8, 9, 16, 17, 35, 36, 37, 38, 39, 46 ];
	if (!aryCodes.contains(code)) {
		if (!field.value.match(/^[0-9]*$/)) {
			field.value = field.value.replace(/[^0-9]/g, "");
		}
		if (field.value.replace(/^\s*|\s*$/) != "") {
			if (!field.value.match(/^([0-9]{1,5})$/)) {
				field.value = field.value.replace(/([0-9]{1,5})([0-9]*)$/, "$1");
			}
		}
	}
	return true;
}

function isNumeric(text) {
	if (text.replace(/^\s+|\s+$/g, "") == "") {
		return false;
	}
	var objRegExp = /^([-][1-9]\d*|\d+)$/;
	return objRegExp.test(text);
}

function isPhone(text) {
	if (text.replace(/^\s+|\s+$/g, "") == "") {
		return false;
	}
	var objRegExp = /^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}(([\s]*(x|ext|ext.){1}[\s]*[0-9]{1,6}[\s]*|[\s]*[0-9]{0,6}[\s]*))$/;
	return objRegExp.test(text);
}

function formatCardNumber(field, amex, event) {
	try {
		var code = 0;
		if (event) {
			event = event || window.event;
			code = event.which || event.keyCode;
		}
		var code = 14;
		//-- ignore backspace, tab, shift, ctrl, home, end, arrows, del
		var aryCodes = [ 8, 9, 16, 17, 35, 36, 37, 38, 39, 46 ];
		if (!aryCodes.contains(code)) {
			return formatCardNumberBase(field, amex.checked);
		}
	} catch (er) { }
	return true;
}

function formatCardNumberBase(field, formatAmex) {
	try {
		if (field.value.replace(/^\s+|\s+$/g, "") == "") {
			return true;
		}
		var strValue = field.value.replace(/^\s+|\s+$/g, "");
		if (formatAmex) {
			if (strValue.match(/^\d{1,3}$/) ||
				strValue.match(/^\d{4}-?$/) ||
				strValue.match(/^\d{4}-\d{1,5}$/) ||
				strValue.match(/^\d{4}-\d{6}-?$/) ||
				strValue.match(/^\d{4}-\d{6}-\d{1,5}$/)
			) {
				return true;
			}
		} else {
			if (strValue.match(/^\d{1,3}$/) ||
				strValue.match(/^\d{4}-?$/) ||
				strValue.match(/^\d{4}-\d{1,3}$/) ||
				strValue.match(/^\d{4}-\d{4}-?$/) ||
				strValue.match(/^\d{4}-\d{4}-\d{1,3}$/) ||
				strValue.match(/^\d{4}-\d{4}-\d{4}-?$/) ||
				strValue.match(/^\d{4}-\d{4}-\d{4}-\d{1,4}$/)
			) {
				return true;
			}
		}
		
		strValue = strValue.replace(/[^0-9]/g, "");
		if (formatAmex) {
			if (strValue.length >= 10) {
				field.value = strValue.replace(/^(\d{4})(\d{6})(\d*)$/, "$1-$2-$3");
			} else if (strValue.length >= 4) {
				field.value = strValue.replace(/^(\d{4})(\d*)$/, "$1-$2");
			}
		} else {
			if (strValue.length >= 12) {
				field.value = strValue.replace(/^(\d{4})(\d{4})(\d{4})(\d*)$/, "$1-$2-$3-$4");
			} else if (strValue.length >= 8) {
				field.value = strValue.replace(/^(\d{4})(\d{4})(\d*)$/, "$1-$2-$3");
			} else if (strValue.length >= 4) {
				field.value = strValue.replace(/^(\d{4})(\d*)$/, "$1-$2");
			}
		}
	} catch (er) { }
	return true;
}

function validateFormField(isValid, theField, strMessage) {
	if (isValid && theField) {
		var strType = theField.type;
		try {
			strType = (theField[0].type != undefined ? theField[0].type : strType);
		} catch (er) { }
		var strValue = "";
		var isChecked = false;
		if (strType.indexOf("select") < 0) {
			if (strType.indexOf("checkbox") < 0 && strType.indexOf("radio") < 0) {
				strValue = new String(theField.value);
			} else {
				for (var i=0; i<theField.length; i++) {
					if (theField[i].checked) {
						strValue = new String(theField[i].value);
						isChecked = true;
						break;
					}
				}
			}
		} else {
			strValue = theField.options[theField.selectedIndex].value;
			strValue = (strValue.replace(/^\s+|\s+$/g, "") == "-1" ? "" : strValue);
		}
		if (strValue.replace(/^\s+|\s+$/g, "") == "" && !isChecked) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

function validateFormFieldState(isValid, theField, strMessage) {
	if (isValid && theField) {
		var strValue = new String(theField.value);
		if (strValue.replace(/^\s+|\s+$/g, "") == "") {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		var objRegExp = /^[a-zA-Z]{2}$/;
		if (!objRegExp.test(strValue)) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

function validateFormFieldZipCode(isValid, theField, strMessage) {
	if (isValid && theField) {
		var strValue = new String(theField.value);
		if (strValue.replace(/^\s+|\s+$/g, "") == "") {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		var objRegExp = /^[0-9]{5}$/;
		if (!objRegExp.test(strValue)) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

function validateFormFieldEmail(isValid, theField, strMessage) {
	if (isValid && theField) {
		var strValue = new String(theField.value);
		if (strValue.replace(/^\s+|\s+$/g, "") == "") {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		var objRegExp = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
		if (!objRegExp.test(strValue)) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

function validateFormFieldPhone(isValid, theField, strMessage) {
	if (isValid && theField) {
		var strValue = new String(theField.value);
		if (strValue.replace(/^\s+|\s+$/g, "") == "") {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		var objRegExp = /^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}(([\s]*(x|ext|ext.){1}[\s]*[0-9]{1,6}[\s]*|[\s]*[0-9]{0,6}[\s]*))$/;
		if (!objRegExp.test(strValue)) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

function validateFormFieldPassword(isValid, theField, strMessage) {
	if (isValid && theField) {
		var strValue = new String(theField.value);
		if (strValue.replace(/^\s+|\s+$/g, "") == "") {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		var objRegExp = /^[a-zA-Z0-9_\.\-]{6,}$/;
		if (!objRegExp.test(strValue)) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

function validateFormFieldEquals(isValid, theField1, theField2, strMessage) {
	if (isValid && theField1 && theField2) {
		if (theField1.value.replace(/^\s+|\s+$/g, "") != theField2.value.replace(/^\s+|\s+$/g, "")) {
			if (strMessage.replace(/^\s+|\s+$/g, "") != "") { alert(strMessage); }
			try {
				theField1.focus();
			} catch (er) { }
			return false;
		}
		return true;
	}
	return isValid;
}

var maxLengthField;
function imposeMaxLength(field, event) {
	//-- maxlength attribute must be set
	//-- onkeyup, onkeydown				return imposeMaxLength(this, event)
	//-- onpaste						imposeMaxLength(this, event); this.blur(); this.focus();
	//-- oninput, onfocus, onblur		imposeMaxLength(this, event)
	try {
		if (field.value.replace(/^\s+|\s+$/g, "") == "") {
			return true;
		}
		event = event || window.event;
		code = event.which || event.keyCode;
		//-- allow backspace, tab, shift, ctrl, home, end, arrows, del
		var aryCodes = [ 8, 9, 16, 17, 35, 36, 37, 38, 39, 46 ];
		if (aryCodes.contains(code)) {
			return true;
		}
		var maxlen = (field.getAttribute ? parseInt(field.getAttribute("maxlength")) : "");
		if (isNaN(maxlen)) {
			return true;
		}
		if (field.value.length >= maxlen) {
			field.value = field.value.substring(0, maxlen-1);
			maxLengthField = field;
			setTimeout("maxLengthField.scrollTop = maxLengthField.scrollHeight;", 0);
		}

		return (field.value.length < maxlen);
	} catch (err) {
		//alert(err.description);
		return true;
	}
}

var mapAddress, mapDirections, map, mapMarker;
function showMap(link, label, address1, address2, citystatezip) {
	try {
		if ((typeof map) != undefined) {
			var tmpAddress = address1 + (address2.replace(/^\s+|\s+$/g, "") != "" ? ", " : "") + address2 + "<br />" + citystatezip;
			var tmpAddress2 = unescape(tmpAddress.replace(/<br \/>/g, ", "));
			tmpAddress = tmpAddress.replace(/\%22/g, "&quot;").replace(/\%27/g, "&#39;");
			mapAddress = "<strong>" + label.replace(/\%22/g, "&quot;").replace(/\%27/g, "&#39;") + "</strong><br />" + tmpAddress.replace(/\%22/g, "&quot;").replace(/\%27/g, "&#39;");
			mapDirections = "<strong><a href='http://maps.yahoo.com/#mvt=m&zoom=17&q2=" + escape(tmpAddress2) + "' target='_blank'>Get Directions</a></strong>";
			map.removeOverlay(mapMarker);
			map.drawZoomAndCenter(tmpAddress2, 10);
			
			$("#mapText").html($(link).parent().prev(".details").html());
			$("#map").addClass("printable");
			setTimeout('$.fn.colorbox({ speed: 250, scrolling: false, inline: true, href: "#mapDetails", onCleanup:function(){$("#map").removeClass("printable");}});', 250);
		}
	} catch (err) {
		try { console.error(err.description); } catch (er) { /*alert(err.description);*/ }
	}
	return false;
}

function selectPrevShipping(objCheckbox, intAddressID) {
	if (objCheckbox.checked) {
		$("#previousShippingAddress input[name='ship_AddressID']").each(function(i){
			$(this).attr("checked", false);
			if ($(this).val() == intAddressID.toString()) {
				$(this).attr("checked", true);
				$("#newShippingAddress").hide();
				$("#previousShippingNo").attr("checked", false);
				$("#previousShippingYes").attr("checked", true);
				$("#previousShippingAddress").show();
			}
		});

		try {
			setTimeout(function() { objCheckbox.checked = false; }, 3000);
		} catch (err) { }
	} else {
		clearShipping(objCheckbox);
	}
}

function copyNewShipping(objCheckbox, firstName, middleInitial, lastName, companyName, address1, address2, city, state, zip, phone1, phone2, canadaAddress, intlAddress) {
	if (objCheckbox.checked) {
		theForm = objCheckbox.form;
		theForm.ship_FirstName.value = firstName;
		theForm.ship_MiddleInitial.value = middleInitial;
		theForm.ship_LastName.value = lastName;
		theForm.ship_CompanyName.value = companyName;
		theForm.ship_Address1.value = address1;
		theForm.ship_Address2.value = address2;
		theForm.ship_City.value = city;
		theForm.ship_State.value = state;
		theForm.ship_Zip.value = zip;
		theForm.ship_Phone1.value = phone1;
		theForm.ship_Phone2.value = phone2;
		theForm.ship_CanadaAddress.value = canadaAddress.replace(/<BR>/g, "\n");
		theForm.ship_IntlAddress.value = intlAddress.replace(/<BR>/g, "\n");

		$("#previousShippingAddress").hide();
		$("#previousShippingNo").attr("checked", true);
		$("#previousShippingYes").attr("checked", false);
		/*
		$("#intlShippingNo").attr("checked", $("#intlBillingNo").attr("checked"));
		$("#intlShippingCanada").attr("checked", $("#intlBillingCanada").attr("checked"));
		$("#intlShippingYes").attr("checked", $("#intlBillingYes").attr("checked"));
		if ($("#intlBillingNo").attr("checked") == true) {
			$("#canadaShippingAddress").hide();
			$("#intlShippingAddress").hide();
			$("#usShippingAddress").show();
		} else if ($("#intlBillingCanada").attr("checked") == true) {
			$("#usShippingAddress").hide();
			$("#intlShippingAddress").hide();
			$("#canadaShippingAddress").show();
		} else {
			$("#usShippingAddress").hide();
			$("#canadaShippingAddress").hide();
			$("#intlShippingAddress").show();
		}
		$("#newShippingAddress").show();
		*/
		if (canadaAddress.replace(/^\s+|\s+$/g, "") == "" && intlAddress.replace(/^\s+|\s+$/g, "") == "") {
			$("#intlShippingNo").attr("checked", true);
			$("#intlShippingCanada").attr("checked", false);
			$("#intlShippingYes").attr("checked", false);
			
			$("#usShippingAddress").show();
			$("#canadaShippingAddress").hide();
			$("#intlShippingAddress").hide();
		} else if (canadaAddress.replace(/^\s+|\s+$/g, "") != "") {
			$("#intlShippingNo").attr("checked", false);
			$("#intlShippingCanada").attr("checked", true);
			$("#intlShippingYes").attr("checked", false);
			
			$("#usShippingAddress").hide();
			$("#canadaShippingAddress").show();
			$("#intlShippingAddress").hide();
		} else {
			$("#intlShippingNo").attr("checked", false);
			$("#intlShippingCanada").attr("checked", false);
			$("#intlShippingYes").attr("checked", true);
			
			$("#usShippingAddress").hide();
			$("#canadaShippingAddress").hide();
			$("#intlShippingAddress").show();
		}
		$("#newShippingAddress").show();

		try {
			setTimeout(function() { objCheckbox.checked = false; }, 3000);
		} catch (err) { }
	} else {
		clearShipping(objCheckbox);
	}
}

function clearShipping(objCheckbox) {
	if (!objCheckbox.checked) {
		theForm = objCheckbox.form;
		theForm.ship_FirstName.value = "";
		theForm.ship_MiddleInitial.value = "";
		theForm.ship_LastName.value = "";
		theForm.ship_CompanyName.value = "";
		theForm.ship_Address1.value = "";
		theForm.ship_Address2.value = "";
		theForm.ship_City.value = "";
		theForm.ship_State.value = "";
		theForm.ship_Zip.value = "";
		theForm.ship_Phone1.value = "";
		theForm.ship_Phone2.value = "";
		theForm.ship_CanadaAddress.value = "";
		theForm.ship_IntlAddress.value = "";

		$("#previousShippingAddress input[name='ship_AddressID']").attr("checked", false);
		$("#previousShippingAddress").hide();
		$("#previousShippingNo").attr("checked", true);
		$("#previousShippingYes").attr("checked", false);
		$("#intlShippingNo").attr("checked", true);
		$("#intlShippingCanada").attr("checked", false);
		$("#intlShippingYes").attr("checked", false);
		$("#canadaShippingAddress").hide();
		$("#intlShippingAddress").hide();
		$("#usShippingAddress").show();
		$("#newShippingAddress").show();
	}
}

function checkAddresses(objElement) {
	var parent = $("#previousBillingAddress");
	var inputName = "bill_AddressID";
	if ($(objElement).attr("name") == "previousShipping") {
		parent = $("#previousShippingAddress");
		inputName = "ship_AddressID";
	}
	if ($("input[name='" + inputName + "']:checked", parent).length == 0) {
		$("input[name='" + inputName + "']", parent).first().attr("checked", true);
	}
}

$(document).ready(function(){
	$("a.colorbox").each(function(){
		if (this.rel) {
			$("a[rel='" + this.rel + "']").colorbox();
		} else {
			$(this).colorbox();
		}
	});
	//-- the following makes colorbox work on iOS devices
	if (navigator.userAgent.match(/Mobile/i) && navigator.userAgent.match(/Safari/i)) {
		var ios_scrollTop = $(window).scrollTop() + 75;
		$(document).bind("cbox_load, cbox_complete", function(){
			var ios_scrollLeft = ($(document).width() - $(window).width()) / 2 - $(window).scrollLeft();
			if ($(window).scrollTop() <= 0) {
				window.scrollTo(0, 1);
			}
			$("#cboxOverlay").css({width:$(document).width(),height:$(document).height()});
			$("#colorbox").css("webkitTransition", "all .5s ease-in-out");
			$("#colorbox").css("webkitTransform", "translate(" + (ios_scrollLeft).toString() + "px, " + (ios_scrollTop).toString() + "px)");
		});
	}
	
	$("#nav li.navitem").has("ul").hover(
		function() {
			$(this).clearQueue();
			$(this).delay(250);
			$(this).queue(function(){
				$(this).addClass("hover");
				$(this).dequeue();
			});
		},
		function() {
			$(this).clearQueue();
			$(this).delay(250);
			$(this).queue(function(){
				$(this).removeClass("hover");
				$(this).dequeue();
			});
		}
	);
	//-- makes drop-down navigation work on iOS devices
	if (navigator.userAgent.match(/Mobile/i) && navigator.userAgent.match(/Safari/i)) {
		$(document).bind("touchmove", function(){
			$("#nav li.hover").mouseout();
		});
		$("#nav li.navitem").has("ul").unbind("mouseenter");
		$("#nav li.navitem").has("ul").children("a.navlink").click(function() {
			var parent = $(this).parent("li.navitem");
			if (parent.hasClass("hover")) {
				return true;
			}
			parent.clearQueue();
			parent.delay(250);
			parent.queue(function(){
				parent.addClass("hover");
				parent.dequeue();
			});
			return false;
		});
	}

	$("#search form input[name='k']").focus(function() {
		if ($(this).hasClass("empty")) {
			$(this).val("");
			$(this).removeClass("empty");
		}
	});
	$("#search form input[name='k']").blur(function() {
		if ($(this).val().replace(/^\s+|\s+$/g, "") == "" || $(this).val().replace(/^\s+|\s+$/g, "") == $(this).attr("title")) {
			$(this).val($(this).attr("title"));
			$(this).addClass("empty");
		}
	});
	$("#search form input[name='k']").blur();
	$("#search form").submit(function() {
		if ($("#search form input[name='k']").hasClass("empty")) {
			$("#search form input[name='k']").val("");
			$("#search form input[name='k']").removeClass("empty");
		}
	});
	$("body.pg-item #content .product-images a.primary").hover(
		function() {
			$(this).parents("div.primary-shadow").addClass("primary-hover");
		},
		function() {
			$(this).parents("div.primary-shadow").removeClass("primary-hover");
		}
	);
	$("img.jQreflect").reflect({height: 45, opacity: 0.75});
});

$(window).load(function(){
	$("div#bannerImageScroller").smoothDivScroll({ autoScroll: "always", autoScrollDirection: "endlessloopleft", autoScrollStep: 2, autoScrollInterval: 25 }).smoothDivScroll("moveToElement", "first");
	$("div#bannerImageScroller").bind("mouseover", function() {
		$(this).smoothDivScroll("stopAutoScroll");
	}).bind("mouseout", function() {
		$(this).smoothDivScroll("startAutoScroll");
	});
	$("div#bannerImageScroller a").bind("mouseover", function() {
		var img = $("img", this);
		var imgWidth = img.attr("rel").substr(img.attr("rel").indexOf("-")+1)+"px";
		$(this).stop(true,false).delay(250).animate({marginTop: "0px", paddingLeft: "0px", paddingRight: "0px"}, 250);
		$("span.tooltip", this).stop(true,false).css({left: "0px", top: "140px", width: imgWidth}).delay(750).animate({opacity: 0.8}, 250);
		img.stop(true,false).delay(250).animate({height: "160px"}, 250);
		img.next().stop(true,false).delay(250).animate({width: imgWidth}, 250);
		if ($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent) && document.all && !window.opera && !window.XMLHttpRequest) {
			img.eq(0).stop(true,false).animate({opacity: 1}, 250).animate({height: "160px"}, 250);
		}
	}).bind("mouseout", function() {
		var img = $("img", this);
		var imgWidth = img.attr("rel").substr(0,img.attr("rel").indexOf("-"))+"px";
		$(this).stop(true,false).animate({marginTop: "15px", paddingLeft: "7px", paddingRight: "7px"}, 250);
		$("span.tooltip", this).stop(true,false).animate({left: "7px", top: "110px", width: imgWidth, opacity: 0}, 250);
		img.stop(true,false).animate({height: "130px"}, 250);
		img.next().stop(true,false).animate({width: imgWidth}, 250);
		if ($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent) && document.all && !window.opera && !window.XMLHttpRequest) {
			img.eq(0).animate({opacity: 0}, 250);
		}
	});
	$("div#bannerImageScroller a img").each(function() {
		var cwidth = $(this).width();
		var cheight = $(this).height();
		var nwidth = Math.round((160 / cheight) * cwidth, 0);
		$(this).attr("rel", cwidth.toString() + "-" + nwidth.toString());
		$(this).parent().next("span.tooltip").css({ display: "block", opacity: 0 });
		if ($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent) && document.all && !window.opera && !window.XMLHttpRequest) {
			if ($(this).hasClass("reflected")) {
				$(this).parents("a").css("background-image", "url(" + $(this).attr("src").replace("maxheight=160", "maxheight=130") + ")");
				$(this).css({opacity: 0});
			}
		}
	});
	if ($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent) && document.all && !window.opera && !window.XMLHttpRequest) {
		if ($("#bannerImageScroller div.scrollableArea").width() < 970) {
			$("#bannerImageScroller div.scrollableArea").width(function(){
				return $(this).width() + 45;
			});
		}
	}
});

