// enble JS styles
$("div.productListingOptions").addClass("jsEnabled");
// close box
$("a.closeBox").click(
	function(){
		$(this).parent().hide();
		return false;
	}
)
// set class for checked elements
$(".colOptions label input:checked")
	.each(
		function(){
			$(this).parent().find("span").addClass("radioChecked")
		}
	)
// set class on hover
$(".colOptions label span:not(.radioChecked)")
	.hover(
		function(){
			$(this).addClass("hover")
		},
		function(){
			$(this).removeClass("hover")
		}
	)
// change classes and selected input on click - enabled radios
$(".colOptions label:has(input:enabled)")
	.each(
		function(){
			$(this).find("span").bind (
				"click",
				function(){
					// remove classes on all elements
					$(this).parent().parent().find("span").removeClass("radioChecked");
					// uncheck all elements
					$(this).parent().parent().find("input:checked").each(function() {
						this.checked = false;
					});
					// add class on click element
					$(this).addClass("radioChecked");
					// check clicked element
					$(this).parent().find(":radio").each(function() {
						this.checked = true;
					});
					return false;
				}
			)
		}
	)
// change classes and selected input on click - disabled radios
$(".cOption label:has(input:disabled)")
	.each(
		function(){
			$(this).bind (
				"click",
				function(){
					// get product title and url encode
					var pTitle = $(this).parent().parent().parent().parent().find("h6 strong").text();
					// else get other place title might be
					if (pTitle.length < 1) {
						 pTitle = $(this).parent().parent().parent().find("h2 strong").text();
					}
					var pColour = $("#tooltip h3").text();
					var pTitleSafe = escape(pTitle);
					var pColourSafe = escape(pColour);
					// remove div for out of stock items already created
					$("#contactHolder").remove();
					// create a div and insert it into parent container
					$("<div id=\"contactHolder\"><p><strong>This product is currently out of stock.</strong><br /><br />Please <a href=\"mailto:info@ettinger.co.uk?subject=Product%20Request%20for%20"+pTitleSafe+"%20in%20"+pColourSafe+"&amp;body=Please%20enter%20you%20contact%20details%20and%20we%20will%20get%20back%20to%20you.\">click here</a> to request "+pTitle+" in "+pColour+".</p></div>").appendTo($(this).parent().parent().parent().parent());
					// add a close link to the div
					$("<p><a id=\"closeContactHolder\" href=\"#\">Close</a></p>").appendTo("#contactHolder").click(
						function(){
							$("#contactHolder").remove();
							return false;
						}
					);
					return false;
				}
			)
		}
	)
// add to bag
$("div.productListingLinks .sendToBag").click(
	function(){
		if ($(this).parent().find("div.productListingOptions").css("display") == 'block') {
			$(this).parent().parent().submit();
		} else {
			$(this).parent().find("div.productListingOptions").show();
		}
		return false;
	}
)
// buy now
$("div.productListingLinks .buyNowBtn :image").click(
	function(){
		$(this).parent().parent().parent().parent().append("<input type=\"hidden\" value=\"buy\" name=\"buy_now\"/>");
		$(this).parent().parent().parent().parent().submit();
		return false;
	}
)


function tep_filename(str){
	str = str.replace('/', '');
	str = str.replace('\\', '');		
	str = str.replace('<', '');		
	str = str.replace('>', '');		
	str = str.replace(' ', '-');
	str = str.replace('%', '');
	str = str.replace('£', '');
	str = str.replace("'", '');
	str = str.replace(":", '');
	str = str.replace("&", '');
	str = str.replace("0", 'zero');
	str = str.replace("1", 'one');
	str = str.replace("2", 'two');
	str = str.replace("3", 'three');
	str = str.replace("4", 'four');
	str = str.replace("5", 'five');
	str = str.replace("6", 'six');
	str = str.replace("7", 'seven');
	str = str.replace("8", 'eight');
	str = str.replace("9", 'nine');
	return(str);
}

function popupWindow(url, width, height) {
	if(typeof width == 'undefined') width = 400;
	if(typeof height == 'undefined') height = 400;
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + width + ',height=' + height + ',screenX=150,screenY=150,top=150,left=150');
}