$(window).load(function () {
	//$('#brownshow').click();
	}); 

var flag=1;
var mode_searh='noext';

function body__(span)
{
	$('#sbody').attr('disabled','disabled');
	$('#type_cap').html($(span).html());
	
	$('#hbody').attr('value',$(span).attr('id').substr(4));
}

function probeg(val)
{
	form_clear();
	$('#sbody').removeAttr('disabled');
	$('#hprivod').attr('value',val);
	change_tt(23,'type'); 
	$('#searh_baton').trigger('click',['Click','Event']);
}			

function salez(){
	pathname = window.location.pathname;
	//alert(pathname);
	if (pathname=='/main' || pathname=='/main/' || pathname== '/' || pathname=='') {showhide('sale','buy');}
	else window.location.href="/main?opensale";
}

function page_x(x) //абсолютный переход страницы
{
	if (CheckForm(this.form,1,6)){
 		find_ie=document.getElementById("modefind").value;
 		body=document.getElementById("hbody").value;
 		rul=document.getElementById("hrul").value;
 		box=document.getElementById("hbox").value;
 		privod=document.getElementById("hprivod").value;
 		place=document.getElementById("hplace").value;
 		color=document.getElementById("hcolor").value;
 		any_ie=document.getElementById("hany").value;
 		city=document.getElementById("hcity").value;
 		type_=document.getElementById("htype").value;
 		mmetalic=document.getElementById("hmetalic").value;
 		marka=document.getElementById("1").value;
 		model=document.getElementById("2").value;
 		cash_b=document.getElementById("3").value;
 		cash_e=document.getElementById("4").value;
 		age_b=document.getElementById("5").value;
 		age_e=document.getElementById("6").value;
 		cdesc=document.getElementById("hdesccash").value;
 		ydesc=document.getElementById("hdescyear").value;
 		
 		var page_link = $("#hlink").attr('value');
 		//var page_link = document.getElementById("hlink").value;

 		
    	if (page_link=='0'){$('#sr').load('/ajax/results_redirect.php?start='+(x.innerHTML-1)+'&city='+city+'&type='+type_+'&mode=0&find='+find_ie+'&body='+body+'&rul='+rul+'&box='+box+'&privod='+privod+'&place='+place+'&color='+color+'&any='+any_ie+'&metalic='+mmetalic+'&marka='+marka+'&model='+model+'&cash_b='+cash_b+'&cash_e='+cash_e+'&age_b='+age_b+'&age_e='+age_e+'&cdesc='+cdesc+'&ydesc='+ydesc);}
    	else {$('#sr').load('/ajax/results_redirect.php?start='+(x.innerHTML-1)+page_link+'&ydesc='+ydesc+'&cdesc='+cdesc);}
	  	
	}
	
	}

function page_i(x) //относительный переход страницы
{	if (x<=0) x=1;
	if (CheckForm(this.form,1,6)){
		find_ie=document.getElementById("modefind").value;
 		body_ie=document.getElementById("hbody").value;
 		rul=document.getElementById("hrul").value;
 		box=document.getElementById("hbox").value;
 		privod=document.getElementById("hprivod").value;
 		place=document.getElementById("hplace").value;
 		color=document.getElementById("hcolor").value;
 		any_ie=document.getElementById("hany").value;
 		city=document.getElementById("hcity").value;
 		type=document.getElementById("htype").value;
 		metalic_ie=document.getElementById("hmetalic").value;
 		marka=document.getElementById("1").value;
 		model=document.getElementById("2").value;
 		cash_b=document.getElementById("3").value; 
 		cash_e=document.getElementById("4").value;
 		age_b=document.getElementById("5").value;
 		age_e=document.getElementById("6").value;
 		cdesc=document.getElementById("hdesccash").value;
 		ydesc=document.getElementById("hdescyear").value;
 		
 		var page_link = $("#hlink").attr('value');
 		
    	if (page_link=='0'){$('#sr').load('/ajax/results_redirect.php?start='+(x-1)+'&city='+city+'&type='+type+'&mode=0&find='+find_ie+'&body='+body_ie+'&rul='+rul+'&box='+box+'&privod='+privod+'&place='+place+'&color='+color+'&any='+any_ie+'&metalic='+metalic_ie+'&marka='+marka+'&model='+model+'&cash_b='+cash_b+'&cash_e='+cash_e+'&age_b='+age_b+'&age_e='+age_e+'&cdesc='+cdesc+'&ydesc='+ydesc);}
    	else {$('#sr').load('/ajax/results_redirect.php?start='+(x-1)+page_link+'&ydesc='+ydesc+'&cdesc='+cdesc);}
	}
	
	}

function tovar(ono) //грузим машинку
{	
	$('#sr').hide();
	$('#sr2').load('/ajax/tovar.php?id='+ono.id.substring(1, ono.id.length));       
    $('#sr2').delay(500).show();
}


function change_pic(small_pic) //грузим машинку
{	var block = $('#'+small_pic);
	$('.to_hide').animate({opacity: "hide"}, 500);
	block.delay(500).animate({opacity: "show"}, 250);
	
}

function change_ok(id,flag) //ставим,убираем галоку
{	if (flag.value=='0'){
		flag.value='1';
		$("#"+id).css('background-image',"url('../img/ok.png')");
		$(".colours").css('width','15px');
		$(".colours").css('height','15px');
		$(".colours").css('margin-top','0px');
		$(".colours").css('border','0px');
	}
			
	
	else	{
		flag.value='0';
		$("#"+id).css('background-image',"url('../img/no_ok.png')");
		$(".colours").css('width','15px');
		$(".colours").css('height','15px');
		$(".colours").css('margin-top','0px');
		$(".colours").css('border','0px');
	}
}

function change_ok_any(id,flag) //ставим,убираем галоку
{	if (flag.value=='0'){
		flag.value='1';
		$("#"+id).css('background-image',"url('../img/ok.png')");
		$(".colours").css('width','15px');
		$(".colours").css('height','15px');
		$(".colours").css('margin-top','0px');
		$(".colours").css('border','0px');
	}
			
	
	else	{
		flag.value='1';
		$("#"+id).css('background-image',"url('../img/ok.png')");
		$(".colours").css('width','15px');
		$(".colours").css('height','15px');
		$(".colours").css('margin-top','0px');
		$(".colours").css('border','0px');
	}
}

function choose_color(color,iam) //выбираем цвет
{
document.getElementById('hcolor').value=color;

document.getElementById('hany').value='0';
$("#any").css('background-image',"url('../img/no_ok.png')");

$(".colours").css('width','15px');
$(".colours").css('height','15px');
$(".colours").css('margin-top','0px');
$(".colours").css('border','0px');

iam.style.width="16px";
iam.style.height='16px';
iam.style.marginTop='-3px';
iam.style.marginBottom='3px';
iam.style.border='1px solid';
}



function hidesearh(x) //прячемся (доп.поиск)
{	$("#slider,#slider2").animate({ 
	opacity: "hide",
		height:"hide"
				}, x*1.5);
	
	$("#buyext").animate({ 
	    	  opacity: "hide"
	          }, x); 
	$("#exsea").delay(4.6*x).animate({ 
      	  opacity: "show"
            }, x);               
  	
    $("#hidesea").animate({ 
    	  opacity: "hide"         
          }, x);
        
	      $("#buy_sale").delay(x).animate({ 
		        width: "520px",
		        	height: "380px"
		      }, x*1.4);
	      
	      $("#spaceban").animate({ 
		        height: "32px"
	      }, 0.1*x);
	      
	      $("#stat_hide").animate({ 
	    	  opacity: "show"
	          }, 2*x); 
	      
	      
	      
	      $("#brownhide").delay(x*4).animate({ opacity: "hide"}, 0); 
	      if (flag!=3) {$("#brownshow").delay(x*4).animate({ opacity: "show"}, 0);}
	      flag=1;

	      
}

function showsearh(x) //вылазием(доп.поиск)
{		  	
			
	
			$("#slider,#slider2").delay(x*2).animate({ 
	  			opacity: "show",
	  			height:"show"
			}, x*1.5);
	      
			$("#hidesea").delay(4*x).animate({ 
	        	  opacity: "show",
	        	  height:"show"
	              }, x); 
	      
	      $("#buyext").delay(3*x).animate({ 
	    	  opacity: "show"
	          }, x); 
	    	
	      $("#exsea").animate({ 
	      	  opacity: "hide"         
	            }, x);              
		    
	      
	      
	      $("#stat_hide").delay(2*x).animate({ 
	    	  opacity: "hide"
	          }, x*2);	      
	    	
	      $("#buy_sale").delay(x).animate({ 
	        width: "750px",height: "450px"
	      }, x*2);  
	      
	             
	      $("#brownshow").delay(x*4).animate({ opacity: "hide"}, 0); 
	      $("#brownhide").delay(x*4).animate({ opacity: "show"}, 0);
	      flag=2;
	      
	      $("#spaceban").delay(4*x).animate({ 
		        height: "500px"
	      }, 0.1*x);
	      
}


function	form_clear() //чистим форму
	{
		//alert($('#hplace').attr('value'));
	
		$('#hprivod').attr('value','all');
		
		temptype=$('#htype').attr('value');
		tempcity=$('#hcity').attr('value');
		
		
		
		document.forms.sale.reset();
		document.forms.buy.reset();
		document.forms.ext.reset();
		
		$(".colours").css('width','15px');
		$(".colours").css('height','15px');
		$(".colours").css('margin-top','0px');
		$(".colours").css('border','0px');
		
		$("#metalic").css('background-image',"url('../img/no_ok.png')");
		$("#any").css('background-image',"url('../img/ok.png')");
		
		document.getElementById('hany').value='1';
		document.getElementById('hmetalic').value='0';
		
		$('#htype').attr('value',temptype);
		$('#hcity').attr('value',tempcity);	
		
		$('#hplace').attr('value',$('#splace').attr('value'));
		$('#hbox').attr('value',$('#sbox').attr('value'));
		
		
		if ($('#htype').attr('value')!=81 && $('#htype').attr('value')!=82)
		{
		$('#sbody').removeAttr('disabled');
		$('#hbody').attr('value',$('#sbody').attr('value'));
		}
		
	}

function showhide(show,hide){ //переключалка слоев
	if (flag==2) {	flag=3;
					hidesearh(300);
					//$("#brownshow").delay(x*4).animate({ opacity: "hide"}, 0); 
					//$("#brownhide").delay(x*4).animate({ opacity: "hide"}, 0);
					}
	
	$("#"+show).delay(500).animate({opacity: "show"}, 250); 
	$("#"+hide).animate({opacity: "hide"}, 500);
	
	
	if (show=="sale") {
		
		document.getElementById("brownhide").style.display = 'none';
		document.getElementById("brownshow").style.display = 'none';
		document.getElementById("hidesea").style.display = 'none';
		document.getElementById("buy_sale_head").style.background = "url('../img/block2.png') no-repeat left top"; 
		document.getElementById("cap_buy").style.color = "#0071a1";
		document.getElementById("cap_sale").style.color = "#636e6e";
		document.getElementById("cap_sale").style.border = "0px";
		document.getElementById("cap_buy").style.borderBottom = "1px dashed";
		$("#buy_sale").animate({ height: "500px" }, 250); 
		
			
		      }
	
	else { 
		document.getElementById("cap_sale").style.color = "#0071a1";
		document.getElementById("brownshow").style.display = 'block';
		document.getElementById("cap_sale").style.borderBottom = "1px dashed";
		document.getElementById("cap_buy").style.color = "#636e6e";
		document.getElementById("cap_buy").style.border = "0px";
		document.getElementById("buy_sale_head").style.background = "url('../img/block.png') no-repeat left top"; 
		$("#buy_sale").animate({  height: "400px"}, 250);  
		
	}
		
	
		
	
	}



function validate() {
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = document.forms.sale.mail.value;
	   if(reg.test(address) == false) {
	      alert('Некорректно введённый e-mail');
	      $('#f10').css('borderColor','#e0a6be');
	      return false;
	   }
	   else{
		   $('#f10').css('borderColor','#ebebeb');
	   }
	}



function sendsale(){
    var return_value = true;  
    
    
    
    $('form[name=sale] input').each(function(){ if ($(this).attr('value')==""){
    														$(this).css('borderColor','#e0a6be');
    														return_value=false;
    														}
    											else $(this).css('borderColor','#ebebeb');
    													});
   
    if (return_value==false) alert("Все поля должны быть заполнены!");
    
    if (validate()==false) return_value=false;
    
    return return_value;
}

function CheckForm(form,f,l){
    var return_value = true;        
    
  /*  $('form[name=buy] input').each(function(){ if ($(this).attr('value')==""){
    														$(this).css('borderColor','#e0a6be');
    														return_value=false;
    														}
    											else if($(this).attr('type')!="button") $(this).css('borderColor','#ebebeb');
    													});
    for (var i=f;i<=l;i++)
    	if (document.getElementById(i).value=="") {
    							document.getElementById(i).style.borderColor='#e0a6be';
    							return_value=false;
    							}
    	else document.getElementById(i).style.borderColor='#ebebeb';*/
    
    if (return_value==false) alert("Все поля должны быть заполнены!"); 
    
    else document.getElementById("modefind").value=flag;
    //alert(flag);
    return return_value;
}


function change_slider(ui,slider,input1,input2,m,s)
{
	$("#"+slider+" div:first").css('background-position','-'+$("#"+slider+" div:first").css('left')+' 0px');
	document.getElementById(input1).value=s+ui.values[0]*m;
	document.getElementById(input2).value=s+ui.values[1]*m;
}



function change_tt(id,parent){ 

	$('#cluetip').hide();
	$('#blocklayer').animate({width:"hide"},700);


	
	//$('#'+parent+'_tool').load('/ajax/'+parent+'.php?'+parent+'='+id);
	
	document.getElementById('h'+parent).value=id;

	if($('#hprivod').attr('value')=='new' && parent=='type') $('#type_cap').html('Новые легковые автомобили');
	else
	if($('#hprivod').attr('value')=='old' && parent=='type') $('#type_cap').html('Легковые автомобили с пробегом');
	else if ((parent=='type' && id!=81 && id!=82) || parent=='city') $('#'+parent+'_cap').load('/ajax/'+parent+'.php?one='+id);
	
	if (parent=='type') {
						$('#1').load('/ajax/select.php?type=mark&type_id='+id);
						
						//$('#2').load('/ajax/select.php?type=modelfromtype&type_id='+id);
						$('#sbody').load('/ajax/select.php?type=body&type_id='+id);
						$('#hbody').attr('value',$('#sbody').attr('value'));
						
						}
	/*$('#searh_baton').trigger('click',['Click','Event']);*/

}

function cashx()//инвертируем цену поиске
		{
		$('#hdescyear').attr('value','0');
		val=$('#hdesccash');
		startnow=$('#startnow').attr('value');
		startnow++;
		$('#startnow').after('<span id="mysend">'+startnow+'</span>');
		
		if (val.attr('value')=='0') {
									val.attr('value','1');
									page_x(document.getElementById('mysend'));
									
									}
		
		else {
			val.attr('value','0');
			page_x(document.getElementById('mysend'));
			
			}
		
		$('#mysend').remove();
		}
function yearx() //инвертируем год при поиске
{	$('#hdesccash').attr('value','0');
	val=$('#hdescyear');
	startnow=$('#startnow').attr('value');
	startnow++;
	$('#startnow').after('<span id="mysend">'+startnow+'</span>');
	
	if (val.attr('value')=='0') val.attr('value','1');
	else val.attr('value','0');
	
	page_x(document.getElementById('mysend'));
	$('#mysend').remove();
	
	}		

 	//jquery

$(document).ready(function(){
	/*$('option[name=marka]').click(function(){
						alert($(this).attr('value'));
						 					
	});
	$('option[value=1]').click(function(){
						alert($(this).attr('value'));
	});*/
	change_tt(23,'type');
	change_tt(999,'city');
	if (getopen=='ok')showhide('sale','buy');
	
	flag=2;
	
	//выпадашки
	/*
	$("span.bluel a").css('color','#0A76A4')
	
	
	div_type="<div  class='tooltip_'> <div id='type_tool' class='tooltip_body'> </div></div>";
	$('#type_tt').simpletip({content: div_type});
	
	div_city="<div  class='tooltip_'><div id='city_tool' class='tooltip_body'></div></div>";
    $('#city_tt').simpletip({content: div_city});
    
    
	
	$('#type_tool').load('/ajax/type.php?type=23');
	$('#city_tool').load('/ajax/city.php?city=999');
	 */
	
	
	
	//разворачиваемся
	$("#exsea,#brownshow").click(function(){
		showsearh(300);
	 });
	
	//сворачиваемся
	$("#hidesea,#brownhide").click(function(){
		hidesearh(300);
		
	});
	
	
	
	//грузим select модель.
		  $('#1').click(function(){
		  	idmark=document.getElementById("1").value;
	        $('#ajaxmodel').load('/ajax/select.php?type=model&mark='+idmark+"&m=1");       
	    }) 
	
	  //грузим select модель2.
		  $('#f12').click(function(){
		  	idmark=document.getElementById("f12").value;
	        $('#ajaxmodel2').load('/ajax/select.php?type=model&mark='+idmark+"&m=2");       
	    }); 


	 //ищем
	 $('#searh_baton').click(function(){
		 		fff=CheckForm(this.form,1,6)
		 		if (fff){
		 			find1=$("#modefind").attr('value');
		 	 		body=$("#hbody").attr('value');
		 	 		rul=$("#hrul").attr('value');
		 	 		box=$("#hbox").attr('value');
		 	 		privod=$("#hprivod").attr('value');
		 	 		place=$("#hplace").attr('value');
		 	 		color=$("#hcolor").attr('value');
		 	 		any1=$("#hany").attr('value');
		 	 		city=$("#hcity").attr('value');
		 	 		type_=$("#htype").attr('value');
		 	 		metalic1=$("#hmetalic").attr('value');
		 	 		marka=$("#1").attr('value');
		 	 		model=$("#2").attr('value');
		 	 		cash_b=$("#3").attr('value');
		 	 		cash_e=$("#4").attr('value');
		 	 		age_b=$("#5").attr('value');
		 	 		age_e=$("#6").attr('value');
		 	 		ydesc=$("#hdescyear").attr('value');
		 	 		cdesc=$("#hdesccash").attr('value');
		 	 		//this.redirect('#/123');
		 	 		$('#hlink').val('&city='+city+'&type='+type_+'&mode=1&find='+find1+'&body='+body+'&rul='+rul+'&box='+box+'&privod='+privod+'&place='+place+'&color='+color+'&any='+any1+'&metalic='+metalic1+'&marka='+marka+'&model='+model+'&cash_b='+cash_b+'&cash_e='+cash_e+'&age_b='+age_b+'&age_e='+age_e);
			  	$('#sr').load('/ajax/results_redirect.php?start=0'+'&city='+city+'&type='+type_+'&mode=1&find='+find1+'&body='+body+'&rul='+rul+'&box='+box+'&privod='+privod+'&place='+place+'&color='+color+'&any='+any1+'&metalic='+metalic1+'&marka='+marka+'&model='+model+'&cash_b='+cash_b+'&cash_e='+cash_e+'&age_b='+age_b+'&age_e='+age_e+'&ydesc='+ydesc+'&cdesc='+cdesc+'&ololo='+Math.floor( Math.random( ) * (100+1) ));
			  	//$('#sbody').attr('value',$('#hplace').attr('value'));
		 		}
		 		
		    })    

	//создаем и настраиваем slider    
	$(function(){
		$("#slider").slider({
				    min: 0,
				    max: 49,
				    step:1,
				    range:true,
				    animate:false,
				    values: [20,30],
				    slide:function(event,ui) {change_slider(ui,"slider","3","4",50000,0) ;},
					stop: function(event,ui) {change_slider(ui,"slider","3","4",50000,0) ;},						
					start: function(event,ui){change_slider(ui,"slider","3","4",50000,0 );}
				  });
		
		$("#slider2").slider({
		    min: 1,
		    max: 50,
		    step:1,
		    range:true,
		    animate:false,
		    values: [20,30],
		    slide:function(event,ui) {change_slider(ui,"slider2","5","6",1,1960) ;},
			stop: function(event,ui) {change_slider(ui,"slider2","5","6",1,1960) ;},						
			start: function(event,ui){change_slider(ui,"slider2","5","6",1,1960);}
		  });
		
		
	
		$("#slider a:first").html("<img src='/img/leftb.png' align='left'>");
		$("#slider a:last").html("<img src='/img/rightb.png' align='right'>");
		$("#slider a:first").css('margin-left',"-9px");
		$("#slider a:last").css('margin-left',"-12px");
		  
		
		
		  
		$("#slider2 a:first").html("<img src='/img/leftb.png' align='left'>");
		$("#slider2 a:last").html("<img src='/img/rightb.png' align='right'>");
		$("#slider2 a:first").css('margin-left',"-9px");
		$("#slider2 a:last").css('margin-left',"-12px");
		  		
		    		});
		
		    
});

(function($) {
	  var app = jQuery.sammy('#sr', function() {
	    this.debug = true;
	    var form_fields = null;
	    this.get('/', function() {
	      this.redirect('#/search');
	      this.app.swap('');
	    });

	    this.get('main/', function() {
	      this.redirect('#/');
	    });
	    
	    this.get('#/form', function() {
	    var elem = $('a.get_tov').get(0);
	    var curid = $('a.get_tov').attr('id');
	    var curidn = curid.replace('i', '');
	 //   var currentId = $(this).attr('id');
	      this.partial('/ajax/tovar.php?id=35873');
	      alert(elem);
	      alert(curidn);
	    });
	    
	    this.get('#/detailed/:some1/:id/', function() {
	        var list = this.params['id']; 
	        var get_id = list.split('_');
	        $('#main_div').remove();
	          this.partial('/ajax/tovar.php?id='+get_id[get_id.length - 1]);
	        });
	    
	    this.get('#/link/:id', function() {
	        var list = this.params['id']; 
	        $('#main_div').remove();
	          this.partial('/ajax/tovar.php?id='+list);
	        });
	    
	    this.post('#/pretend/post/url', function() {
	      form_fields = this.params;
	      this.log($.param(form_fields.toHash()));
	      this.redirect('#/123');
	    });
	    
	    this.get('#/display', function() {
	      if (form_fields) {
	        this.app.swap(form_fields.toHTML());
	      } else {
	        this.redirect('#/form')
	      }
	    });
	    this.get('#/search', function() {
	    	//alert('juf');
	    	this.partial('/ajax/results.php?start=0'+'&city='+city+'&type='+type_+'&mode=1&find='+find1+'&body='+body+'&rul='+rul+'&box='+box+'&privod='+privod+'&place='+place+'&color='+color+'&any='+any1+'&metalic='+metalic1+'&marka='+marka+'&model='+model+'&cash_b='+cash_b+'&cash_e='+cash_e+'&age_b='+age_b+'&age_e='+age_e+'&ydesc='+ydesc+'&cdesc='+cdesc);
	      });
	    
	    this.get('#/search/:start/:city/:type/:mode/:find/:body/:rul/:box/:privod/:place/:color/:any/:metalic/:marka/:model/:cash_b/:cash_e/:age_b/:age_e/:ydesc/:cdesc/:mrand', function() {
	    	$('#main_div').remove();
	    	var s_start = this.params['start'];
	    	var s_city = this.params['city'];
	    	var s_type = this.params['type'];
	    	var s_mode = this.params['mode'];
	    	var s_find = this.params['find'];
	    	var s_body = this.params['body'];
	    	var s_rul = this.params['rul'];
	    	var s_box = this.params['box'];
	    	var s_privod = this.params['privod'];
	    	var s_place = this.params['place'];
	    	var s_color = this.params['color'];
	    	var s_any = this.params['any'];
	    	var s_metalic = this.params['metalic'];
	    	var s_marka = this.params['marka'];
	    	var s_model = this.params['model'];
	    	var s_cash_b = this.params['cash_b'];
	    	var s_cash_e = this.params['cash_e'];
	    	var s_age_b = this.params['age_b'];
	    	var s_age_e = this.params['age_e'];
	    	var s_ydesc = this.params['ydesc'];
	    	var s_cdesc = this.params['cdesc'];
	    	
	    	var s_link = $("#hlink").attr('value');
	    	if (s_link=='0'){$('#hlink').val('&city='+s_city+'&type='+s_type+'&mode='+s_mode+'&find='+s_find+'&body='+s_body+'&rul='+s_rul+'&box='+s_box+'&privod='+s_privod+'&place='+s_place+'&color='+s_color+'&any='+s_any+'&metalic='+s_metalic+'&marka='+s_marka+'&model='+s_model+'&cash_b='+s_cash_b+'&cash_e='+s_cash_e+'&age_b='+s_age_b+'&age_e='+s_age_e+'&ydesc='+s_ydesc+'&cdesc='+s_cdesc);}
	    	
	    	//this.partial('/ajax/results.php?start='+s_start+'&city='+s_city+'&type='+s_type+'&mode=1&find='+s_find+'&body='+s_body+'&rul='+s_rul+'&box='+s_box+'&privod='+s_privod+'&place='+s_place+'&color='+s_color+'&any='+s_any+'&metalic='+s_metalic+'&marka='+s_marka+'&model='+s_model+'&cash_b='+s_cash_b+'&cash_e='+s_cash_e+'&age_b='+s_age_b+'&age_e='+s_age_e);
	    	this.partial('/ajax/results.php?start='+s_start+'&city='+s_city+'&type='+s_type+'&mode='+s_mode+'&find='+s_find+'&body='+s_body+'&rul='+s_rul+'&box='+s_box+'&privod='+s_privod+'&place='+s_place+'&color='+s_color+'&any='+s_any+'&metalic='+s_metalic+'&marka='+s_marka+'&model='+s_model+'&cash_b='+s_cash_b+'&cash_e='+s_cash_e+'&age_b='+s_age_b+'&age_e='+s_age_e+'&ydesc='+s_ydesc+'&cdesc='+s_cdesc);

	    	//change_tt(''+s_type+'','type');
	    	//change_tt(''+s_city+'','city');
	    	$('#city_tool').load('/ajax/city.php?city='+s_city+'');
	    	
	      });

	  });

	  $(function() {
	    app.run();
	  }); 
	  
	  
	  
	  
	  
	  
	  
	  
	  
/*
(function($) {
  var app = jQuery.sammy('#sr', function() {
    this.debug = true;
    var form_fields = null;
    this.get('/', function() {
      this.redirect('#/search');
      this.app.swap('');
    });

    this.get('main/', function() {
      this.redirect('#/');
    });
    
    this.get('#/form', function() {
    var elem = $('a.get_tov').get(0);
    var curid = $('a.get_tov').attr('id');
    var curidn = curid.replace('i', '');
 //   var currentId = $(this).attr('id');
      this.partial('/ajax/tovar.php?id=35873');
      alert(elem);
      alert(curidn);
    });
    this.get('#/link/:id', function() {
        var list = this.params['id']; 
        $('#main_div').remove();
          this.partial('/ajax/tovar.php?id='+list);
   //       alert(list);
        });
    
    this.post('#/pretend/post/url', function() {
      form_fields = this.params;
      this.log($.param(form_fields.toHash()));
      this.redirect('#/123');
    });
    
    this.get('#/display', function() {
      if (form_fields) {
        this.app.swap(form_fields.toHTML());
      } else {
        this.redirect('#/form')
      }
    });
    this.get('#/search', function() {
    	//alert('juf');
    	this.partial('/ajax/results.php?start=0'+'&city='+city+'&type='+type_+'&mode=1&find='+find1+'&body='+body+'&rul='+rul+'&box='+box+'&privod='+privod+'&place='+place+'&color='+color+'&any='+any1+'&metalic='+metalic1+'&marka='+marka+'&model='+model+'&cash_b='+cash_b+'&cash_e='+cash_e+'&age_b='+age_b+'&age_e='+age_e+'&ydesc='+ydesc+'&cdesc='+cdesc);
      });
    
    this.get('#/search/:start/:city/:type/:mode/:find/:body/:rul/:box/:privod/:place/:color/:any/:metalic/:marka/:model/:cash_b/:cash_e/:age_b/:age_e/:ydesc/:cdesc/:mrand', function() {
    	$('#main_div').remove();
    	var s_start = this.params['start'];
    	var s_city = this.params['city'];
    	var s_type = this.params['type'];
    	var s_mode = this.params['mode'];
    	var s_find = this.params['find'];
    	var s_body = this.params['body'];
    	var s_rul = this.params['rul'];
    	var s_box = this.params['box'];
    	var s_privod = this.params['privod'];
    	var s_place = this.params['place'];
    	var s_color = this.params['color'];
    	var s_any = this.params['any'];
    	var s_metalic = this.params['metalic'];
    	var s_marka = this.params['marka'];
    	var s_model = this.params['model'];
    	var s_cash_b = this.params['cash_b'];
    	var s_cash_e = this.params['cash_e'];
    	var s_age_b = this.params['age_b'];
    	var s_age_e = this.params['age_e'];
    	var s_ydesc = this.params['ydesc'];
    	var s_cdesc = this.params['cdesc'];
    	
    	var s_link = $("#hlink").attr('value');
    	if (s_link=='0'){$('#hlink').val('&city='+s_city+'&type='+s_type+'&mode='+s_mode+'&find='+s_find+'&body='+s_body+'&rul='+s_rul+'&box='+s_box+'&privod='+s_privod+'&place='+s_place+'&color='+s_color+'&any='+s_any+'&metalic='+s_metalic+'&marka='+s_marka+'&model='+s_model+'&cash_b='+s_cash_b+'&cash_e='+s_cash_e+'&age_b='+s_age_b+'&age_e='+s_age_e+'&ydesc='+s_ydesc+'&cdesc='+s_cdesc);}
    	
    	//this.partial('/ajax/results.php?start='+s_start+'&city='+s_city+'&type='+s_type+'&mode=1&find='+s_find+'&body='+s_body+'&rul='+s_rul+'&box='+s_box+'&privod='+s_privod+'&place='+s_place+'&color='+s_color+'&any='+s_any+'&metalic='+s_metalic+'&marka='+s_marka+'&model='+s_model+'&cash_b='+s_cash_b+'&cash_e='+s_cash_e+'&age_b='+s_age_b+'&age_e='+s_age_e);
    	this.partial('/ajax/results.php?start='+s_start+'&city='+s_city+'&type='+s_type+'&mode='+s_mode+'&find='+s_find+'&body='+s_body+'&rul='+s_rul+'&box='+s_box+'&privod='+s_privod+'&place='+s_place+'&color='+s_color+'&any='+s_any+'&metalic='+s_metalic+'&marka='+s_marka+'&model='+s_model+'&cash_b='+s_cash_b+'&cash_e='+s_cash_e+'&age_b='+s_age_b+'&age_e='+s_age_e+'&ydesc='+s_ydesc+'&cdesc='+s_cdesc);

    	//change_tt(''+s_type+'','type');
    	//change_tt(''+s_city+'','city');
    	$('#city_tool').load('/ajax/city.php?city='+s_city+'');
    	
      });

  });

  $(function() {
    app.run();
  }); 
  */
  
})(jQuery);


