$(document).ready(function(){
	var lact = function(){
		var lacth = $('.wrapper').innerHeight();
		$('.lactive').css({'height' : lacth +'px'});
	};
	$('.lactive').click(function(){
		$(this).hide();
		$('.login-form').hide();
	});
	$(".i-sorting .itabs").tabs(".i-sorting > div.panes > div.pane");
	var api = $(".i-sorting .itabs").tabs(".i-sorting > div.panes > div.pane"); 
	api.next(); 
	$(".text .itabs").tabs(".text > div.panes > div.pane");
	var api = $(".text .itabs").tabs(".text > div.panes > div.pane"); 
	api.next(); 
	$(".goods .itabs").tabs(".goods > div.panes > div.pane");
	var api = $(".goods .itabs").tabs(".goods > div.panes > div.pane"); 
	api.next(); 
	$(".product-n .itabs").tabs(".product-n > div.panes > div.pane"); 
	var api = $(".product-n .itabs").tabs(".product-n > div.panes > div.pane"); 
	api.next(); 
	
	$('.itabs li a').click(function(){
		$(this).parent().parent().find('li').removeClass('active');
		$(this).parent().addClass('active');
		return false;
	});
	
	$('.tabs .more > a').click(function(){
		$('.submenu').toggle();
		return false;
	});
	$('.tabs >ul a').click(function(){$('.submenu').hide();});
	$('.b-inner').click(function(){$('.submenu').hide();});
	$('.login form .remember').click(function(){
		$(this).find('.check').toggleClass('checked');
		return false;
	});
	$('.login .login-link a').click(function(){
		$('.login-form').toggle();
		$('.lactive').toggle();
		lact();
	});
	
	$(document).not('div.select').click(function(){
		$('.select ul').hide();
		$('.select').removeClass('active-block');
	});
	$('.foption div a, .soption div a, .numbers div a').click(function(){
	if ($(this).parent().parent().hasClass('active-block')) {
		$('.select ul').show();
		$('.select').removeClass('active-block');
	} else {
		$('.foption ul, .soption ul, .numbers ul').hide();
		$(this).parent().parent().children('ul').show();
		$(this).parent().parent().addClass('active-block');
		return false
		}
	});
	$('.foption li a, .soption li a, .numbers li a').click(function(){
		fs = $(this).text();
		$(this).parent().parent().parent().children().children('a').text(fs);
		$('.foption ul li, .soption ul li, .numbers ul li').removeClass('active');
		$(this).parent().addClass('active');
		ss = $('.foption ul .active, .soption ul .active, .numbers ul .active').prevAll().size();
		$(this).parent().parent().parent().children().children('select').children('option:eq('+ss+')').attr('selected','selected');
		$('.foption ul, .soption ul, .numbers ul').hide();
		$('.foption, .soption, .numbers').removeClass('active-block');
		return false
	});
	$('.gallery .images li a').click(function(){
		/*var img = $(this).find('img').attr('alt');
		$('.gallery .image').find('img').attr({'src':'./pic/' +img+ '.jpg'});*/
		return false;
	});

});






function add_note(){	
	hr='';
	mode='N';
	for(i=0;i<note_row.length;i++){
		if(eval("document.all['ch_"+note_row[i]+"'].checked==true")){
			hr+='note_id['+i+']='+note_row[i]+'&';	
			mode='Y';
		}	
	}
	if(mode=='Y')
		window.open("/note.php?"+hr+"","note","top=50,left=50,directories=no,height=400,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width=500");	
	return false;
}

function check_note(){
	if(document.all["note_num"].innerText=='0')
		return false;
	else	
		window.open("","note","top=50,left=50,directories=no,height=400,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width=500");
}
function open_note(){
	window.open("","note","top=50,left=50,directories=no,height=400,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width=500");
}

function randomNumber (m,n)
{
  m = parseInt(m);
  n = parseInt(n);
  return Math.floor( Math.random() * (n - m + 1) ) + m;
}



function add_basket(id)
{

	var imageElement = document.getElementById('prod_img');
	
	bsk_size=0;
	if($('select#bsk_size'))
		bsk_size=$('select#bsk_size').attr('value');
	//alert(bsk_size);	
	//return false;	
	$.getJSON(
		"/add_bsk.php?b_id="+id+"&bsk_size="+bsk_size,
		$.proxy(
			function(data) {
		
				if (imageElement)
				{
					var imageToFly = $(imageElement);
					var position = imageToFly.position();
					var flyImage = imageToFly.clone().insertBefore(imageToFly);
				
					//imageToFly.hide();
					flyImage.css({ "position": "absolute", "left": position.left, "top": position.top, "z-index": 10 });
					//flyImage.animate({ width: 0, height: 0, left: 900, top: -358 }, 2000, 'linear');
					flyImage.animate({ width: 0, height: 0, left: 150, top: 150 }, 3000, 'linear');
					
					//$(imageElement).show();
				}
	
				
				
				
				
				//alert(data.count);
				
				if($('#add_link').length)
					$('#add_link').text('В корзине');
				
				if($('#cat_prod_buy_'+id).length)
					$('#cat_prod_buy_'+id).text('В корзине');
				
				if($('#new_prod_buy_'+id).length)
					$('#new_prod_buy_'+id).text('В корзине');
				
				
				if(data.count=='0')
					$('#top_basket').html('Корзина пуста<br><a href="/cont/help.html">как сделать заказ</a><br>');
				else
					$('#top_basket').html('Товаров в корзине '+data.count+' на сумму<br> '+data.sum+' руб. <a href="/basket.php" title="Оформить заказ">Оформить заказ</a> ');
				
				
				
				// popup корзины				
				$('.lactive2').show();
				var lacth_bsk = $('.wrapper').innerHeight();
				$('.lactive2').css({'height' : lacth_bsk +'px'});
								
				$('#start').center().show();
				
				
				$('#link-select-prod').click(function(){
					$('#start').hide();
					$('.lactive2').hide();
					return false;
				});
				
				
			}
		)
	);
	
	
	
	return false;

}




jQuery.fn.center = function() 
	{
	var w = $(window);	
	this.css("position","absolute");
	this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
	this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
	return this;
	}

