var GET = [];$(document).ready(function(){		
$("script[type*=javascript]").each(function() {		var reg = /[a-z]+\.js\?(.*=.*)$/ig;		var regp = /(.*)=(.*)/;		src_ = this.src;		if(p = reg.exec(src_)){			params = p[1]; paramList = params.split('&');			for(p=0;p<=paramList.length-1;p++){				param = regp.exec(paramList[p]);				GET[param[1]] = param[2];			}		}	});		

	$(".filter form a#price_submit").click(function(){

		obj = $(this);		
		price_form = obj.parent('div').parent('form');
		input_from = $('input#from');		
		input_forward = $('input#forward');
		if(input_from.val()=='') input_from.val(0);
		if(input_forward.val()=='') input_forward.val(0);
		regex = /^\d+$/;				
		if(!regex.test(input_from.val())){			input_from.addClass('error');			return false;		}
		else{			input_from.removeClass('error');		}				
		
		if(!regex.test(input_forward.val())){			input_forward.addClass('error');			return false;		}
		else{			input_forward.removeClass('error');		}				
		
		if(parseInt(input_forward.val()) < parseInt(input_from.val())){			alert("Начальная цена не может быть больше конечной");			return false;		}
		price_form.attr('action', 'limitprice.php').submit();	
	});	

	$(".filter form a#reload_submit").click(function(){
		obj = $(this);		price_form = obj.parent('div').parent('form');		
		$("#targetting").val("reload");			
		price_form.attr('action', 'limitprice.php').submit();	
		
	});	
	
	$("ul.catalog li").each(function(){
		
		$(this).find("span").click(function(){
			$(this).toggleClass("minus");
			$(this).next("a").next("ul").slideToggle();
		});
	});
	
	
	params = window.location.href.slice(window.location.href.indexOf('?') + 1);
	
	$.ajax({

		url:	'brands.php',
		type:	'POST',
		contentType: 'application/x-www-form-urlencoded', //Тип передаваемых данных
		data:	params,
		//переменные для отправки почты
		beforeSend: function(){
		
					
		},
		success: function(response){
				
			$("#brands-load").html(response);
				  
		},
		error: function(){
					
		}
			
	});
	
	
	params = window.location.href.slice(window.location.href.indexOf('?') + 1);
	
	global_brand = window.location.href.slice(window.location.href.indexOf('brand=') + 6);
	
	$.ajax({

		url:	'cbrands.php',
		type:	'POST',
		contentType: 'application/x-www-form-urlencoded', //Тип передаваемых данных
		data:	params,
		//переменные для отправки почты
		beforeSend: function(){
		
			$("ul.catalog li.active a").after('<span id="preloader" ><img src="images/evg/ajax-loader.gif" /> Загрузка брендов</span>');		
			
		},
		success: function(response){
			$("ul.catalog li.active a").next("span").remove();	
			$("ul.catalog li.active a").after(response);
			$("ul.catalog li.active ul li a").each(function(){
				href_ = $(this).attr("href");
				current_brand = href_.slice(href_.indexOf("brand=") + 6);
				if(current_brand == global_brand) $(this).parent("li").addClass("active");
			});
				  
		},
		error: function(){
			$("ul.catalog li.active a span").remove();		
		}
			
	});

});


$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


function absPosition(obj) {
       var x = y = 0;
       while(obj) { 
	   x += obj.offsetLeft;
	   y += obj.offsetTop; 
	   obj = obj.offsetParent;
       }
       return {x:x, y:y};
}

function show_sub(smb){	
	d= document;
	elpos= absPosition(d.getElementById(smb));
	x= elpos.x+60;	y= elpos.y+60;
	d.getElementById('i_subcat_'+smb).style.visibility='visible';
	d.getElementById('i_subcat_'+smb).style.top=  y+'px';
	d.getElementById('i_subcat_'+smb).style.left=  x+'px';
}

function show_sub2(smb) {

	document.getElementById('i_subcat_'+smb).style.visibility='visible';
}

function hide_sub(smb) {

	document.getElementById('i_subcat_'+smb).style.visibility='hidden';
}

function home_divs_positioning () {
	homedivs= new Array('kolyaski', 'igrushki', 'mebel', 'avtokresla', 'bezopasnost', 'kormlenie', 'gigiena');
	arrpos= new Array(40, -40, 380, -30, 210, 120, 20, 210, 420, 210, 100, 400, 360, 400);
	poshome= absPosition(document.getElementById('home_menu'));	
	for (k=0; k<7; k++) {
		document.getElementById( homedivs[k] ).style.left= poshome.x+arrpos[k*2]+'px';
		document.getElementById( homedivs[k] ).style.top= poshome.y+arrpos[k*2+1]+'px';
		poselem= absPosition(document.getElementById( homedivs[k] ));	
	}
}
