var hideP = 0;
var hideN = 0;
function makenav(){
	$($('#projects')[0]).mouseenter(function(){
		if(hideN != 0)
			hideN = -0.5;
		hideP = 0;
		var el = $($('#projects')[0]).parent().children(".navbox");
		el.fadeIn(200);
		el.mouseenter(function(){
			hideP = 0;
			el.fadeIn(100);
		});
		el.mouseleave(function(){
			hideP = 10.5;
			setTimeout("hidenav()", 100);
		});
		setTimeout("hidenav()", 100);
	});
	$($('#projects')[0]).mouseleave(function(){
		hideP = 10.5;
		setTimeout("hidenav()", 100);
	});
	$($('#news')[0]).mouseenter(function(){
		if(hideP != 0)
			hideP = -0.5;
		hideN = 0;
		var el = $($('#news')[0]).parent().children(".navbox");
		el.fadeIn(200);
		el.mouseenter(function(){
			hideN = 0;
			el.fadeIn(100);
		});
		el.mouseleave(function(){
			hideN = 10.5;
			setTimeout("hidenav()", 100);
		});
		setTimeout("hidenav()", 100);
	});
	$($('#news')[0]).mouseleave(function(){
		hideN = 10.5;
		setTimeout("hidenav()", 100);
	});
};
function hidenav(){
	if(hideP > 0)
		hideP--;
	if(hideN > 0)
		hideN--;								
	
	if(hideP < 0){
		$($('#projects')[0]).parent().children(".navbox").fadeOut(400);
		hideP = 0;
	}
	else if(hideN < 0){
		$($('#news')[0]).parent().children(".navbox").fadeOut(400);
		hideN = 0;
	}

	if(hideN != 0 || hideP != 0)
		setTimeout("hidenav()", 100);
};

function makecontact(){
	try{
		if(!GBrowserIsCompatible())
			return;
	}
	catch(e){
		return;
	}
 
	//place marker
	var point = new GLatLng(51.495200, -0.2275);
 
	//create the map
	window.Map = new GMap2($(".images")[0]);
	Map.addControl(new GLargeMapControl());
	Map.addControl(new GMapTypeControl());
	Map.setCenter(point, 14);
 
	// create the marker
	window.marker = new GMarker(point);
	window.Map.addOverlay(window.marker);
	//marker.openInfoWindowHtml("<h1 style='font-family: arial; font-weight: bold;font-size: 13px; padding: 0px 7px 0px 7px;'>DawnBuild HQ</h1>");
 
};

var curImg = 0;
function setimage(num){
	if(num < 0)
		num = $(".mainimg").length - 1;
	if(num >= $(".mainimg").length)
		num = 0;
	if(num == curImg)
		return;
		
	$($(".mainimg")[curImg]).fadeOut(400, function(){
		$($(".mainimg")[num]).fadeIn(200);											
	});
	curImg = num;
	$(".imgnum").css("font-weight", "normal");
	$($(".imgnum")[num]).css("font-weight", "bold");
};
var maxHeight = 200;
$(document).ready(function(){
	$($(".mainimg")[0]).css("display", "block");
	//add onload function to each image so that when it loads, 
	jQuery.each($(".mainimg"), function(){
		$(this).load(function(){
			if($(this).attr("height") > maxHeight){
				maxHeight = $(this).attr("height");
				$(".images").css("height", maxHeight);
			}
		});
	});
	makenav();
	if(contact)
		makecontact();
});
