function setHeight(el, target){
	var elHeight = $(el).height();
	var targetHeight = $(target).height();
	if (elHeight < targetHeight) { $(el).height(targetHeight); }
}

function newWindow(mainHTML, headHTML, footHTML){
	if (!mainHTML) { var mainHTML = ""; }
	if (!headHTML) { var headHTML = ""; }
	if (!footHTML) { var footHTML = ""; }
	
	if (!$("#popupcontent").length){
		$popout = $("<div id=\"popup\"></div>").addClass("popup");
	} else {
		$popout = $("#popup").empty();
		if (!$popout.hasClass("popup")) { $popout.addClass("popup"); }
	}
	
	$popup = $("<div id=\"popupcontent\"></div>");
	$("body").append($popout.append($popup));
	
	$close = $("<a>Close</a>").addClass("close").click(function(){ $("#popup").remove();});
	$popupHead = $("<div id=\"popuphead\"></div>").html(headHTML).prepend($close);
	$popupFoot = $("<div id=\"popupfoot\"></div>").html(footHTML);
	$popup.html(mainHTML);
	$popout.prepend($popupHead).append($popupFoot);

	$popout.css({
		position:"absolute",
		top:($(window).height()-$popout.outerHeight())/2,
		left:($(window).width()-$popout.outerWidth())/2
	});
}

$(document).ready(function(){
// Auto stetch main content if too short
// Kind of a hack.
	setHeight("#main", "#childnavigation");

//Auto select in text boxes
	$(":input[type=text]").focus(function(){ this.select(); });
	
//Hovers for buttons and images
	$(".over")
		.mouseover(function(){
			var cur = $(this).attr("src");
			path = cur.substring(0,cur.lastIndexOf('/')+1);
			file = cur.substring(cur.lastIndexOf('/')+1, cur.indexOf('.'));
			ext  = cur.substring(cur.indexOf('.')+1, cur.length);
			$(this).attr("src",path+file+"_over."+ext);
		})
		.mouseout(function(){
			var cur = $(this).attr("src");
			path = cur.substring(0,cur.lastIndexOf('/')+1);
			file = cur.substring(cur.lastIndexOf('/')+1, cur.indexOf('_over'));
			ext  = cur.substring(cur.indexOf('.')+1, cur.length);
			$(this).attr("src",path+file+"."+ext);
		});
		
		$('.scrollbar').jScrollPane({ scrollbarWidth:23,showArrows:true });
});