//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 load() {
if (GBrowserIsCompatible()) {
	var icon = new GIcon();
	icon.image = "/images/mappointer.png";
	icon.shadow = "/images/mappointershadow.png";
	icon.iconSize = new GSize(74, 41);
	icon.shadowSize = new GSize(115, 41);
	icon.iconAnchor = new GPoint(37, 41);
	icon.infoWindowAnchor = new GPoint(37, 41);
	
	
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(52.827957, 0.892000), 9);

	var marker = new GMarker(map.getCenter(), icon);
	map.addOverlay(marker);
/*
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("<span style=\"font-family: 'Arial', Helvetica, sans-serif; font-size: 70%;\"><span style=\"color: #26488B; font-weight: bold; font-size: 120%;\">Pensthorpe,</span><br/>Fakenham, Norfolk,<br/>England. NR21 0LN</span>");
	});
*/
	GEvent.addListener(marker, "click", function() {
		map.setCenter(new GLatLng(52.827957, 0.892000), (map.getZoom()+1))
	});
  }
}


function prepareName()
{
	if(document.getElementById('name').value=='your name') document.getElementById('name').value='';
}

function prepareEmail()
{
	if(document.getElementById('email').value=='email address') document.getElementById('email').value='';
}

$(document).ready(function() {

	initialize();

	var mydate = new Date();
	$('.year').html(mydate.getFullYear());

	$("#client-quotes-list").newsTicker();


	$(".case-studies-link img").mouseover(function(){
		$(this).animate({opacity: 0.7}, 200);
	});

	$(".case-studies-link img").mouseout(function(){
		$(this).animate({opacity: 1.0}, 200);
	});


	if ( $(".editable-item").length < 1 ) {
		$('h1').flash(
			{ 
				src: '/flash/text-replace.swf', 
				flashvars: { 
					css: [
						'* { color: #ff9021; font-size: 3.2em; }',
						'span { color: #000; }',
						'a { color: #0099CC; text-decoration: none; }',
						'a:hover { text-decoration: underline; }'
					].join(' ')
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));
			}
		);
	}

	$('h3').flash(
		{ 
			src: '/flash/text-replace.swf', 
			flashvars: { 
				css: [
					'* { color: #4b99e0; }',
					'a { color: #0099CC; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			}
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<div>'+this.innerHTML+'</div>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));
		}
	);


	$("#homepage-banner").flash(
		{ src: "/flash/player.swf",
		  width: 920,
		  height: 150,
		  flashvars: { domain: location.host }
		},
	{ version: 8 }
	);





});