/**
 * Librex Javascript Styling
 * 
 * @since 01/10/2007
 * @copyright Profitmaster Systems Ltd.
 * @author Pete Hurst <peterh@profitmaster.co.uk>
 */

/**
 * Fix the height of various page elements
 */
var fixHeight = function(){
	// Get reference to footer element
	var footer = $("#footer");
	// If there's no footer, don't bother trying to fix the page height. This
	// will be Image page or Drill page.
	if (footer.length>0) {
		// Stretch page so footer rests at bottom with a small gap (and account 30 for menu bar)
		var offsetHeight = footer.height()+16;
		$("#page").fillPage(offsetHeight);
		// Stretch the group tree to fill available space
		$("#tree").fillHeight("#page",0);
	}
	// Also stretch its last list item, -6px to account for padding
//	$("#tree>li:last-child").fillHeight("#tree",4);
};

/**
 * Fixes button edges for IE6 by moving them outside of their container
 * 
 * This prevents them being masked by the filter area of the container.
 * They must retain the exact client locations after the move.
 */ 
var fixButtonsIE6 = function() {
	// Get container offset
	var contOff;
	// Get all buttons in menu bar (they are the PNG background ones)
	$("#menu .button").each(function(){
		var left = $(this).children(".l");
		var right = $(this).children(".r");
		var leftHeight = left.height();
		var leftWidth = left.width();
		var rightWidth = right.width();
		var midWidth = $(this).width(); 
		left.insertBefore($(this));
		right.insertAfter($(this));
		
		left.css({
			position:"absolute",
			top:0,
			left:1}); // By trial and error, was 1px off
		left.width(leftWidth).height(leftHeight);
		
		right.css({
				position:"absolute",
				top:0,
				// Position from the left, since positioning from the right
				// could sporadically produce 1-pixel gap (presumably due to rounding errors
				// on font widths)
				left:leftWidth+midWidth+1}) // Again the +1 found by trail and error
			 .width(rightWidth)
			 .height(leftHeight);
	});
}

$(function() {
	// Set up the tree expanders/collapsers
	$("#tree").treeExpander(); //fixHeight);
	// Call PMWeb standard setup
	PMWeb.OnLoad();
});

/*
// Call fix routines
if ($.browser.msie && parseInt($.browser.version)==6) {
	// Attach to jQuery onload event
	$(fixButtonsIE6);
}
// Only fix height on non-IE6
// Causes various problems on IE6, not worth it since MS are discontinuing support very soon...
else {
	$(window).load(fixHeight);
}

//$(window).resize(fixHeight);
*/