$(document).ready(function()
{
	$("a[rel=external]").click(function()
	{
		$(this).attr("target", "_blank");
	})
});

function ResizeStructure()
{
	if($("table.small td.content").height() < 150)
	{
		$("table.small td.content").height(150);
	}

	//$("table.small td.header").innerHeight($("div.middle").height() - $("table.small td.content").height() + "px"); //--old
	$("table.small td.header").height($("div.middle").innerHeight() - $("table.small td.content").innerHeight()); //--new

	$("table.small td.header ul").css("vertical-align","bottom");
	$("table.small td.header h2").css("vertical-align","bottom");

	if($("ul.list").height() > $("td.header").height())
	{
		$("#scrollpane").height($("td.header").height() + "px");
		$("#scrollpane").jScrollPane({scrollbarOnLeft:true, showArrows: true});
	}
	else
	{
		$("#scrollpane").height($("ul.list").height() + 20);
	}


	if(screen.height <= 800)
	{
		var strBackground = $("#body").css("background-image");
		strBackground = strBackground.replace("/backgrounds","/backgrounds/low-res");
		$("#body").css("background-image", strBackground);

	}
	

	if(screen.width <= 1024)
	{
		$("#body").css("font-size","9.5px");

		$("div.left").css("left","0px");
		$("div.left").css("top","20px");
		$("ul.menu").css("width", "285px");
		$("div.middle").css("margin-left","305px");
		$("div.foot").css("height", "30%");
	}
}

function InitializeGoogleMaps(strMapId)
{

	var LatLng = new google.maps.LatLng(50.855532, 2.726398 );

	var myOptions = {
		zoom: 13,
		center: LatLng,
		mapTypeId: google.maps.MapTypeId.HYBRID,
		disableDefaultUI: true,
		navigationControl: true,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		scaleControl: false
	};

	return new google.maps.Map(document.getElementById(strMapId), myOptions);
}


function CreateMarker(googlemaps, objMarker)
{

	if(objMarker.icon !== undefined)
	{
		var Pin = new google.maps.MarkerImage(strPath + 'images/' + objMarker.icon, new google.maps.Size(42, 63));
	}
	else
	{
		var Pin = new google.maps.MarkerImage(strPath + 'images/pin-small.png', new google.maps.Size(21, 32));
	}
	var Marker = new google.maps.Marker({
		position: new google.maps.LatLng(objMarker.lat, objMarker.lng),
		map: googlemaps,
		icon: Pin
	});

	var InfoWindow = new google.maps.InfoWindow({
		content: "<iframe src='" + strPath + "address-google-maps.php?addressno=" + objMarker.addressno + "&map=1' frameborder='0' width='300px' height='150px'></iframe>", size: new google.maps.Size(300,150)
	});

	google.maps.event.addListener(Marker, 'click', function(){
		InfoWindow.open(googlemaps, Marker);
	});
}

function CreateMarkers(googlemaps, arrMarkers)
{

	var GlobalLngLat = new google.maps.LatLngBounds();
	var intGoogleMapsInterval = 0.003;

	for(var i = 0; i < arrMarkers.length; i++)
	{
		var objMarker = arrMarkers[i];
		CreateMarker(googlemaps, objMarker);
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat + intGoogleMapsInterval, objMarker.lng));
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat, objMarker.lng + intGoogleMapsInterval));
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat - intGoogleMapsInterval, objMarker.lng));
		GlobalLngLat.extend(new google.maps.LatLng(objMarker.lat, objMarker.lng - intGoogleMapsInterval));
	}

	if(arrMarkers.length >= 1)
	{
		googlemaps.fitBounds(GlobalLngLat);
	}
}


