/**
 * Settings
 */
var externalLinksInNewWindow    = true; // Show external links in a new window (Emulate target="_blank")
var externalLinksConfirmation   = true; // Ask user for confirmation of new window?



function arrangeMenu() {
	// menu is hidden via css to prevent twitching - so make it visable again
	$('#header-navigation ul').css('display','block');
	$('#header-navigation ul').removeClass('nav');
	var actualWidth = 902;
	var totalLIWidth = 0;
	var newTotalLIWidth = 0;
	var lis = $('#header-navigation ul li');
	lis.each(function(){
    	totalLIWidth += $(this).width();
	});
	// Work out how much padding we need
	var requiredPadding = Math.round(((actualWidth-totalLIWidth)/(lis.length-1))/2);
	// To account for rounding errors, the error is going to be forced into the first tab.
	//var roundingErrorFix = (requiredPadding*lis.length*2)+totalLIWidth-actualWidth;
	// Apply padding to list items
	var i = 1;
	lis.each(function() {
		newTotalLIWidth+=$(this).width();
		//alert('requiredPadding ='+requiredPadding);
		if (i == 1) {
	    	$(this).css('padding-right',requiredPadding+'px');
	    } else if (i == lis.length) {
	    	$(this).css('padding-left',requiredPadding+'px');
	    } else {
	    	$(this).css('padding-left',requiredPadding+'px').css('padding-right',requiredPadding+'px');
	    	newTotalLIWidth+=requiredPadding;
	    }
	    newTotalLIWidth+=requiredPadding;
	    i++;
	});
}


function backgroundHeigth(){
	var windowH = $(window).height();
	var wrapperH =  $('.wrapper').height();
	if (wrapperH < windowH) {
		$('.wrapper').height(windowH);
	}
}

	
	
/*
* set all features to the same height
*/
function fixHeight(){	
	
	/*
	var feature_max_height = 0;
	$('.sameheight').each(function(){
		var myheight = $(this).height();
		if (myheight > feature_max_height) {
			feature_max_height = myheight;
		}
	});
	$('.sameheight').height(feature_max_height);
*/
	var i = 0;
	var previous_height = 0;
	var previous_top = 0;
	$('.sameheight').each(function(){
		var myheight = $(this).height();
		var mytop = $(this).position().top;
		if (!$(this).prev().hasClass('sameheight') || mytop !=previous_top) {
			previous_height = myheight;
			previous_top = mytop;
		} else {
			if (previous_height > myheight) {
				$(this).height(previous_height+1);
			} else {
				previous_height = myheight;
			}
		}
		
		
	});
}
	
// XHTML Strict new windows
// NOTE: For windows to open in new tab/window add rel="external" to the link
function externalLinks(){
    $('a[rel*=external]').live('click', function(e){
        e.preventDefault();
        if(externalLinksConfirmation) {
            if(confirm($(this).attr('href') + "\nwill open in a new window/tab.\n\nDo you want to continue?")) {
                newWindow = window.open($(this).attr('href'), 'mylorWindow');
                newWindow.focus();
            }
        }
        else {
            newWindow = window.open($(this).attr('href'), 'mylorWindow');
            newWindow.focus();
        }
    });
}

function clear_time_out(thistimeout){
	//alert(thistimeout);
	window.clearTimeout(thistimeout);
}
