$(function(){
    
    $(function() {
        var price_from = 150;
        var price_to = 325;
        if ($('.price_from').val() > 0) price_from =  $('.price_from').val();
        if ($('.price_to').val() > 0) price_to =  $('.price_to').val();
		$(".price-range").slider({
			range: true,
			min: 0,
			max: 850,
			values: [price_from, price_to],
			step: 25,
			slide: function(event, ui) {
				$("#amount").val(ui.values[0] + 'лв' + ' - ' + ui.values[1]+'лв');
				$(".price_from").val(ui.values[0]);
				$(".price_to").val(ui.values[1]);
			},
			stop: function(event, ui) {
/* //			    $("form#left_search_form").submit(); */
			}
		});
		$("#amount").val($(".price-range").slider("values", 0) + 'лв - ' + $(".price-range").slider("values", 1) + 'лв');
	});

	if($("#top-item").size() > 0) {
        $("#top-item").jCarouselLite({
            auto: 2500,
            speed: 1000,
            visible: 1,
            btnGo: [".1", ".2",".3"]
        });
    }
    $('.vip_listing').hover(function(){
        $(this).addClass('vip_listing_over');
        $(this).removeClass('vip_listing');
    }, function(){
         $(this).removeClass('vip_listing_over');
         $(this).addClass('vip_listing');
    });
    $('.vipb_listing').hover(function(){
        $(this).addClass('vipb_listing_over');
        $(this).removeClass('vipb_listing');
    }, function(){
         $(this).removeClass('vipb_listing_over');
         $(this).addClass('vipb_listing');
    });
    $(".show_cats_extra").click(function(){
        $("ul.cat_extra").toggle('slide');
        $(this).hide();
        return false;
    });

});

function loginForm(form){
    var params = $('form#userLoginForm').serialize();
    $.post("users.php", params ,
		function (data) {
		    if(data.message) {
		        hs.close('login');
		        window.location.reload();
		    } else {
		        $('.error_inline').html(data.error).fadeIn();
/* 		        hs.close('login');
		        show_error(data.error);
 */		    }
		}, 'json'
	);
}

function passwordForm(form){
    hs.close('sendpassword');
    var params = $('form#userPasswordForm').serialize();
    $.post("users.php", params ,
		function (data) {
		    if(data.message) {
		        show_message(data.message);
		    } else {
		        $('.error_inline').html(data.error).fadeIn();
		        show_error(data.error);
		    }
		}, 
		'json'
	);
}

/* //send ajax EMAIL CONTACT */
function sendMail(form_id) {
var params = $("form#"+form_id).serialize();
	$.post("sendmail.php", params ,
		function (data) {
			show_error(data);
		}
	);
}

function show_error(msg){
    alert(msg);
}
function show_message(msg){
    alert(msg);
}
