$(document).ready(function() {
	//Cufon.replace(".ba_page_right_inner h1");
	$('.searchresults').jScrollPane({ showArrows: true, scrollbarWidth: 15, arrowSize: 16 });
	$("a.floorplanlightbox").fancybox({
		'hideOnContentClick': false,
		'overlayOpacity': 0.6
	});
	$("a.map").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 600,
		'frameHeight': 400,
		'overlayOpacity': 0.6
	}); //.each(function() {$(this).attr("href","#map") });
	$("a.gallery").fancybox({
		'hideOnContentClick': false,
		'overlayOpacity': 0.6
	});
	$("#map").css("display", "block");
	$('.map').maphilight({ fillOpacity: 1, fillColor: 'FFE311', strokeColor: 'FFE311', strokeOpacity: 1 });
	$(".contact_formholder").css("height", "0").css("overflow", "hidden");
	$("a.contact_form").click(function() { var newwin = window.open("/contactus.aspx?property=" + $(this).attr("rel"), "newlondoncontact", "width=440,height=450,location=no,menubar=no,personalbar=no,status=no,scrollbars=no,resizable=no,titlebar=no"); }).attr("href", "javascript:;");
	$.externallinks();
	$.firstchildamend();
	$('input[type=text][title!=""]').hint();
	$('textarea[title!=""]').hint();

	$("a.videofancybox,a.floorplanlightbox").attr({
		title: function(arr) {
			if ($(this).attr("title").indexOf(" (opens in a new window)") >= 0) {
				$(this).attr("title", $(this).attr("title").replace(" (opens in a new window)", ""));
			}
			if ($(this).attr("title").indexOf("opens in a new window") >= 0) {
				$(this).attr("title", $(this).attr("title").replace("opens in a new window", ""));
			}
		}
	});

	$('.modalbackground').css("opacity", 0.6).css("filter", "alpha(opacity=60)");
	$(function() {
		$(".menu .bottom ul li a").mouseover(function() {
			$(this).addClass("over");
		}).mouseout(function() {
			$(this).removeClass("over");
		}).focusin(function() {
			$(this).addClass("over");
		}).focusout(function() {
			$(this).removeClass("over");
		});
	});

	$(".menu ul").hide();
	$(".menu li.bc>ul").show();

	$(".menu a[href^='javascript:;']").click(function() {
		if ($(this).parent().find('ul:visible').size() > 0) {
			$(".flashdiv").css("height", "400px");
			$(".flashdiv object").css("height", "400px");
			$(".flashdiv object").css("z-index", "0");
			$(".flashdiv embed").css("height", "400px");
			$(".banners li").hide();
			$(".banners li.banner" + $(this).parent().attr("class").replace('color', '').replace(' bc', '')).show();
		}
		else if ($(this).parent().find('ul:hidden').size() > 0) {
			$(".menu ul").hide();
			$(this).parent().find('ul').show();

			$(".flashdiv").css("height", "0");
			$(".flashdiv object").css("height", "0");
			$(".flashdiv object").css("z-index", "-1");
			$(".flashdiv embed").css("height", "0");
			$(".banners li").hide();
			$(".banners li.banner" + $(this).parent().attr("class").replace('color', '').replace(' bc', '')).show();
		}
	});
	$(".menu .current a").click(function() {
		$(".banners li").hide();
		return false;
	}).each(function() {
		$(this).attr('href', "javascript:;");
	});

	$("a[href^='#']").each(function() {
		var xhash = window.location.hash;
		var xlocation = window.location.href;
		var href = xlocation.replace(xhash, '') + $(this).attr('href').replace('/#.*/i', '');
		$(this).attr('href', href);
	});
	$.slickslideshow();
});

$(window).unload(function() { GUnload(); });

$.firstchildamend = function() { $(".footnav li:first-child").css("border", "0").css("padding-top", "0") }

$.externallinks = function() {
	$('a[href^="http://"],a[rel="external"]')
	.attr({
		target: "_blank",
		title: function(arr) {
			if ($(this).attr("title").length > 0) {
				$(this).attr("title", $(this).attr("title") + " (opens in a new window)");
			}
			else {
				$(this).attr("title", "opens in a new window");
			}
		}
	});
	$('a[href^="http://clients.islington.byteart.com/"]')
	.attr({
		target: "_self",
		title: function(arr) {
			$(this).attr("title", $(this).attr("title").replace(/ (opens in a new window)/, ""));
			$(this).attr("title", $(this).attr("title").replace(/(opens in a new window)/, ""));
		}
	});
}
$.slickslideshow = function() {
	var currentPosition = 0;
	var slideWidth = 360;
	var slides = $('.slide');
	var numberOfSlides = slides.length;
	$('#slidesContainer').css('overflow', 'hidden');
	slides.wrapAll('<div id="slideInner"></div>').css({ 'float': 'left', 'width': slideWidth });
	$('#slideInner').css('width', slideWidth * numberOfSlides);
	$('#slideshow').prepend('<a class="control" id="leftControl" href="javascript:;">Clicking moves left</a>').append('<a class="control" id="rightControl" href="javascript:;">Clicking moves right</a>');
	manageControls(currentPosition);
	$('.control').bind('click', function() { currentPosition = ($(this).attr('id') == 'rightControl') ? currentPosition + 1 : currentPosition - 1; manageControls(currentPosition); $('#slideInner').animate({ 'marginLeft': slideWidth * (-currentPosition) }); });
	function manageControls(position) { if (position == 0) { $('#leftControl').hide() } else { $('#leftControl').show() } if (position == numberOfSlides - 1) { $('#rightControl').hide() } else { $('#rightControl').show() } }
}

var localSearch = new GlocalSearch();
var map;
var icon = new GIcon();
icon.image = "http://www.google.com/mapfiles/marker.png";
icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);

function usePointFromPostcode(location, callbackFunction) { mapLoad(); localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var point = new GLatLng(resultLat, resultLng); callbackFunction(point); } else { var point = new GLatLng(-33.0277, 17.9176); callbackFunction(point); } }); localSearch.execute(location); /*showPointLatLng(point);*/ }

function placeMarkerAtPoint(point) { var marker = new GMarker(point, icon); map.addOverlay(marker); setCenterToPoint(point); }

function setCenterToPoint(point) { map.setCenter(point, 15); }

//function showPointLatLng(point) { alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng()); }

function mapLoad() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.setUIToDefault(); map.setCenter(new GLatLng(0, 0), 2, G_NORMAL_MAP); } }
