jQuery(document).ready(function($) {

	$(".external").attr("target", "_blank");


	var site_path = "";
	site_path = (document.location.host == "roy.local") 
		? document.location.protocol + '//' + document.location.host + "/inglis.com.au/httpdocs/" 
		: document.location.protocol + '//' + document.location.host + "/";

	// Pop Window
	$('.popup').click(function() {
		var window_width = 780;
		var window_height = 700;
		var left = (screen.width - window_width) / 2;
		var top = (screen.height - window_height) / 2;

		var popupWindow = window.open(this.href,'','width='+ window_width +',height=' + window_height +',resizable=yes,scrollbars=yes,menubar=yes,toolbar=no,location=no,screenX='+ left +',screenY='+ top +',left='+ left +',top='+ top);
		return false;
	});


	$(".opaq").css('opacity', 0.7);
	$(".opaq_extreme").css('opacity', 0.2);
	$(".opaq_hard").css('opacity', 0.6);

	// only process links that have some where to go - this is more of a tool used during development.
	$("a").bind('click', function() {
		if ($(this).attr('href') == "") {
			return false;
		}
	});

	$(".disabled").each(function() {
		$(this).attr("disabled", "disabled");
	});


	$("form").bind("submit", function() { 

		if (jQuery(this).attr("action") == "") {
			alert('No action set; form can not be submitted.');
			return false;
		}
	});

	if ($("table.outlined").length > 0)
		setTableWidths();

	$('.flash').hide();
	$('.flash').fadeIn('slow', function(){
		setTimeout("$('.flash').fadeOut('slow')", 3000);
	});

	$(".printThis").click(function() {
		window.print();
		return false;
	});

});

function setTableWidths() {

	jQuery("table.outlined").each(function($) { 

		var parentWidth = jQuery(this).parent().width();
		var tableMarginLeft = jQuery(this).css("margin-left");
		var tableMarginRight = jQuery(this).css("margin-right");

		var setTableWidth = parentWidth - tableMarginLeft.replace("px", "") - tableMarginRight.replace("px", "");

		jQuery(this).width(setTableWidth);

	});
}