﻿/* Queue the Site Load Events
===================================================================================== */
$(function() {
	initLabels();
	initExternalLinks();
	initMap();
});

  
   
/* Googlemap
===================================================================================== */
function initMap() {

  if (!$("#map")[0]) return;
  
  var icon = createPushpin();
  if (GBrowserIsCompatible()) {
  //http://maps.google.com/maps?f=q&hl=en&geocode=&q=35+Alma+vale+Road,+Clifton
  //&sll=37.0625,-95.677068
  //&sspn=49.444078,78.398437&ie=UTF8&cd=1&ll=51.462577,-2.615197&spn=0.009572,0.01914&z=16&iwloc=addr
	  var pos = new GLatLng('51.462577', '-2.615197');
	  var map = new GMap2(document.getElementById("map"));
	  map.setCenter(pos, 13);
	  map.addControl(new GLargeMapControl());
	  map.addControl(new GMapTypeControl());
	  map.addOverlay(new GMarker(pos, icon));
  }
  
  $("body").unload(GUnload);
}
function createPushpin(){
  
  var icon = new GIcon();
  icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
  icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
  icon.iconSize = new GSize(12, 20);
  icon.shadowSize = new GSize(22, 20);
  icon.iconAnchor = new GPoint(6, 20);
    
    icon.infoWindowAnchor = new GPoint(9,2);
    icon.infoShadowAnchor = new GPoint(18,25);
    
    return icon;    
}

/* labels
===================================================================================== */
function initLabels() {
	$(".moveLabels input:text").each( 
		function() { resetLabel($(this)); }
	);
	
	$(".moveLabels input:text").focus(function() {
			if ($(this).val() == $(this).siblings("label").text()) {
				$(this).attr('value', '');
			}
	});
	
	$(".moveLabels input:text").blur(function() {
			resetLabel($(this));
	});
}
function resetLabel(txtBox) {
	if ($(txtBox).val() == '') {
		$(txtBox).val($(txtBox).siblings("label").text());
	}
}
  
/* External Links and PDF Links
===================================================================================== */
function initExternalLinks() {
	var h = window.location.host.toLowerCase();
	$("a[@href^='http']:not([@href^='http://" + h + "']):not([@href^='http://www." + h + "']), a[@href$='.pdf']").attr("target", "_blank");
}
