$(document).ready(function(){
	
	$(".top-menu-active").prev().css("backgroundImage", "none");
	
	$("#sale-menu").hover(function(){
		var off = $(this).offset();
		$("#for-sale-dropdown").css( {left:off.left, top:off.top+35, zIndex :9999}).show();
		$("#frame-for-sale-dropdown").css( {left: off.left-2, top: off.top+35, height:$("#for-sale-dropdown").height()}).show();

		}, function () {
            $("#for-sale-dropdown").hide();
			$("#frame-for-sale-dropdown").hide();
    });
	
	$("#for-sale-dropdown").hover(function(){
		$("#for-sale-dropdown").show();
		$("#frame-for-sale-dropdown").show();
	}, function () {
        $("#for-sale-dropdown").hide();
		$("#frame-for-sale-dropdown").hide();
    });
	
	$("#rent-menu").hover(function(){
		var off = $(this).offset();
		$("#for-rent-dropdown").css( {left:off.left, top:off.top+35, zIndex :9999} ).show();
		$("#frame-for-rent-dropdown").css( {left: off.left-2, top: off.top+35, height:$("#for-rent-dropdown").height()}).show();
		}, function () {
            $("#for-rent-dropdown").hide();
			$("#frame-for-rent-dropdown").hide();
    });
	
	$("#for-rent-dropdown").hover(function(){
		$("#for-rent-dropdown").show();
		$("#frame-for-rent-dropdown").show();
	}, function () {
        $("#for-rent-dropdown").hide();
		$("#frame-for-rent-dropdown").hide();
    });
	
	/* lang - menu */
	$("#lang-menu").hover(function(){
		var off = $(this).offset();
		$("#lang-menu-dropdown").css( {left:off.left-51, top:off.top+23, zIndex :9999}).show();
		$("#frame-lang-menu-dropdown").css( {left: off.left-51, top: off.top+23, height:$("#lang-menu-dropdown").height()}).show();

		}, function () {
            $("#lang-menu-dropdown").hide();
			$("#frame-lang-menu-dropdown").hide();
    });
	
	$("#lang-menu-dropdown").hover(function(){
		$("#lang-menu-dropdown").show();
		$("#frame-lang-menu-dropdown").show();
	}, function () {
        $("#lang-menu-dropdown").hide();
		$("#frame-lang-menu-dropdown").hide();
    });
	
	
	
	$("#carousel").css("display", "block");
	
	$("#carousel").jCarouselLite({
		auto:2000,
		speed:800,
		visible:12,
		start:0,
		vertical:false,
		btnNext:".carousel-next",
        btnPrev:".carousel-prev"
	});
	
	$(".carousel-list").hover(function(){
		var off = $(this).offset();				   
		$("#carousel-popup").css( {left: off.left, top: off.top-110, zIndex:900}).show();
	},
		function(){
			$("#carousel-popup").hide();	
		}
	);
	
	
	
	
	$(".carousel-list").hover(function(){
		$.ajax({
				type: 'GET',
				url: 'include/ajax.php',
				data: 'action=getCarouselPopup&culture='+$("#lang").val()+'&advert_id='+$(this).attr("advert_id"),
				contentType: "application/json; charset=utf-8",
				
				beforeSend: function(result)
				{
					$("#carousel-popup-loading").css("display", "block");
					$("#carousel-popup-content").css("display", "none");
					
				},
				
				error: function(result)
				{
					ajaxError(result.responseText);
					$("#carousel-popup-loading").css("display", "none");
					$("#carousel-popup-content").css("display", "none");
				},
				
				success: function(result) {
					$("#carousel-popup-loading").css("display", "none");
					$("#carousel-popup-content").html(result);
					$("#carousel-popup-content").css("display", "block");
				}
			});
		return false;
	});
	
	$(".private-advert-content li img").click(function(){
		$.ajax({
				type: 'GET',
				url: 'include/ajax.php',
				data: 'action=getPrivateAdvertBigAjaxImage&id='+$(this).attr("img_id"),
				contentType: "application/json; charset=utf-8",
				
				beforeSend: function(result)
				{
					$("#big-image-loading").css("display", "block");
				},
				
				error: function(result)
				{
					$("#big-image-loading").css("display", "none");
					ajaxError(result.responseText);
				},
				
				success: function(result) {
					$("#big-image-loading").css("display", "none");
					$(".private-advert-big-image").html(result);
				}
			});
		return false;
	});
	
	$("#main-advert li a").click(function(){
		$("#main-advert li").removeClass("main-advert-selected");
		$(this).parent().addClass("main-advert-selected");
		var $this = $(this);
		var $content = $this.html();
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=getMainAdvertAcclaim&culture='+$("#lang").val()+'&list_type='+$this.attr("list_type"),
			contentType: "application/json; charset=utf-8",
			
			beforeSend: function(result)
			{
				$this.html(AllLoading);
			},
			
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$this.html($content);
				$("#main-advert-content").html(result);
			}
		});
		return false;
	});
	
});
