$(function(){	
	
	/*########################################################################################################################
	##
	## clear form value, show again if nothing entered
	##
	*/
	var elem = $("input:text, input:password, textarea");
	elem.each(function(){
		$(this).attr("alt",$(this).val());
	});
	
	elem.focus(function() {
		if($(this).val()==$(this).attr("alt")) {
			$(this).val("");
		}
	});
	
	elem.blur(function() {
		if($(this).val()=="") {
			$(this).val($(this).attr("alt"));
		}
	});

/*########################################################################################################################
	##
	## apply first and last child classes to li's (damn you ie)
	##
	*/
	$("ul li:first-child").each(function(){
		$(this).addClass("first");
	});
	
	$("ul li:last-child").each(function(){
		$(this).addClass("last");
	});
	
	//hover class
	$('ul li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	
/*########################################################################################################################
	##
	## fancybox
	##
	*/
	
	$("a.fancy").fancybox();
	
	$("a.fancy2").fancybox({
		frameHeight:430			   
	});
	
	
	
	// add active class to "open" li
	$("#leftNav li ul").each(function(){
		$(this).parents("li").addClass("active");
	});
	
	
	/*########################################################################################################################
	##
	## closed shop
	##
	*/
	
	$(".closed").each(function(){
		$(this).css({opacity:0.5, cursor:'default'});
		$(this).children("*").css({cursor:'default'});
		$(this).children("*").click(function(){
			return false;
		});
	});
	
	
	/*########################################################################################################################
	##
	## quantity increase
	##
	*/
	
	$("#quant a").click(function(){
	
		if ( $(this).attr("class") == 'inc'){
			var newVal = parseInt( $("#quant input").val() );
			$("#quant input").val(newVal+1);
			$.get("/ajax/update_future_delivery_cost.ajax.php",{ variation_id: $('#hidden_product_variation').html(), quantity: newVal+1 },function(data){$("#future_delivery_cost").html(data)});
			return false;
		}
		else if ( $(this).attr("class") == 'dec'){
			if ( $("#quant input").val() > 0 ) {
				var newVal = parseInt( $("#quant input").val() );
				$("#quant input").val(newVal-1);
				$.get("/ajax/update_future_delivery_cost.ajax.php",{ variation_id: $('#hidden_product_variation').html(), quantity: newVal-1 },function(data){$("#future_delivery_cost").html(data)});
			}
			return false;
		}
		else {
			return false;
		}
	
	});

});
