// When the DOM is ready...
$(document).ready(function(){
	// Setup the submenus to display on hover (IE6 doesn't recognise the CSS pseudo)
	$("#topnav li").hover(
		function(){
			$("ul",this).css("display","block");
		},
		function(){
			$("ul",this).css('display','none');
		}
	);

	// On the /search/search page, focus the text box if it's empty
	if($("#SearchQuery").val() == ""){
		$("#SearchQuery").focus();
	}

	// Random div.photo background
	number_of_photos = 12;
	photo_no = parseInt(Math.random()*parseInt(number_of_photos)+1);
	$(".photo").css("background-image","url('/css/stanstedpc/img/photos/" + photo_no + ".jpg')");
});
// When all the images have loaded...
$(window).load(function(){
	// Add captions to images with the class: caption
	$("div.page img.caption").each(
		function(){
			alt = $(this).attr("alt");
			if(alt != ""){
				$(this).after('<div class="imgcap"><p class="caption">' + alt + '</p></div>');
				$(this).prependTo($(this).next('div.imgcap'));
				if($(this).hasClass("left")){
					$(this).parent().addClass("left");
				}
				if($(this).hasClass("right")){
					$(this).parent().addClass("right");
				}
				$(this).parent().css("width",$(this).width() + "px").find("p").css("width",$(this).width() + "px");
			}
		}
	);

	// Set the main page content and the sidebar DIVs to be of equal heights
	page_height = $("div.page").css("margin-bottom","0").css("padding-bottom","25px").height();
	sidebar_height = $("div.sidebar").css("margin-bottom","0").css("padding-bottom","15px").height();
	if(page_height > sidebar_height){
		$("div.sidebar").css("height",page_height);
		$("div.inner").css("height",page_height-10);
	}
	else {
		$("div.page").css("height",sidebar_height);
		$("div.inner").css("height",sidebar_height-10);
		$("div.sidebar").css("padding-bottom","0px");
	}
});