$(document).ready(function() {
	/*
	bgImagesPrefix = "../images/bg_page_";
	bgImagesSuffix = ".jpg";
	bgImagesAvailable = 3;
	randomNumber=Math.floor(Math.random()*bgImagesAvailable)+1;
	$(".page").css("background-image","url('"+bgImagesPrefix+randomNumber+bgImagesSuffix+"')");
	$.timer(10000, function (timer) {
		if (randomNumber > bgImagesAvailable) {
			randomNumber = 1;
		}
		$(".page").css("background-image","url('"+bgImagesPrefix+randomNumber+bgImagesSuffix+"')");
		randomNumber++;
	});
	*/

	currentZIndex = 1;
	currentContent = "Home";
	$(".mapOutside").hide();
	$(".content").hide();
	$("#contentHome").fadeIn(250);

	$(".navigation .menu LI A").click(function(){
		contentName = $(this).parent("LI").attr("id").substring(10);
		if (currentContent != contentName){
			$("#content"+currentContent).fadeOut(250, function(){
				$("#navigation"+currentContent).removeClass();
				$("#navigation"+contentName).attr({className: "active"});
				$("#content"+contentName).fadeIn(250);
				currentContent = contentName;
			});
		}
		return false;
	})

	$("#contentHome h1 a").click(function(){
		contentName = "01";
		$("#content"+currentContent).fadeOut(250, function(){
			$("#navigation"+currentContent).removeClass();
			$("#navigation"+contentName).attr({className: "active"});
			$("#content"+contentName).fadeIn(250);
			currentContent = contentName;
		});
		return false;
	})

	$(".logo A").click(function(){
		if (currentContent != "Home"){
			$("#content"+currentContent).fadeOut(250, function(){
				$("#navigation"+currentContent).removeClass();
				$("#contentHome").fadeIn(250);
				currentContent = "Home";
			});
		}
		return false;
	})

	$(".showMap").click(function(){
		mapName = $(this).attr("id").substring(4);
		$("#mapOutside"+mapName).fadeIn(250);
		$(".mapOutside").draggable();
		$("#mapOutside"+mapName).css("zIndex",currentZIndex);
		currentZIndex++;

		if (GBrowserIsCompatible()) {
			if (mapName == "Whitchurch"){
				var mapWhitchurch = new GMap2(document.getElementById("mapInsideWhitchurch"));
				mapWhitchurch.setCenter(new GLatLng(52.917966,-2.648638), 16);
				mapWhitchurch.addControl(new GSmallMapControl());
		        mapWhitchurch.addControl(new GMapTypeControl());
		        mapWhitchurch.addOverlay(new GMarker(mapWhitchurch.getCenter()));
				mapWhitchurch.openInfoWindowHtml(mapWhitchurch.getCenter(),"<p>Office Building<br />Grocontinental Higher Heath Site<br />Mill Lane<br />Whitchurch<br />SY13 2HF Shropshire</p>");
			}
			if (mapName == "London"){
				var mapLondon = new GMap2(document.getElementById("mapInsideLondon"));
				mapLondon.setCenter(new GLatLng(51.5144,-0.130939), 16);
				mapLondon.addControl(new GSmallMapControl());
		        mapLondon.addControl(new GMapTypeControl());
				mapLondon.addOverlay(new GMarker(mapLondon.getCenter()));
				mapLondon.openInfoWindowHtml(mapLondon.getCenter(),"<p>11 Greek Street<br />W1D 4DJ London</p>");
			}
			if (mapName == "Barcelona"){
				var mapBarcelona = new GMap2(document.getElementById("mapInsideBarcelona"));
				mapBarcelona.setCenter(new GLatLng(41.390252,2.167568), 16);
				mapBarcelona.addControl(new GSmallMapControl());
		        mapBarcelona.addControl(new GMapTypeControl());
		        mapBarcelona.addOverlay(new GMarker(mapBarcelona.getCenter()));
				mapBarcelona.openInfoWindowHtml(mapBarcelona.getCenter(),"<p>Passeig de Gr&agrave;cia 26<br />Principal<br />08007 Barcelona</p>");
			}
		}
		return false;
	})

	$(".hideMap").click(function(){
		mapName = $(this).attr("id").substring(4);
		$("#mapOutside"+mapName).fadeOut(250);
		return false;
	})

	$(".mapOutside").click(function(){
		$(this).css("zIndex",currentZIndex);
		currentZIndex++;
	});
	
	$("#portlogin").submit(function() {
		if($('#user').val() == '' || $('#pass').val() == '') return false;
		$('#pass').val($.md5($('#pass').val()));
		return true;
	});

});