window.onresize = sizeContent;
window.onload = fixPNG;

function sizeContent() {
	var viewportheight;
	var size;
	
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight
	}
	
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		viewportheight = document.documentElement.clientHeight
	}
	else {
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	size = viewportheight - extraheight - 137 - 224 - 20;
	if(!googlemap) {
		document.getElementById('maincontent').style.minHeight = size+'px';
	}
}

function movep(id) {
	var move = 0;
	if(portfolio[id][0]<portfolio[id][1]) {
		move = 4;
		if(move>(portfolio[id][1]-portfolio[id][0])) {
			move = portfolio[id][1]-portfolio[id][0];
		}
	}
	else if(portfolio[id][0]>portfolio[id][1]) {
		move = -4;
		if(move<(portfolio[id][1]-portfolio[id][0])) {
			move = portfolio[id][1]-portfolio[id][0];
		}
	}

	if(move!=0) {

		portfolio[id][0] += move;
		document.getElementById('pinfo'+id).style.marginTop = portfolio[id][0]+'px';
		setTimeout('movep('+id+')', 50);
	}
	else {
		portfolio[id][0][2] = false;
	}
}


function sp(id) {
	if(!portfolio[id][0][2]) {
		portfolio[id][0][2] = true;
		portfolio[id][1] = -33;
		movep(id);
	}
}

function hp(id) {
	if(!portfolio[id][0][2]) {
		portfolio[id][0][2] = true;
		portfolio[id][1] = 0;
		movep(id);
	}
}

function s(id) {
	document.getElementById(id).style.display = 'block';	
}

function h(id) {
	document.getElementById(id).style.display = 'none';	
}

function swapPortfolio(id, ext) {
	document.mainimage.src = '/images/portfolio/'+id+ext+'-large.png';
	return false;
}

var map;
var gdir;
var geocoder = null;
var addressMarker;
var localSearch;
var evolutedMarker;
function initialize() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		gdir = new GDirections(map, document.getElementById("map_directions"));
		localSearch = new GlocalSearch();
        geocoder = new GClientGeocoder();
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

		var point = new GLatLng(53.244596418618606, -1.4147686958312988);
		map.addControl(new GSmallMapControl());
		map.setCenter(point, 10);
		
		var baseIcon = new GIcon();
		baseIcon.shadow = "/images/we-are-here-shadow.png";
		baseIcon.iconSize = new GSize(129, 42);
		baseIcon.shadowSize = new GSize(151, 42);
		baseIcon.iconAnchor = new GPoint(18, 42);

		var letteredIcon = new GIcon(baseIcon);
		letteredIcon.image = "/images/marker.png";
		markerOptions = { icon:letteredIcon };
		evolutedMarker = new GMarker(point, markerOptions);
		/*GEvent.addListener(evolutedMarker, "click", function() {
			alert("yes");
		});*/
		map.addOverlay(evolutedMarker);	
		
	}
}

function setDirections(from) {
	localSearch.setSearchCompleteCallback(null, 
		function() {
			if (localSearch.results[0]) {    
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var points = Array();
				points[0] = new GLatLng(resultLat,resultLng);
				points[1] = new GLatLng(53.244596418618606, -1.4147686958312988); //office
				gdir.loadFromWaypoints(points);
				document.getElementById('map_directions_print').style.display = 'block';
			}
			else{
				handleErrors();
			}
		});  
	localSearch.execute(from + ", UK");
}

function onGDirectionsLoad(){ 
	evolutedMarker.hide();
}

function handleErrors(){
	alert("Address could not be found");
}

function clearBox(f) {
	if(f.value==f.defaultValue) {
		f.value = '';	
	}
}

function restoreBox(f) {
	if(f.value=='') {
		f.value = f.defaultValue;	
	}
}


function sz(t) {
	a = t.value.split('\n');
	b=1;
	for (x=0;x < a.length; x++) {
		if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
	}
	b+= a.length;
	if (b > t.rows) t.rows = b;
}

function fixPNG() {
	if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) {
		document.styleSheets[0].addRule('img', 'behavior: url(/iepngfix.htc)');
	}
}
