$(document).ready(function(){
	// Navigation :: Primary Nav
	$("#menu li").hoverIntent( {
			over: function() {
				$(this).addClass("hover").find("ul:first").slideDown("fast").fadeTo(100, 0.95);
			},
			out: function() {
				$(this).removeClass("hover").find("ul:first").fadeTo(0, 0.99).hide();
			},
			interval: "10",
			timeout: "10"
		}
	);
	
	// Accessible Target links
	$(".external-window").click( function(e) {
		// Abort if a modifier key is pressed
		if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
			return true;
		} else {
			// Change "_blank" to something like "newWindow" to load all links in the same new window
		    var newWindow = window.open(this.getAttribute('href'), '_blank');
			if (newWindow) {
				if (newWindow.focus) {
					newWindow.focus();
				}
				return false;
			}
			return true;
		}
		
	});
	$(".external-window").attr("title", "Link opens in an external window");
	
	//enableJSClass();
	/*
		** ClientName Specific Components
	*/
	$("#menu li").find("ul:first").fadeTo(0, 0.99);
	
	//$(".equalise .col-box").vjustify();
	equaliseColBox();
	$(".equalise .col-box input.image").click(
		function()
		{
			equaliseColBox();
		}
	);
	
	
	// Login box tabs
	$(".login-set h2 a").click(
		function() {
			mainEle = $(".login-set");
			mainEle.attr("class", "login-set");
			
			mainEle.find("fieldset").removeClass("active");
			thisFieldset = $(this).parents("fieldset");
			mainEle.addClass(thisFieldset.attr("class"));
			thisFieldset.addClass("active");
			
			return false;
		}
	);
	
	$(".expanding-list h2 a").click(
		function() {
			$(this).parents(".expanding-list").find("li.active").removeClass("active");
			$(this).parents("li").addClass("active").find(".details").fadeIn();
			
			return false;
		}
	);
	
	/*insert swfs*/
	if(document.getElementById("intrustTreat")){
		var so = new SWFObject("basemedia/flash/treat.swf", "sotester", "559", "97", "8", "#000000");
		//var so = new SWFObject("/basemedia/flash/treat.swf", "sotester", "595", "262", "8", "#000000");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("wmode", "transparent");
		so.write("intrustTreat");
	}
});

/*
	** Global functions
*/
jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};

jQuery.fn.log = function (msg) {
	console.log("%s: %o", msg, this);
	return this;
};

function enableJSClass() {
	document.body.className = "jsEnabled";
}

function printPage() { 
	if (window.print) { 
		window.print() ; 
	} else { 
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; 
	}
}

function equaliseColBox()
{
	$(".equalise .col-box").vjustify();
	var h = parseInt($(".equalise .col-box").height());
	var nh = h + 60;
	$(".equalise .col-box").css("height", nh+"px");
}