$(document).ready(function(){
	
	$("a#thumb_slider").click(function(){
		$("ul#property_thumbs").animate({left: "-87px"}, 200, "swing", function(){
			$(this).css("left", "0px").children("li:first").appendTo("ul#property_thumbs");
		});
		return false;
	});
	
	$("ul#property_thumbs a").click(function(){
		$("img#property_photo_main").attr( "src", $(this).attr("href") ).parents("a:first").attr("href", $(this).attr("href").replace( /_255x255/, "_600~500" ) );
		return false;
	});
	
	$("a.fb_pop").fancybox({
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': false
	});
	
	$("a#toggle_map").click(function(){
		if( $("div#property_map").css("height") == "410px" ){
			$(this).html("View Map");
			$("div#property_map").css("height", "0px");
			return false;
		}else{
			$(this).html("Hide Map");
			$("div#property_map").css("height", "410px");
		}
		geocoder = new google.maps.Geocoder();
		var latlng = new google.maps.LatLng(53.792, -1.754);
		var myOptions = {
			zoom: 15,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		map = new google.maps.Map(document.getElementById("property_map_inner"), myOptions);
		
		var address = $(this).attr("rel");
		
		if (geocoder) {
			geocoder.geocode( { 'address': address, 'country': 'UK'}, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					map.setCenter(results[0].geometry.location);
					var marker = new google.maps.Marker({
						map: map, 
						position: results[0].geometry.location
					});
				}else{
					alert( "Unable to locate this property on map." );
				}
			});
		}
		
		return false;
	});
	
	$("ul#menu li").hover(function(){
		$(this).css("overflow", "visible").addClass("hovered");
		var width = $(this).width();
		if( width > 200 ){
			$(this).find("ul").css( "width", (width-20)+"px" );
			$(this).find("ul a").css( "width", (width-32)+"px" );
		}
	},function(){
		$(this).css("overflow", "hidden").removeClass("hovered");
	});
	
	$("a.tenant_step").addClass("hide").click(function(){
		if( !$(this).hasClass("hide") ){
			$(this).addClass("hide");
			return false;
		}
		$("a.tenant_step").addClass("hide");
		$(this).removeClass("hide");
		return false;
	});
	
	$("div#tenants_steps a.tenant_step:first").click()
	
});