//<script type="text/javascript">
jQuery(function() {
	jQuery(".but_kupit").click(function (){
		flag['user_cart']= 'yes';
		jQuery(".but_oform").show();
		var click_href_add = jQuery(this).attr('href')+'&jquerystop';
		jQuery.get(click_href_add, function(data){
		},'html');
		var id = jQuery(this).attr('id');
		var price = parseInt(parseFloat(jQuery(this).attr('id').replace(/(.*sum)|(_-_.*)/ig, "")),'10');
		var quantity= 1;
		id_product = jQuery(this).attr('id').replace(/(.*_-_q)/ig, "");
		text= '#text_cart_'+id_product;
		photo= '#photo_cart_'+id_product;
		photo_thumb= '#thumb_'+id_product;
		price_html= '#price_cart_'+id_product;
		//var price= 0;
		flag.quantity=parseInt(parseFloat(jQuery('#bin_content_quantity').html()),'10');
		flag.price=flag.price + price*quantity;		
		flag.quantity+=quantity;
		jQuery('#bin_content_quantity').html(flag.quantity);
		jQuery('#bin_content_sum').html(flag.price);
		jQuery('#'+id).append('<img class="but_green_ok_center_up" id="but_green_ok'+id+'" src="i/but_green_ok.gif">');
		jQuery('#but_green_ok'+id).fadeIn('slow');
		setTimeout(function () { 		jQuery('#but_green_ok'+id).fadeOut('slow'); }, 2000);
		setTimeout(function () { 		jQuery('#but_green_ok'+id).remove(); }, 4100);
		if ('1'==flag.quantity)
			//jQuery("#inner_popup").html('');
		jQuery("#cart_empty_show").hide();
		jQuery("#inner_popup").prepend('<div id="bin_pop_products_'+id_product+'"><div id="close_'+id_product+'" class="bin_popup_close"><a onclick="return false;" id="products_'+id_product+'-sum'+price+'_-_q'+quantity+'" href="/shop/index.php?products_id='+id_product+'&action=delete_product"><img src="i/bin_popup_close.gif" alt="X" /></a></div>'+'<table class="bin_popup_item" cellspacing="0" cellpadding="0"><tbody>'	+'<tr><td>'+jQuery(photo).html()+'</td><td style="text-align:left;">'+jQuery(text).html()+'<br/>'+jQuery(price_html).html()+'<br /><input type="hidden" value="'+id_product+'" name="products_id[]"/><label for="stc">Кол-во:</label><select id="cart_quantity_99" name="cart_quantity[]" onchange="this.form.submit();"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select></td></tr></tbody></table><div class="hr"></div></div></div>');
		jQuery("#inner_popup "+photo_thumb).attr('height','49').attr('width','62');
		flag['user_cart']= 'yes';
		setTimeout(function () {
			//jQuery(".but_kupit").css('background-image','url(i/compare_blue.gif)');
			jQuery("#"+id).attr('class','');
			jQuery('#'+id).html('<a class="but_kupit_ok" href="">Оформить</a>').hide();
			jQuery('#'+id).stop().fadeIn('slow');
			jQuery('#products_'+id_product+'-sum'+price+'_-_q'+quantity).click(function (){
			jQuery('#'+id).html('<a class="but_kupit" href="">Купить</a>');
		});

			jQuery(".but_kupit_ok").click(function(){
				flag['user_cart']= 'yes';
				basket_show();
				return false;
			});
		}, 1000);
		return false;
	});

		jQuery(".but_kupit_ok").click(function(){
				flag['user_cart']= 'yes';
				basket_show();
				return false;
			});

	jQuery(".but_after_add_to_cart").live('click',function(){
		flag['user_cart']= 'yes';
		basket_show();
		return false;
	});

	jQuery("#buy_submit").click(function (){
		submit_click(this);
		return false;
	});

	jQuery("#tp_fixjquery").hover(
		function (){
			jQuery('#show_icqfixjquery').fadeIn('slow');
		},function (){
			jQuery('#show_icqfixjquery').hide();
	});

	jQuery(".bin_popup_close").live("click", function(){
		close_pop_products(this);
		return false;	
	});

	//jQueriy(".but_after_add_to_cart").live('click',function(){
		//basket_show();
		//return false;
	//});
});

function submit_click(value){
	flag['user_cart']= 'yes';
	jQuery(".but_oform").show();
	jQuery("#cart_empty_show").hide();
	jQuery("#bin_pop_products_99").slideDown('slow');
	var click_href_add = jQuery.trim(jQuery("form#id_cart_add").attr('action'))+'&jquerystop';
	serialize = jQuery("form#id_cart_add").serialize();
	jQuery.post(click_href_add, serialize, function (data) {
	},'html');
	var quantity = parseInt(parseFloat(jQuery('select#cart_qty_for_add option:selected').attr('value')),'10');
	quantity_for_cart = quantity-1;
	jQuery('#cart_quantity_99 option:eq('+quantity_for_cart+')').attr('selected','selected');
	if (quantity==='') quantity= 1;
	flag.quantity=parseInt(parseFloat(jQuery('#bin_content_quantity').html()),'10');
	var price = parseInt(parseFloat(jQuery(value).children().attr('id').replace(/(.*sum)/ig, "")),'10');
	flag.price=flag.price + price*quantity;		
	flag.quantity+=quantity;
	if (flag.price<0||'NaN'===price) flag.price=0;
	if (flag.quantity<0||'NaN'===quantity) flag.quantity= 0;
	jQuery('#bin_content_quantity').html(flag.quantity);
	jQuery('#bin_content_sum').html(flag.price);
	jQuery('.tovar_buy').html('<img class="but_green_ok" id="but_green_ok" src="i/but_green_ok.gif">').hide();
	jQuery('.tovar_buy').fadeIn('slow');
	setTimeout(function () { 		jQuery('.tovar_buy').fadeOut('slow'); }, 1000);
	setTimeout(function () { 		
		jQuery('.tovar_buy').html('<a class="but_after_add_to_cart" onclick="return false;" href="">Оформить заказ</a>').hide();
		jQuery('.tovar_buy').stop().fadeIn('slow');
	}, 1000);

	setTimeout(function () { 		
				jQuery(".but_after_add_to_cart").click(function(){
				flag['user_cart']= 'yes';
				basket_show();
				return false;
			});
	}, 2000);

}

function close_pop_products(value) {	
		var click_href_delete = jQuery(value).children().attr('href')+'&jquerystop';
		var id = jQuery(value).children().attr('id').replace(/-sum.*/ig, "");
		var prod_id = jQuery(value).children().attr('name').replace(/-id.*/ig, "");
		var prod_id2 = jQuery('#id_check').attr('value');
		jQuery('#bin_pop_'+id).slideUp();
		jQuery.get(click_href_delete, function(data){
		var quantity= parseInt(parseFloat(jQuery('#bin_pop_'+id+' select option:selected').html()),'10');
		flag.quantity=parseInt(parseFloat(jQuery('#bin_content_quantity').html()),'10');
		var price = parseInt(parseFloat(jQuery(value).children().attr('id').replace(/(.*sum)|(_-_.*)/ig, "")),'10');
		flag.price=flag.price - price*quantity;
		//if ('products_99'===id){
		if (prod_id2===prod_id){
			var price_vip = Math.round(price*0.2);
			price = Math.round(price*0.8);
			var vip_and_price = price + price_vip;
			var reg_check = document.getElementById('region_check').value;
			if (reg_check == 1)
			{
			jQuery('.tovar_buy').html(
				'<table cellpadding="0" cellspacing="0" border="0"><tr><td>'+
				'<input type="hidden" name="check_vip_hidd" value="'+price_vip+'">'+
				'<div id="vip_block1" class="vip">'+
				'<input id="check_vip_for_add" name="check_vip" class="usl_spb" type="checkbox" onClick="vip_price_show('+price+','+vip_and_price+'); show_point(\'pre_vip\');" value="'+prod_id+'"> <span id="vip_capt" onClick="vip_visibility(\'vip_block1\',\'vip_block2\',\'vip_block3\');" onMouseOver="vip_underline(\'vip_capt\');" onMouseOut="vip_underline(\'vip_capt\');" style="text-decoration:underline; cursor:pointer;">VIP – пакет</span>'+
           	'<span class="price_vip1" style="padding-left:70px;">'+price_vip+' руб.</span>'+
			'</div></td></tr><tr><td>'+
			'<div id="vip_block2" class="vip22" style="display:none;">'+
			'<div style="margin-left:30px; margin-right:5px;">'+
			'<ul>'+
				'<li>Возможна бесплатная доставка в день заказа</li>'+
				'<li onClick="show_point(\'point1\');" style="cursor:pointer;"><span style="border-bottom:dotted; border-bottom-width:1px;">Супер гарантия на 6 месяцев</span></li>'+
				'<div id="point1" style="margin-left:30px; margin-right:5px; display:none;">'+
				'Обмен неисправного товара в течение 2-х рабочих дней на такой же или аналогичный по стоимости или техническим характеристикам.'+
				'</div>'+
				'<li onClick="show_point(\'point2\');" style="cursor:pointer;"><span style="border-bottom:dotted; border-bottom-width:1px;">Сервис-центр не выходя из дома</span></li>'+
				'<div id="point2" style="margin-left:30px; margin-right:5px; display:none;">'+
				'Если товар, купленный у нас, ломается в течении всего гарантийного срока, то мы бесплатно забираем у Вас товар и отвозим его в сервис-центр, а после починки привозим его Вам обратно.'+
				'</div>'+
			'</ul>'+
			'</div></div></td></tr>'+
			'<tr><td>'+
			'<div id="vip_block3" class="vip23" style="display:none;">&nbsp;</div>'+
			'</td></tr>'+
			'</table>'+
			'<br>'+
				'<span class="red">Кол-во:</span>'+
				'<select id="cart_qty_for_add" name="cart_qty"><option value="1" selected="selected">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>'+
				'&nbsp;&nbsp;<span id="buy_submit_'+price+'"><input id="buy_submit-sum'+price+'" class="but_buy" type="submit" value="Купить"/></span>'+
				'<!--<br>prod_id '+prod_id+'<br>prod_id2 '+prod_id2+'<br>price '+price+'<br>vip_price '+price_vip+'<br>vip_and_price '+vip_and_price+'-->');
			}
			else
			{
				jQuery('.tovar_buy').html(
				'<span class="red">Кол-во:</span>'+
				'<select id="cart_qty_for_add" name="cart_qty"><option value="1" selected="selected">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>'+
				'&nbsp;&nbsp;<span id="buy_submit_'+price+'"><input id="buy_submit-sum'+price+'" class="but_buy" type="submit" value="Купить"/></span>');
			}
			jQuery("#buy_submit_"+price).click(function (){
				jQuery("#cart_empty_show").hide();
				submit_click(this);
				return false;
			});
		}
		if (flag.price<0||'NaN'===price) flag.price=0;
		flag.quantity-=quantity;
		if (flag.quantity<0||'NaN'===quantity) flag.quantity= 0;
		jQuery('#bin_content_quantity').html(flag.quantity);
		jQuery('#bin_content_sum').html(flag.price);
		if (flag.quantity=='0'){
				flag['user_cart']= 'no';
				jQuery("#cart_empty_show").show();
				jQuery(".but_oform").hide();
			//jQuery("#inner_popup").html('<span id="cart_empty" style="display:none;">Корзина пуста</span>');
		}
		},'html');
		return false;	
}
//</script>
