// JavaScript Document
function homeHeights(){
	
	var boxHeight1 = $("#box1").height()+parseInt($("#box1").css("paddingTop"))+parseInt($("#box1").css("paddingBottom"));
	var boxHeight2 = $("#box2").height()+parseInt($("#box2").css("paddingTop"))+parseInt($("#box2").css("paddingBottom"));
	var boxHeight3 = $("#box3").height()+parseInt($("#box3").css("paddingTop"))+parseInt($("#box3").css("paddingBottom"));
	var boxHeight4 = $("#box4").height()+parseInt($("#box4").css("paddingTop"))+parseInt($("#box4").css("paddingBottom"));
	var boxHeight5 = $("#box1").height()+parseInt($("#box5").css("paddingTop"))+parseInt($("#box5").css("paddingBottom"));
	
	var newHeight = Math.max(boxHeight1, boxHeight2);
	newHeight = Math.max(newHeight, boxHeight3);
	newHeight = Math.max(newHeight, boxHeight4);
	newHeight = Math.max(newHeight, boxHeight5);
	
	$("#box1").css("height", newHeight-15);
	$("#box2").css("height", newHeight);
	$("#box3").css("height", newHeight);
	$("#box4").css("height", newHeight);
	$("#box5").css("height", newHeight);
	
}

function secondLevelHeights(){
	var boxHeight1 = $("#section1").height()+parseInt($("#section1").css("paddingTop"))+parseInt($("#section1").css("paddingBottom"));
	var boxHeight2 = $("#section2").height()+parseInt($("#section1").css("paddingTop"))+parseInt($("#section2").css("paddingBottom"));
	var boxHeight3 = $("#section3").height()+parseInt($("#section1").css("paddingTop"))+parseInt($("#section3").css("paddingBottom"));
	var boxHeight4 = $("#section4").height()+parseInt($("#section1").css("paddingTop"))+parseInt($("#section4").css("paddingBottom"));
	
	var newHeight = Math.max(boxHeight1, boxHeight2);
	
	$("#section1").css("height", newHeight);
	$("#section2").css("height", newHeight);
	
	newHeight = Math.max(boxHeight3, boxHeight4);
	
	$("#section3").css("height", newHeight);
	$("#section4").css("height", newHeight);
}

function template3Heights(){
	var boxHeight1 = $("#textCol").height()+parseInt($("#textCol").css("paddingTop"))+parseInt($("#textCol").css("paddingBottom"));	
	var boxHeight2 = $("#imageCol").height()+parseInt($("#imageCol").css("paddingTop"))+parseInt($("#imageCol").css("paddingBottom"));
	
	if(boxHeight1 < boxHeight2){
		$("#textCol").css("height", boxHeight2-25);	
	}
}

function template3DirectionsHeights(){
	var boxHeight1 = $("#textCol").height()+parseInt($("#textCol").css("paddingTop"))+parseInt($("#textCol").css("paddingBottom"));	
	var boxHeight2 = $("#map").height()+parseInt($("#imageCol").css("paddingTop"))+parseInt($("#imageCol").css("paddingBottom"));
	
	if(boxHeight1 < boxHeight2){
		$("#textCol").css("height", boxHeight2-25);	
	}else{
		$("#map").css("height", boxHeight1);	
	}
}

function submitForm(){
	postcode = document.directions.saddr.value;
	postCodeTo = document.directions.daddr.value;
	var url = "http://maps.google.co.uk/maps?daddr="+ postCodeTo + "&saddr=" + postcode;
	window.open(url, "_blank");
}

function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(55.951915, -3.203502), 13);
        var point = new GLatLng(55.951915, -3.203502);
        var marker = new GMarker(point);
        map.addOverlay(marker); 
        
        //GEvent.addListener(marker, "click", function() {
   				 marker.openInfoWindowHtml("<strong>The Alliance Scotland</strong><form name='directions' action=\"http://maps.google.co.uk/maps\" onsubmit='submitForm(); return false;' method=\"get\">Enter your postcode to get directions:<br/><input type=\"text\" name=\"saddr\" id=\"saddr\" value=\"\" /> <a href='javascript:submitForm()'>Go</a><input type=\"hidden\" name=\"daddr\" value=\"55.951915, -3.203502\" /><input type=\"hidden\" name=\"hl\" value=\"en\" /><br/></form>");
 		 //});
		 
		 GEvent.addListener(marker, "click", function() {
   				 marker.openInfoWindowHtml("<strong>The Alliance Scotland</strong><form name='directions' action=\"http://maps.google.co.uk/maps\" onsubmit='submitForm(); return false;' method=\"get\">Enter your postcode to get directions:<br/><input type=\"text\" name=\"saddr\" id=\"saddr\" value=\"\" /> <a href='javascript:submitForm()'>Go</a><input type=\"hidden\" name=\"daddr\" value=\"55.951915, -3.203502\" /><input type=\"hidden\" name=\"hl\" value=\"en\" /><br/></form>");
 		 });
        
      }
    }
