var containerWidth=0;
var containerHeight=0;
var totalPages=0;
var animationSpeed=400;


$(document).ready(function() {
  	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
/*
$('a.loadx').click(function(){
	var url=$(this).attr('href');
//	$('#loadx').load(url+"?ajax=true");
	window.location.href=url;
	return false;
});
*/
$('.lcol input').change(banzay);
$('.lcol select').change(banzay);
$('.select').change(banzay);
$('#search input').addClass('search').val('Поиск').bind('focus',function(){
	$(this).val('').removeClass('search').addClass('shover').unbind('focus').bind('keypress',function(e){
		var code=e.charCode.toString();
		console.log(code);
		if(code=='13'|| code=='0'){
			/*$.ajax({
   type: "POST",
   url: "/search/?aj=true",
   data: "&keyword="+encodeURIComponent($(this).val()),
   success: function(msg){
     $('#ajcont').html( msg );
   }
 });
			*/
			$('#ajcont').load('/search/?aj=true',{keyword:$(this).val()});
		
		}
	});
});
alignHight('.item .title a',3);
});

function banzay(){
	var chk=$('.lcol input:checked').get();
	var b=[];
	var p=[];
	var name,val;
	for(var i=0; i<chk.length; i++){
		name=$(chk[i]).attr('name');
		val=$(chk[i]).val();
		if(name.charAt(0)=='b') b.push(val);
		if(name.charAt(0)=='p') p.push(name+"="+val);
	}
	chk=$('.select select option:selected').get();
	for(var i=0; i<chk.length; i++){
		name=$(chk[i]).parent().attr('name');
		val=$(chk[i]).val();
		p.push(name+"="+val);
	}
		chk=$('.lcol select option:selected').get();
	for(var i=0; i<chk.length; i++){
		name=$(chk[i]).parent().attr('name');
		val=$(chk[i]).val();
		if(name.charAt(0)=='b') b.push(val);
		if(name.charAt(0)=='p') p.push(name+"="+val);
	}
	
	chk=window.location.href.replace(/\?.*/,'')+'?start='+ $( "#slider" ).slider( "values", 0 )+'&stop='+ $( "#slider" ).slider( "values", 1 )+'&brands='+b.join(',')+'&'+p.join('&');
	
	window.location.href=chk;
}

function clearfilter(){
	$('.lcol input:selected').attr('selected',false);
	$('.lcol input:checked').attr('checked',false);
	banzay();
}



function parentLocation(url){
	window.parent.location=url;		
}
function sel_color(obj){
    par=$(obj).val();
   
}

function buy(id){
$('#basket').load('/?action=buy&param='+encodeURIComponent(par)+'&tov_id='+id,{limit: 25}, function(){
    $.prettyPhoto.open('/basket/?act=list&target=1&iframe=true&width=800&height=600','','');
   // $('#ajcont').load('/basket/?act=checkout&target=1');
});
}
function checkout(){
	 $.prettyPhoto.open('/basket/?act=checkout&target=1&iframe=true&width=800&height=600','','');
	 //$('#ajcont').load('/basket/?act=checkout&target=1');
}
function fsubmit(act){
    $('#myBeg').attr('action','/basket/?act='+act);
    $('#myBeg').submit();
    
}

function pretty(url){
	 $.prettyPhoto.open(url,'','');
}
function update_basket(){

$('#basket').load('/?action=update_basket');
}
function clear_basket(){
   $('#basket').load('/?action=clear_basket',{limit: 25}, function(){
    $.prettyPhoto.close();
}); 
}
function CloseBasket(){
    $.prettyPhoto.close();
}
function ptetty(obj){
    var link=$(obj).attr('href');
     $.prettyPhoto.open(link,'','');
     return false;
}
function show_basket(){
    $.prettyPhoto.open('/basket/?iframe=true&width=800&height=600','','');
}
function fclear(obj){
	if($(obj).hasClass('hid')){
	$(obj).removeClass('hid');
	$(obj).val('');
	
	}
	

	
}
	function alignHight(obj,dx){
		var i=0;
		var elm=[];
		var maxh=0;
		$(obj).each(function(){
			elm.push(this);
			var h=parseInt($(this).height());
			maxh=(h>maxh ? h:maxh);
			i++;
			if(i==dx){
				i=0;
				$(elm).height(maxh);
				elm=[];
				maxh=0;
			}
		});
	}

