/* ***************************************************************************
	User interface setup for Eurofighter
	- initialise menu
	- adjust CSS for selected elements
	- Identify current link in nav
	- SWFObject (embeds flasg without it going in front of everything)
	- jQuery plugins: superfish menu, bgiframe
*************************************************************************** */

$(document).ready(function(){
	$("div#menuv ul").superfish({
		animation : { opacity:"show",height:"show"}
	});

	$("a[@href='"+location.pathname+"']").addClass("selected");
	$("a[@href='"+parenturl+"']").addClass("selectedparent");

	//$("div#menuv ul li li:first-child").addClass("first");
	$("div#menuv ul li li:last-child").addClass("last");
	
	$("div#menuv ul li ul").parent().addClass("submenu").hover(function(){
		$(this).addClass("submenuhover");
	},function(){
		$(this).removeClass("submenuhover");
	});
	
	$("ul.nosubmenu").parent().removeClass("submenu").addClass("nosubmenu");

	$('.styleswitcher').click(function()
	{
		switchStylestyle(this.getAttribute("Title"));
		return false;
	});
	var c = readCookie('style');
	if (c) { switchStylestyle(c); } else { switchStylestyle('Medium'); };

	if(location.search.indexOf('printable')!=-1) { 
		$("body").addClass('printable');
		self.print();
		self.close();
	}
	
	$('#printbutton').click(function() {
		var path = location.href+(location.href.indexOf('?')!=-1?'&printable':'?printable')
		var pwin=window.open(path, 'pwin', 'height=480, width=750, dependent=yes, location=no, menubar=no, personalbar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, z-lock=yes');
	});
	
	$('#keyboardshortcuts a').focus(function(){
		$(this).addClass("show");
	}).blur(function(){
		$(this).removeClass("show");
	})
	
	if($('a[@name=inPageNav]').length==0) { $('#keyboardshortcuts a[@href=#inPageNav]').css('display', 'none'); }
});

// Select or deselect all checkboxes regardless of current 
function checkboxSetAll(curform, newvalue) {
	var inputs = curform.getElementsByTagName('INPUT');
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].getAttribute('type')=='checkbox' && (arguments.length==2 || inputs[i].name==arguments[2])) { inputs[i].checked=newvalue; }
	}
}

// Switch selections - check unchecked, uncheck checked
function checkboxInvertSelection(curform) {
	var inputs = curform.getElementsByTagName('INPUT');
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].getAttribute('type')=='checkbox' && (arguments.length==1 || inputs[i].name==arguments[1])) { 
			inputs[i].checked=!inputs[i].checked;
		}
	}
}

// Select ranges - check two spaced checkboxes and all between will be checked
function checkboxSelectRange(curform) {
	var inputs = curform.getElementsByTagName('INPUT');
	var inrange=false;
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].getAttribute('type')=='checkbox' && (arguments.length==1 || inputs[i].name==arguments[1])) { 
			if (inputs[i].checked) {
				inrange = !inrange;
			} else {
				inputs[i].checked=inrange; 
			}
		}
	}
}
