$(document).ready(function() {
	//
	searchBarShowing = true;

	if ($.cookie('propertySearch') == 'closed') // this is brill Dave!
		searchBarShowing = false;

	if (searchBarShowing) {
		$("#propertySearch a").addClass('comOn');
	}

	//Price Range Functions

	$('#fieldBuy,#fieldRent').html('Price Range');

	function loadAgain() {
		//buy rent clicks
		$('#XplodePage_uscPropertySearch_rblBuyRent_0').click(function() {
			$('#fieldBuyWrap').show();
			$('#fieldRentWrap').hide();
		});

		$('#XplodePage_uscPropertySearch_rblBuyRent_1').click(function() {
			$('#fieldBuyWrap').hide();
			$('#fieldRentWrap').show();
		});
		
		// hover function for all submit buttons with the class "hover"
		$('.hover').hover(function() {
			$(this).attr('src', $(this).attr('src').replace(/\.gif/g, "On.gif"));
		}, function() {
			$(this).attr('src', $(this).attr('src').replace(/On\.gif/g, ".gif"));
		});

		// search hide / show
		function slideUp() {
			$('#search').slideUp('fast');
			$('#propertySearch a').attr("class", "");
			$.cookie('propertySearch', 'closed');
		}

		function slideDown() {
			$('#search').slideDown('fast');
			$('#propertySearch a').attr("class", "comOn");
			$.cookie('propertySearch', 'open');
		}

		// click event for search slider
		$('#propertySearch a,#closeSearch').click(function() {
			if ($('#search').css('display') == "block") {
				slideUp();
			} else {
				slideDown();
			}
			return false;
		});
		
	}

	$('#search').append('<a href="#" id="closeSearch">Close Property Search</a>'); // adds the close button at bottom
	searchBar = $('#search').html();
	$('#search').remove();
	$('#header').after('<div id="search" class="clearfix">' + searchBar + '</div>');
	loadAgain();

	if (!$('#propertySearch a').hasClass('comOn')) {
		$('#search').hide();
	}
	/*  END SEARCH BAR JS  */

	////////////////// page specific JS  ////////////////

	//full nav off clicks

	$('#fullNav li.none a').click(function() {
		return false;
	});

	// location guides + similar properties widgets

	$('#locationWidget div, #similarWidget div').hover(function() {
		$(this).children('a').css({ backgroundImage: 'url("/images/global/trianglePink.gif")', color: "#f00076" });
	}, function() {
		$(this).children('a').css({ backgroundImage: 'url("/images/global/triangleGrey.gif")', color: "#808285" });

	}).css("cursor", "pointer").click(function() {
		window.location = $(this).children('a').attr('href');
	});

	if ($.browser.msie && $.browser.version == 6) {
		$('#fullNav ul li').not('.on').not('.none').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	}

	// Popular searches page

	$('.popLeft,.popRight').css("cursor", "pointer").hover(function() {
		$(this).children('div').children('a').css("color", "#f00076").end().children('h3').children('a').css({ backgroundImage: 'url("/images/global/trianglePink.gif")', color: "#f00076" });
	}, function() {
		$(this).children('div').children('a').css("color", "#686868").end().children('h3').children('a').css({ backgroundImage: 'url("/images/global/triangleGrey.gif")', color: "#808285" });
	}).click(function() {
		window.location = $(this).children('div').children('a').attr("href");
	});

});


function createMap(Layer, Latitude, Longit) {
    if (GBrowserIsCompatible()) {
        // convert nat grid co-ords to lat/lng
        
        // create map & zoom
        var map = new GMap2(document.getElementById(Layer));
        map.addControl(new GLargeMapControl());
        map.setCenter(new GLatLng(Latitude, Longit), 13);

        // create marker
        var marker = new GMarker(new GLatLng(Latitude, Longit));
        map.addOverlay(marker);
        map.addControl(new GMapTypeControl(),
                new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10)));
    }
}

function resizeFeatDev(value) {
	
	$('#featuredDevelopmentFlash').height(value)
	var flashObject = document.getElementById("featDevFlash");
	if (flashObject) flashObject.height = value;
	
	if (navigator.userAgent.toLowerCase().indexOf("safari")!=-1) {
		
		var properFlashObject = document.getElementById("featDevFlash");
		if (properFlashObject) properFlashObject.height = value;
		
	}
	
}
