
 jQuery(document).ready(function(){
 	get_mix_max_price();
 });
 
 
function set_min_max(min,max,price0,price1)
{
	price1 = 0;
	price2 = 0;
	//alert(min+" "+max);
	
	if(parseInt(jQuery("#slider").slider("values",0))>parseInt(min))
	{
		jQuery("#slider").slider("option","min",parseInt(min));
		jQuery("input#price1").val(parseInt(min));
		jQuery("#slider").slider("values",0,parseInt(min));
		//alert(jQuery("#slider").slider("values",0));
		
		jQuery("#slider").slider("option","max",parseInt(max));
		jQuery("input#price2").val(parseInt(max));
		jQuery("#slider").slider("values",1,parseInt(max));
		//alert(jQuery("#slider").slider("values",1));	
		
	}else
	{
		jQuery("#slider").slider("option","max",parseInt(max));
		jQuery("input#price2").val(parseInt(max));
		jQuery("#slider").slider("values",1,parseInt(max));
		//alert(jQuery("#slider").slider("values",1));
		
		jQuery("#slider").slider("option","min",parseInt(min));
		jQuery("input#price1").val(parseInt(min));
		jQuery("#slider").slider("values",0,parseInt(min));
		//alert(jQuery("#slider").slider("values",0));
	}
	
	
	


}


function get_min_price()
{
	var klass = jQuery(jQuery("#cusel-scroll-class_d").children('.cuselActive')[0]).attr('value');
	var snaruzhi = jQuery(jQuery("#cusel-scroll-ex_d").children('.cuselActive')[0]).attr('value');
	var snutri= jQuery(jQuery("#cusel-scroll-in_d").children('.cuselActive')[0]).attr('value');
	if(typeof(klass)=='undefined') klass=jQuery("#class_d").val();
	if(typeof(snaruzhi)=='undefined') snaruzhi=jQuery("#ex_d").val();
	if(typeof(snutri)=='undefined') snutri=jQuery("#in_d").val();
	
	jQuery.ajax({
			type: "POST",
			url: "/includes/search_menu/ajax/search_menu_work.php", 
			data:"mode=min_price&klass="+klass+"&snaruzhi="+snaruzhi+"&snutri="+snutri,
			cache: false,
			dataType: 'html',
			success: function(html){
				set_min(html);
				var params = {
					changedEl: ".lineForm select",
					visRows: 6,
					scrollArrows: true
				}
				cuSel(params);
			} 
		});	
}

function get_max_price()
{
	var klass = jQuery(jQuery("#cusel-scroll-class_d").children('.cuselActive')[0]).attr('value');
	var snaruzhi = jQuery(jQuery("#cusel-scroll-ex_d").children('.cuselActive')[0]).attr('value');
	var snutri= jQuery(jQuery("#cusel-scroll-in_d").children('.cuselActive')[0]).attr('value');
	if(typeof(klass)=='undefined') klass=jQuery("#class_d").val();
	if(typeof(snaruzhi)=='undefined') snaruzhi=jQuery("#ex_d").val();
	if(typeof(snutri)=='undefined') snutri=jQuery("#in_d").val();
	
	jQuery.ajax({
			type: "POST",
			url: "/includes/search_menu/ajax/search_menu_work.php", 
			data:"mode=max_price&klass="+klass+"&snaruzhi="+snaruzhi+"&snutri="+snutri,
			cache: false,
			dataType: 'html',
			success: function(html){
				set_max(html);
				var params = {
					changedEl: ".lineForm select",
					visRows: 6,
					scrollArrows: true
				}
				cuSel(params);
			} 
		});	
}

jQuery.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 jQuery.getUrlVars()[name];
  	}
});

function is_var(_var){
    try{
        if (typeof(_var)=="undefined")
              return false;
        else
              return  _var;
       }
       catch(e){
              return false;
        }
}

function get_mix_max_price()
{
	var klass = jQuery(jQuery("#cusel-scroll-class_d").children('.cuselActive')[0]).attr('value');
	var snaruzhi = jQuery(jQuery("#cusel-scroll-ex_d").children('.cuselActive')[0]).attr('value');
	var snutri= jQuery(jQuery("#cusel-scroll-in_d").children('.cuselActive')[0]).attr('value');
	if(typeof(klass)=='undefined') klass=jQuery("#class_d").val();
	if(typeof(snaruzhi)=='undefined') snaruzhi=jQuery("#ex_d").val();
	if(typeof(snutri)=='undefined') snutri=jQuery("#in_d").val();
	
	var price1=0;
	var price2=0;
	if(is_var(jQuery.getUrlVar('price%5B0%5D')))
	{
		price1 = jQuery.getUrlVar('price%5B0%5D');
	}
	if(is_var(jQuery.getUrlVar('price%5B1%5D')))
	{
		price2 = jQuery.getUrlVar('price%5B1%5D');
	}
	
	//alert(klass+"  "+snaruzhi+"  "+snutri+"  "+price1+"  "+price2);
	
	jQuery.ajax({
			type: "POST",
			url: "/includes/search_menu/ajax/search_menu_work.php", 
			data:"mode=min_max_price&klass="+klass+"&snaruzhi="+snaruzhi+"&snutri="+snutri,
			cache: false,
			dataType: 'html',
			success: function(html){
				var min = html.split('.')[0];
				var max = html.split('.')[1];
				//alert(min+"  "+max);
				set_min_max(min,max,price1,price2);
				//jQuery('#ex_trims').html(html);
				var params = {
					changedEl: ".lineForm select",
					visRows: 6,
					scrollArrows: true
				}
				cuSel(params);
			} 
		});	
}

function set_filter_klass()
{
	var klass = jQuery(jQuery("#cusel-scroll-class_d").children('.cuselActive')[0]).attr('value');
	var snaruzhi = jQuery(jQuery("#cusel-scroll-ex_d").children('.cuselActive')[0]).attr('value');
	var snutri= jQuery(jQuery("#cusel-scroll-in_d").children('.cuselActive')[0]).attr('value');
	if(typeof(klass)=='undefined') klass=jQuery("#class_d").val();
	if(typeof(snaruzhi)=='undefined') snaruzhi=jQuery("#ex_d").val();
	if(typeof(snutri)=='undefined') snutri=jQuery("#in_d").val();
	
	//alert(klass+" "+snaruzhi+" "+snutri);
	
	jQuery.ajax({
			type: "POST",
			url: "/includes/search_menu/ajax/search_menu_work.php", 
			data:"mode=snaruzhi_list_klass&klass="+klass,
			cache: false, 
			dataType: 'html',
			success: function(html){
				//alert(html);
				jQuery('#ex_trims').html(html);
				jQuery("#snaruzhi_id").val('0');	
				var params = {
					changedEl: ".lineForm select",
					visRows: 6,
					scrollArrows: true
				}
				cuSel(params);

			} 
		});
	jQuery.ajax({
			type: "POST",
			url: "/includes/search_menu/ajax/search_menu_work.php", 
			data:"mode=snutri_list_klass&klass="+klass,
			cache: false,
			dataType: 'html',
			success: function(html){
				jQuery('#in_trims').html(html);
				jQuery("#snutri_id").val('0');	
				var params = {
				changedEl: ".lineForm select",
				visRows: 6,
				scrollArrows: true
				}
				cuSel(params);	
				
			} 
		});
	get_mix_max_price();
	return false;
}

function set_filter_snaruzhi()
{
	var klass = jQuery(jQuery("#cusel-scroll-class_d").children('.cuselActive')[0]).attr('value');
	var snaruzhi = jQuery(jQuery("#cusel-scroll-ex_d").children('.cuselActive')[0]).attr('value');
	if(typeof(klass)=='undefined') klass=jQuery("#class_d").val();
	if(typeof(snaruzhi)=='undefined') snaruzhi=jQuery("#ex_d").val();
	
	jQuery.ajax({
			type: "POST",
			url: "/includes/search_menu/ajax/search_menu_work.php", 
			data:"mode=snutri_list&snaruzhi="+snaruzhi+"&klass="+klass,
			cache: false,
			dataType: 'html',
			success: function(html){
				jQuery('#in_trims').html(html);
				var params = {
				changedEl: ".lineForm select",
				visRows: 6,
				scrollArrows: true
				}
				cuSel(params);									
			} 
		});	
	get_mix_max_price();						
	return false;
}
