function pagingcallback() {
	$(".pagingwrapper").show('fast');
	$('.pagingsort').show('fast');
	$('#loadingmessage').hide('fast');
	if($('#pagingtopnav').length > 0) {
		$('.location-list').show('fast');
	}
}

function villadetailcallback() {
	$(".tab_content").show('fast');
	$('#loadingmessage').hide('fast');
}

function initTabs() {
	$(".tab_content").hide(); //Hide all content
	if(location.hash != "") {
		var target = location.hash.split("#")[1];
		$(location.hash).show(); //Show first tab content
		$("ul.tabs li:has(a[href=#"+target+"])").addClass("active").show();
	} else {
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
	}
	//On Click Event
	$("ul.tabs li").click(function(e) {
		//hide ketchup error
		$('.ketchup-error').hide();
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		e.preventDefault();
	});
}

$(window).load(function () {
	
	//paging
	$(".pagingwrapper").quickPager({
		pageSize: 8,
		pagerLocation : 'both'
	});

	//sort
	$('.pagingsort').prependTo('#pagingtopnav');
	$('.location-list').prependTo('#pagingtopnav');
	$('.sortform').clone().prependTo('#pagerbottom');
	
	//villa detail
	$(".tab_content").find('img').batchImageLoad({
		loadingCompleteCallback: villadetailcallback
	});
	
	//photo gallery
	$("a.fancybox").fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
	});

	//rent a villa
	$('li.rent-parent').click( function() {
		$('ul.level2,').css('visibility', 'hidden');
		$('#advsearch-wrapper').hide();
		$(this).children().css('visibility', 'visible');
	});
	$('li.rent-parent.active').children().css('visibility', 'visible');
	//advanced search popup
	$('li.search-parent').click( function() {
		$(this).children().slideDown('fast');
		$('ul.level2,').css('visibility', 'hidden');
	});
	$('.div-close').click( function() {
		$('#advsearch-wrapper').slideUp('fast');
		return false;
	});
	
	//dropdown menu
	$("ul.sf-menu").superfish({ 
        animation: {height:'show'},
		speed: 'fast'
    }); 
	$('li.level2').hover(
		function () {
			$(this).siblings().addClass('dim');
		},
		function () {
			$(this).siblings().removeClass('dim');
		}
	);
	
	//tabs
	initTabs();
	
	//rates
	$('.table-rate tr:odd').addClass('odd');
	
	//form validation
	$.metadata.setType("attr", "validate");
	$('.form-validate-enquiry').validate();
	$('.form-validate-contact').validate();
	
	//error & message
	setTimeout(function() {
 		$(".error-box, .message-box").fadeOut('slow');
	}, 2000);

});
