var map; //gmap var

$(document).ready(function() {


	/* clock */
	setInterval (
		function(){
			 $('#date').strftime( '%H:%M:%S %d/%m/%y' );
		}

	, 1000 );

	/* search box */

	var searchDataHeight = $("#searchData").height();

	$("#search").mouseenter(function (event) {
		$("#searchData").stop().animate({
	        height: "38px",
	        paddingTop: "0px"
	     }, 1, function(){
				$("#searchTab").addClass("active");
				$("#searchData").animate({
			        height: searchDataHeight+"px",
	       			paddingTop: "10px"
			      }, 500)
			}
		 );
	});

	$("#search").mouseleave(function (event) {
		$("#searchData").stop().animate({
	        height: "38px",
	        paddingTop: "0px"
	      }, 500, function(){
				$("#searchTab").removeClass("active");
				$("#searchData").animate({
			        height: "0px",
	       			paddingTop: "0px"
			      }, 1)
			}
		 );
	});

	$("#searchLocations li").click(function (event) {
		$("#searchLocations").stop().animate({
	        height: "0px"
	      }, 300 , function(){
	      		$("#searchSizes").slideDown(300);
	      	}
	      );


	      jQuery.each($("#searchSizes li a"), function(i) {
		    var endURL = $(event.target).attr("href");
		    if($("#searchSizes li:eq("+i+")").attr("title")){
				endURL = endURL.replace( /\.(?!.*\.)/ , "/"+$("#searchSizes li:eq("+i+")").attr("title")+".");
	        }
	        $("#searchSizes li:eq("+i+") a").attr("href",endURL);
		  });

	});


	$("#searchData").height("0px")


	// office image cycle home page

	$('#offices').cycle({
	    fx:     'fade',
	    timeout: 16000,
	    delay:  -2000
	});




	//contact

	$('.contactForm input , .contactForm textarea').focus(function (event) {

		$('.contactForm label[for='+$(event.currentTarget).attr("id")+']' ).addClass( "active" );

	});

	$('.contactForm input , .contactForm textarea').blur(function (event) {

		$('.contactForm label[for='+$(event.currentTarget).attr("id")+']' ).removeClass( "active" );

	});





	/* property tabs */

	$(".propertyDescriptionBox").css("overflow","hidden");
	$(".propertyDescriptionBox > li").css("position","absolute");
	$(".propertyDescriptionBox > li:gt(0)").css("left","-426px");
	$( ".propertyDescriptionBox" ).height( $( $(".propertyMenu li.active").find("a").attr("href")  ).height());

	$(".propertyMenu li").mouseenter(function (event) {
		$(this).stop().animate({
	        marginTop: "0px"
	      }, 300 );
	});

	$(".propertyMenu li").mouseleave(function (event) {
		if(!$(this).hasClass( "active" )){
			$(this).stop().animate({
		        marginTop: "8px"
		      }, 300 );
		}
	});


	$(".propertyMenu li").click(function (event) {

		if(!$(this).hasClass("active")){
			var last = $(".propertyMenu li.active");


			last.stop().animate({
			        marginTop: "8px"
			}, 300 ).removeClass("active");

			$(this).addClass("active");

			$( last.find("a").attr("href")  ).animate({
				        left: "426px"
			}, 400 , function(){
					$( ".propertyDescriptionBox" ).animate({
						height: $( $(".propertyMenu li.active").find("a").attr("href")  ).height()
					}, 400 , function(){
						$( $(".propertyMenu li.active").find("a").attr("href")  ).animate({
					        left: "0px"
					}, 400 );
					$( last.find("a").attr("href") ).css("left","-426px");
				})
			});
		}
	});







	/* property result image fix */


$('.propertyListings_image img').imgpreload
({
	all: function()
	{
		$(".propertyListings .propertyListings_image").each(
			function(index){
				$(".propertyListings .propertyListings_image:eq("+index+")").width( $(".propertyListings .propertyListings_image:eq("+index+") img").width() + 28 );
			}
		);

		$(".propertyListings li").each(
			function(index){
				$(".propertyListings li:eq("+index+") .propertyListings_image").css("position" , "relative");
				$(".propertyListings li:eq("+index+") .propertyListings_image").css("top",  ( $(".propertyListings li:eq("+index+")").height() - $(".propertyListings li:eq("+index+") .propertyListings_image").height() ) / 2 );
			}
		);

	}
});






});