//when page loads start standard functions
function initialize() {
	//replace external links with open in new window
	externalLinks();
}

function $import(src){
	var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
	scriptElem.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(scriptElem);
}


// import with a random query parameter to avoid caching
function $importNoCache(src){
	var ms = new Date().getTime().toString();
	var seed = "?" + ms; 
	$import(src + seed);
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
		}
	}
}

function loadMap() {
if (GBrowserIsCompatible()) {
	var icon = new GIcon();
	icon.image = "/images/map-icon.png";
	icon.iconSize = new GSize(35, 35);
	icon.iconAnchor = new GPoint(35, 35);
	
	var map = new GMap2(document.getElementById("find-us-map"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(51.958442, 1.308532), 12);

	var marker = new GMarker(map.getCenter(), icon);
	map.addOverlay(marker);

	GEvent.addListener(marker, "click", function() {
		map.setCenter(new GLatLng(51.958442, 1.308532), (map.getZoom()+1))
	});
  }
}

function prepareInput(id,value)
{
	if(document.getElementById(id).value==value) document.getElementById(id).value='';
}




$(document).ready(function() {
	initialize();

	if ( $("#find-us-map").length > 0 ) {
		loadMap();
	}

	$("#name").click(function(){
		prepareInput('name','Your Name');
	});

	$("#companyName").click(function(){
		prepareInput('companyName','Company Name');
	});

	$("#email").click(function(){
		prepareInput('email','Email Address');
	});

	$("#telephoneNumber").click(function(){
		prepareInput('telephoneNumber','Telephone Number');
	});

	$("#message").click(function(){
		prepareInput('message','Your Message');
	});

	$(".thumbnail a").mouseover(function(){
		$("#main-large-picture").attr("src",$(this).attr("rel"));
		$("#main-picture-title").html($(this).attr("title"));
	});

	var mydate = new Date();
	$("#year").html("Portcentric Solutions Ltd &copy; " + mydate.getFullYear());

});