jQuery(function($){
				
$(document).ready(function(){

	$(".preload_img").show();
	
	load_cart("");
	
   $(".us_only").hide();
	
	switch_state();

	$("#txtShippingCountry").change(function(){													 
		
		switch_state();
	
	});
		
		
	switch_address();
	
	$("#use_paypal_address").click(function(){											
							
		switch_address();									

	});
		
	$(".add").click(function() {
			$(this).addClass('already')
                   .removeClass('add')
                   .html('Добавлено<br>в гардероб');
                   
            $("#ten").show();
            $("#hint").css("top","-500px");				 
			var id = $(this).attr("id");
			var name = $("form."+id+" .item_name").val();
			var url = $("form."+id+" .item_url").val();
			var qty = $("form."+id+" .item_qty").val();
			var price = $("form."+id+" .item_price").val();
			var item_options_name = $("form."+id+" .item_options_name").val();
			var item_options = $("form."+id+" .item_options").val();
			var shipping = $("form."+id+" .item_shipping").val();
			var itemValues = "item_id="+ id + "&item_name=" + name + "&item_options_name="+item_options_name+"&item_options="+item_options+"&item_url=" + escape(url) + "&item_qty=" + qty + "&item_price="+price+"&item_shipping=" +shipping+ "&action=add_item"; 
			load_cart(itemValues);
         
            jQuery(".cartb")
                .stop()
                .css("width","0px")
                .css("height", "87px")
                .css("left", "-25px")
                .fadeIn(100)
                .animate({width:'380px', left:'-=405'}, 400, function(){ jQuery("#dform_c").fadeIn(300, function(){window.setTimeout(close_cart_info, 5000);}); })
   		
			return false; 
	
	});
    
    
    $(".add3").click(function() {
			$(this.form).find('.add2').fadeIn(100);
                   				 
			var id = $(this).attr("id");
			var name = $("form."+id+" .item_name").val();
			var url = $("form."+id+" .item_url").val();
			var qty = $("form."+id+" .item_qty").val();
			var price = $("form."+id+" .item_price").val();
			var item_options_name = $("form."+id+" .item_options_name").val();
			var item_options = $("form."+id+" .item_options").val();
			var shipping = $("form."+id+" .item_shipping").val();
			var itemValues = "item_id="+ id + "&item_name=" + name + "&item_options_name="+item_options_name+"&item_options="+item_options+"&item_url=" + escape(url) + "&item_qty=" + qty + "&item_price="+price+"&item_shipping=" +shipping+ "&action=add_item"; 
			load_cart(itemValues);
         
            jQuery(".cartb")
                .stop()
                .css("width","0px")
                .css("height", "87px")
                .css("left", "-25px")
                .fadeIn(100)
                .animate({width:'380px', left:'-=405'}, 400, function(){ jQuery("#dform_c").fadeIn(300, function(){window.setTimeout(close_cart_info, 5000);}); })
   		
			return false; 
	
	});
    
    $(".add_c").hover(function(){
        document.getElementById('hint').style.display='block';
    }, function(){
        document.getElementById('hint').style.display='none';
    })		

});

function switch_address(){
	
	if($("#use_paypal_address").is(":checked")){
		
			$("table.AddressEntryTable .address_box").attr("disabled", "disabled");
			$("table.AddressEntryTable .label").css("color","gray");
			
	} else {
		
			$("table.AddressEntryTable .address_box").attr("disabled", "");
			var inicial_color = $("table.entryTable").css("color");
			$("table.AddressEntryTable .label").css("color",inicial_color);				
		
	}	
	
}

function switch_state(){

	if ($("#txtShippingCountry").val() == "US") {
		
	  $(".wpchkt_state").addClass("hidden");
	  $(".wpchkt_state_us").removeClass("hidden");
	  
	  $("#txtShippingState_all").val("");
		
	} else {
		
	  $(".wpchkt_state_us").addClass("hidden");
	  $(".wpchkt_state").removeClass("hidden");
		
	}
}
 
function load_cart(values){

	 $("#wpchkt_widget").load(wpchkt_c_url, values,function(){
			$(".preload_img").hide();
			 $("#wpchkt_widget .update_cart").hide();
			 buttons_events();									 
	 });

}
 
function buttons_events() {
	
	$("#wpchkt_widget .remove_item").click(function() {				 
									
		$(".preload_img").show();	
		var id = $(this).attr("name");
		var itemValues = "remove="+id;		
		load_cart(itemValues);		
		return false;
	
	});
	
	
	$("#wpchkt_widget input").change(function() {
	
		var id = $(this).attr("title");
		var qty = '0';		
		var itemValues = "id="+id+"&qty="+qty+"&update_item=true";
		load_cart(itemValues);	
		return false;		
	});
	
	
	$(".empty_cart").click(function() { 
									
		var itemValues = "empty=true";		
		load_cart(itemValues);
		return false;
	
	});

}

}); 

function close_cart_info(){
   jQuery(".cartb").fadeOut(300); 
}
