function updateUserBasket() {
	jQuery("#user_basket_info").find(".basket_ajax_info").fadeIn("slow").load('/ua/basket/user/ajax');
}

function calculate(obj) {
	jQuery("#charge_block").load('/index.php?type=basket&action=charge&ajax&lang=ua','',function(){
		obj.removeAttr("disabled");
		updateUserBasket();
		}
	);
}

/*-------------------------------------Випадайка верхнє меню-------------------*/
jQuery(document).ready(function(){
		    jQuery('.top_menu_f ul li').hover(
				function() {
					jQuery(this).addClass("active");
					jQuery(this).find('ul').stop(true, true);
					jQuery(this).find('ul').slideDown('fast');
				},
				function() {
					jQuery(this).removeClass("active");
					jQuery(this).find('ul').slideUp('fast');
				}
			);
		    
/*--------------------Горталка фото-----------------------------*/	
/*slCONT*/
/*Кількість речей*/
var NN = jQuery("#photo_product_count").val();
var lN = 0;
var rN = NN-1;
on_NP = 0;
					
jQuery("#AA").click(function(){
	if ( jQuery(".box_gal2").find('#AA').hasClass("left_g_ac")){
		if (on_NP) return false;
		
		on_NP = 1;
		rN++;
		lN--;
		jQuery(".photo_frame").find("#gort").animate({left:"+=512px"},500);		
    }	
	if (!lN) {
		jQuery(".box_gal2").find('#AA').removeClass("left_g_ac").addClass("left_g_na");
	}
    jQuery(".box_gal2").find('#BB').removeClass("right_g_na").addClass("right_g_ac");
    window.setTimeout('on_NP = 0;',1250);
});

jQuery("#BB").click(function(){
	if ( jQuery(".box_gal2").find('#BB').hasClass("right_g_ac")){
		if (on_NP) return false;
		
		on_NP = 1;
		rN--;
		lN++;
		
		jQuery(".photo_frame").find("#gort").animate({left:"-=512px"},500);
	}
	if (!rN) {
		jQuery(".box_gal2").find('#BB').removeClass("right_g_ac").addClass("right_g_na");
	}
	jQuery(".box_gal2").find('#AA').removeClass("left_g_na").addClass("left_g_ac");
	window.setTimeout('on_NP = 0;',1250);
});




/*--------------------------Товари з категорії---------------------*/
jQuery("div.d000").scrollable({size:3}).mousewheel();

/*----------------- Додати в корзину ----------*/

jQuery(".but_fan").click(function() {
	var prod_id = jQuery("#cart_product_id").val();
	var obj_this = jQuery(this);
	jQuery.ajax(
	{
  		type: "POST",
  		url: "/index.php?type=basket&action=addProduct&ajax&lang=ua",
  		data: {'prod_id':prod_id, 'prod_count':jQuery("#cart_product_count").val(), 'prod_size': jQuery("#cart_product_size").val()},
  		beforeSend: function(req) {
  			obj_this.addClass('ajax_bgs');  			
  		},
  		success: function(msg,status){  			  			
  			obj_this.removeClass('ajax_bgs');  
                        msg = msg.replace(/\r\n\r\n/g, '');
  			if(msg == 'Ви не авторизовані!')
  			{
  				jAlert(msg, 'Інформація');	
  			}	
  			else if(msg == 'Товар додано у кошик')
  			{
  				jAlert(msg, 'Інформація');	
  				updateUserBasket();
  			}
  			else if(msg = 'Цього товару тимчасово немає на складі')
  			{
  				jAlert(msg, 'Інформація');
  			}
  			//alert(msg);
  			
  		},
  		error: function(msg) {
  			alert('Вибачте, трапилась помилка. Спробуйте ще раз');
  		},
  		complete: function(req,msg) {
  			obj_this.removeClass('ajax_bgs');  			
  		}							
	});

	return false;
});

//
jQuery(".minus").click(function(){ 
	var val = parseInt(jQuery(this).next().find('input').val());
	if (val > 1) {
		jQuery(this).next().find('input').val(val-1).change();
	}
	return false;
});
//
jQuery(".plus").click(function(){ 
	var val = parseInt(jQuery(this).prev().find('input').val()); 
	jQuery(this).prev().find('input').val(val+1).change(); 
	return false;  
});

jQuery(".t_text_").change(function(){
	var obj = jQuery(this);
	var prod_count = parseInt(jQuery(this).val());
	var prod_id = jQuery(this).attr('prod_id');
	var prod_size = jQuery(this).attr('prod_size');
	var price = jQuery(this).attr('price');
	if( (prod_count<1) || isNaN(prod_count) ) { 
		prod_count = 1; jQuery(this).val(1);
	}
	sum = price*prod_count;	
	jQuery.ajax({
		type: "POST", 
		url: "/?type=basket&action=setProduct&ajax&lang=ua", 
		data: {'prod_id': prod_id, 'prod_size': prod_size, 'prod_count': prod_count},
		beforeSend: function(msg) {
			obj.attr("disabled", true);
		},
		success: function(msg) {
			if(prod_count>1) obj.parent().parent().next().html(price+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span> "+sum+"</span>");
			else obj.parent().parent().next().html(sum+" грн.");
			calculate(obj);			
		},
		complete: function(msg) {
			
		},		
		error: function(msg) {
			window.location.reload();
		},
	});
	return false;
 });
   
   /*----------------------Authorization AJAX--------------------------------*/
		jQuery("#loginForm").submit(function(){
			var email = jQuery("#login_email").val();
			var pass = jQuery("#login_pass").val();
			
			jQuery("#insertForm").fadeOut("slow").hide();
			jQuery("#login_loader").fadeIn("slow").show();
			//jQuery(".basket_ajax_info").fadeIn("slow").html('<img id="login_loader" src="img/preloader.gif" style="display: none; margin-left:86px; margin-top:17px;">');
			
			jQuery.ajax({
				type: "POST", 
				url: "/auth_on_shop.php",
				data: {'email': email, 'pass': pass},

				success: function(msg){
					if(msg == 'Не правильно введений логін або пароль' || msg == 'Вас забанено! Всі питання до адміністратора сайту.')
					{
						jQuery("#login_loader").fadeOut("slow").hide();
						jQuery("#insertForm").fadeIn("slow").show();
						jAlert(msg, 'Увага');
					}
					else
					{
						jQuery("#login_loader").fadeOut("slow").hide();
						jQuery("#user_basket_info").fadeIn("slow").append(msg);
						//alert(msg);
					}
				}
			});
			
		});
	/*------------------------------------------------------------------------*/	


});
