$(document).ready(function(){
	
/*$(".find_fiolet li").click(function(){
	//$(this).fadeOut("slow");
	$(this).toggleClass("check_selected");
	//$(this).attr("checked","checked");
	//$(".find_fiolet > li").css("border","1px solid red");
	//return false;
	});

*/	
$(".find").click(function(){
    $(".hiding_menu").hide();
	$(".find").hide();
	$(".find_menu").show();
	return false;
	});
	
$("#cancel").click(function(){
	$(".hiding_menu").show();
	$(".find").show();
	$(".find_menu").hide();
	return false;
	});	
$(".sub_no a").click(function(){
	$(".subscr_box").hide();
	$(".index_top_bg").removeClass("black");
	return false;
	});	
$(".subscribe a").click(function(){
	$(".subscr_box").show();
	$(".index_top_bg").addClass("black");
	return false;
	});	
	
$("#lupa").click(function () {
        $("#searchext").show("slide", { direction: "up"}, 2000);
        $("#searchmain").hide();
	});

	// цена
$('#hour').trackbar({
		onMove : function() {
		    if(this.leftValue>0 || this.rightValue<3000)
			sendValue('fprice',this.leftValue,this.rightValue);
		},
		width : 313, // px
		leftLimit : 0, // unit of value
		leftValue : 0, // unit of value
		rightLimit : 3000, // unit of value
		rightValue : 3000 // unit of value
	});
	// возраст
$('#age').trackbar({
		onMove : function() {
		    if(this.leftValue>18 || this.rightValue<42)
			sendValue('fage',this.leftValue,this.rightValue);
		},
		width : 313, // px
		leftLimit : 18, // unit of value
		leftValue : 18, // unit of value
		rightLimit : 42, // unit of value
		rightValue : 42 // unit of value
	});
	
$('#height').trackbar({
		onMove : function() {
			if(this.leftValue>150 || this.rightValue<180)
			sendValue('fheight',this.leftValue,this.rightValue);
		},
		width : 313, // px
		leftLimit : 150, // unit of value
		leftValue : 150, // unit of value
		rightLimit : 180, // unit of value
		rightValue : 180 // unit of value
	});
$('#weight').trackbar({
		onMove : function() {
		    if(this.leftValue>40 || this.rightValue<150)
			sendValue('fweight',this.leftValue,this.rightValue);
		},
		width : 313, // px
		leftLimit : 40, // unit of value
		leftValue : 40, // unit of value
		rightLimit : 150, // unit of value
		rightValue : 150 // unit of value
	});
	
    
	
});

function sendValue(name,lvalue,rvalue){
		$('#'+name).val(lvalue+"-"+rvalue);
}
	
	
	// ..................................................................

function sendMessage()
{

	if(!$("#name").val()) { $("#name").focus(); return false; }
	if(!$("#contact").val()) { $("#contact").focus(); return false; }
	if(!$("#text").val()) { $("#text").focus(); return false; }
    
	
	var data = "act=save&" + $("#contacts_form").serialize();
	$.ajax({
		type: "POST",
		url: "/jx/message.php",
		data: data,
		success: function(msg)
		{  
			if(msg == "error")
			{
			    $("#black").show();
			    $("#meserror").show();
			    $("#black").fadeOut(3000);
	            $("#meserror").fadeOut(3000);
				
			}
			else
			{
			 
			 $("#name").val("");
			 $("#contact").val("");
			 $("#text").val("");
			 $("#black").show();
			 $("#message").show();
			 $("#black").fadeOut(3000);
	         $("#message").fadeOut(3000);
	         }
			 
		}
	});
	
    
	return false;
}

// ..................................................................

function sendSubscribe()
{

	if(!$("#email").val()) { $("#email").focus(); return false; }
	
	var data = "act=save&" + $("#subs_form").serialize();

	$.ajax({
		type: "POST",
		url: "/jx/subscribe.php",
		data: data,
		success: function(msg)
		{  
			if(msg == "error")
			{   //$("#subscribe").hide(1000);
			    $(".subscr_box").hide(1000);
			    $("#suberror").show();
	            $("#suberror").fadeOut(3000);
				$(".subscr_box").fadeIn(3000);
			}
			else
			{
			 $("#email").val("");
			 $(".subscr_box").hide(1000);
			 //$("#subscribe").hide(1000);
			 $("#submessage").show();
			 //$("#black").fadeOut(3000);
			 $(".index_top_bg").removeClass("black");
	         $("#submessage").fadeOut(3000);
	         
	        }
			 
		}
	});
	
    
	return false;
}

jQuery.fn.customInput = function(){
	$(this).each(function(i){	
	
		var input = $(this);
		
		// get the associated label using the input's id
		var label = $('label[for='+input.attr('id')+']');
		
		// find all inputs in this set using the shared name attribute
		var allInputs = $('input[name='+input.attr('name')+']');
		
		// necessary for browsers that don't support the :hover pseudo class on labels
		label.hover(
			function(){ $(this).addClass('hover'); },
			function(){ $(this).removeClass('hover'); }
		);
		
		/* jQuery lets you create and bind any custom event ('updateState').
			We trigger this event twice:
				1. when the script is run on DOM ready so that it 
					picks up any inputs checked by default, and 
				2. when the input is clicked via its label */
						
		input.bind('updateState', function(){	
			if (input.is(':checked')) {
				if (input.is(':radio')) {				
					allInputs.each(function(){
						$('label[for='+$(this).attr('id')+']').removeClass('checked');
					});		
				};
				label.addClass('checked');
			}
			else { label.removeClass('checked'); }
									
		})
		.trigger('updateState')
		.click(function(){ 
			$(this).trigger('updateState'); 
		})
		.bind('focus',function(){ label.addClass('focus'); })
		.bind('blur', function(){ label.removeClass('focus'); });
	});
};

$(function(){
		$('input').customInput();
	});


