/*
	Webshop v1.0.0
	Comm: KidsComplete
	Copyright  2007-2008 Fluxility Design

*/
$(document).ready(function(){
	$(".loginbox input").attr("value","");
	$(".loginbox label").css("display","block");
	$(".loginbox input").focus(function(){
		type=$(this).attr("name");
		$(".loginbox label[@for="+type+"]").css("display","none");
	}).blur(function(){
		type=$(this).attr("name");
		if($(this).val() == '') { $(".loginbox label[@for="+type+"]").css("display","block"); }
	});


	$(".searchbox input").attr("value","");
	$(".searchbox label").css("display","block");
	$(".searchbox input").focus(function(){
		type=$(this).attr("name");
		$(".searchbox label[@for="+type+"]").css("display","none");
	}).blur(function(){
		type=$(this).attr("name");
		if($(this).val() == '') { $(".searchbox label[@for="+type+"]").css("display","block"); }
	});


	$(".shop-update").remove();
	$(".prod-count").blur(function(){
		$(this).val((Math.round($(this).val()) ? Math.round($(this).val()) : ""));
		$("#prod-total-"+$(this).attr("name").substr(11)).text("...");
		$.post("/ajax.php5", {
			action: "cart-update",
			name: $(this).attr("name").substr(11),
			value: $(this).val()
		}, function(xml){
			  xml = xml.split("\t");
			  $("#prod-total-"+xml[0]).text(xml[1]);
			  $("#cart-items").text(xml[2]);
			  $("#cart-price").text(xml[3]);
		});
	});
	$("<a class=\"bb-add bb\" title=\"een product erbij\">+<span> 1 product erbij</span></a>").insertAfter(".prod-count");
	$("a.bb-add").click(function(){
	  if(window.update_cart_timer) {
	    clearTimeout(window.update_cart_timer);
	  }

		obj = $(this).prev();
		if(obj.val()=="") { obj.val(0); }
		$(this).prev().val(parseInt($(this).prev().val())+1);

		var thistimer = this;
		window.update_cart_timer = setTimeout(function() { thistimer.countdown() }, 200);

		this.countdown = function () {
		  $(this).prev().blur();
		};

	});
	$("<a class=\"bb-remove bb\" title=\"een product eraf\">-<span> 1 product eraf</span></a>").insertBefore(".prod-count");
	$("a.bb-remove").click(function(){
	  if(window.update_cart_timer) {
	    clearTimeout(window.update_cart_timer);
	  }

        obj = $(this).next();
		if(obj.val()!=""){
            
			$(this).next().val(parseInt($(this).next().val())-1);

  		var thistimer = this;
  		window.update_cart_timer = setTimeout(function() { thistimer.countdown() }, 200);
		}

		this.countdown = function() {
		  $(this).next().blur();
		};

	});

	$(".prod-count").keypress(function(e){
		if(e.which == 13){
			$(this).triggerHandler("blur");
			obj = $(this).parent().parent().next().children().children(".prod-count");
			if( obj.attr("class")=="prod-count" ) {
				obj.focus();
			}else{
				obj = $(this).parent().parent().parent().parent().parent().next().children("table").children().children().children().children(".prod-count:first");
				if( obj.attr("class")=="prod-count" ) {
					obj.focus();
				}else{
					$(".prod-count:first").focus();
				}
			}
			return false;
		}
	});
	//$("#banner2").flash({
	//	src: '/resources/scripts/bambix2.swf',
	//	width:488,
	//	height:60
	//});
});

