$(document).ready(function() {
	$(".search_area").focus(function() {
		if($(this).val() == "PRODUCTS SEARCH") {
			$(this).css({color: "#2d4212"}).val("");
		}
	}).blur(function() {
		if($(this).val() == "") {
			$(this).css({color: "#cadbb4"}).val("PRODUCTS SEARCH");
		}
	});

	$(".related_product .products_item div").css("opacity", 0.9);
	$(".products_line_category .products_item div").css("opacity", 0.9);

	$("table tr:has(td):odd").css("backgroundColor", "#f0ffdc");
	$("table tr:has(td)").hover(function() {
		$(this).addClass("trhover");
	}, function() {
		$(this).removeClass("trhover");
	});

	$(".product_image_small").hover(function() {
		$(this).addClass("product_image_small_hover"); 
	}, function() {
		$(this).removeClass("product_image_small_hover"); 
	});
	$(".product_navi div").click(function() {
		var x = $(this).index();
		x++;
		$(".img" + x).fadeIn("fast").siblings("a").fadeOut("fast");
	});

	$(".question").click(function() {
		var content = $(this).next();
		var others = content.parent().find("div.answer:visible");
		content.slideDown();
		others.slideUp();
	});

	$(".sidebar_items .hassub").toggle(function() {
		$(this).next().slideDown("fast");	
		$(this).toggleClass("span_state");
		return false;
	}, function() {
		$(this).next().slideUp("fast");	
		$(this).toggleClass("span_state");
		return false;
	});

	$(".submit").click(function() {
		var contact = $("#id_comment").val();
		if (!contact.match(/[^\s]+/)){
			alert("Please fill in the Comments or Enquiry, thanks!");
			return false;
		}
	});

	var quantity = $(".quantity_line input");
	quantity.bind({
		focus: function() {
		},
		blur: function() {
			var tr = $("tr:not(.tb_first)");
			var wsp = 0;
			var qty = 0;
			var total = 0;
			tr.each(function() {
				wsp = $(this).children(".price").html();
				qty = parseInt($(this).find("input").val());
				total = total + wsp * qty;
			});

			var amount = parseInt($(this).val());
			if(amount.toString().match(/[0-9.]+/) && typeof amount == "number") {
				$(".subtotal span").empty().append(total);
			} else {
				$(this).empty().attr("value", 0);
			}
		}
	});
});

