function mycarousel2_initCallback(carousel) {
    jQuery('div.next2').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('div.prev2').bind('click', function() {
        carousel.prev();
        return false;
    });
};
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function($) {
	$(".categories li:last-child").css({margin: "0px"});
	$(".categories ul:last").css({margin: "0px"});
	try {
    if(jQuery('div.block5 .need2').jcarousel) { 
		$("div.block5").children("div.bx-context-toolbar-empty-area").unwrap();
		jQuery('div.photos .photo').jcarousel({
			scroll: 1,
			wrap: 'circular',
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: mycarousel2_initCallback
		});
		jQuery('div.block5 .need2').jcarousel({
			scroll: 1,
			auto: 3,
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}
	} catch(e) { }
	$("div.foto4 a").click(function(){
		$("div.foto4 a:first img").attr("src", $(this).attr("href"));
		return false;
	});
	$("a[rel=z]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
		setInterval(function() {
			$(".weather").toggleClass("hide");
		}, 30000);
		
	$(".menu > ul > li").mouseover(function() {
		$(this).addClass("hover");
	}).mouseout(function() {
		$(this).removeClass("hover");
	});
	
	$("select[name=country]").change(function(){
		var val = $(this).val();
		$(this).parents("form").attr("action", "/objects/"+(val?val+"/":""));
        $("select[name=city]").attr('disabled', true).html('<option>загрузка...</option>');
        $.getJSON(
            'http://'+window.location.hostname+"/objects/citys.php",
            "country_id=" + val,
			function (result, status) {
				if (status == 'error') {
                    alert('error');
                    return(false);
                } else {
                    var options = '';
                    $.each(result, function(key,val) {
                        options += '<option value="' + key + '">' + val + '</option>';
                    });
                    $("select[name=region]").html(options).attr('disabled', false);
				}
			}
		);
        $.getJSON(
            'http://'+window.location.hostname+"/objects/priceselect.php",
            "country_id=" + val,
			function (result, status) {
				if (status == 'error') {
                    alert('error');
                    return(false);
                } else {
                    var options = '';
                    $.each(result, function(key,val) {
                        options += '<option value="' + key + '">' + val + '</option>';
                    });
                    $("select[name=price]").html(options).attr('disabled', false);
				}
			}
		);
	});
	$("a.knopa2").click(function(){
		$(this).parents("form").submit();
		return false;
	});
	$(".cmp").click(function(){
		if($("input.cmp:checked").size()>1) {
			$(".cmp-submit").attr("disabled", "");
		} else {
			$(".cmp-submit").attr("disabled", "true");
		}
	});
	$(".cmp-submit").click(function(){
		if($("input.cmp:checked").size()>1) {
		$("#cmp-form").submit();
		} else {
			alert("Для сравнения необходимо отметить несколько объектов");
		}
		return false;
	});
});


