window.addEvent("domready", function(){
	
	
	//-----------------------------
	// initialise fisheye flags //
	//-----------------------------
	new iFishEye({
		container: $("MAC-esque"),
		norm: "L1"
	});
	
	//-----------------------------
	// -- Open links in new windows when rel="external"
	//-----------------------------
	$$("a[rel=external]").each(
		function(item) {
			item.setProperty("target", "_blank");
		}
	);
	
	//-----------------------------
	// -- Add the opacity change on mouseover/out to the flags--//
	//-----------------------------
	// $$ shortcut lets you specify CSS styles paths and return an array of elements
	$$("#MAC-esque img.iFishEyeImg").each(
		function(item) {
			//Set initial opacity
			changeOpac(50, item.id);
			item.addEvents({
				// Use this as a shortcut to the currently selected element
				"mouseenter" : function() {
					changeOpac(100, this.id )
				},
				"mouseout" : function() {
					changeOpac(50, this.id )
				}
			});
		}
	);
	
	//-----------------------------
	// -- navigation animation --//
	//-----------------------------
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

	$$("#menu a").each(
		function(item, index) {
			//Does it have class="selected" ?
			if(!item.hasClass('selected')) {
				var fx = new Fx.Morph(item, {link: 'chain', duration: '300', transition: Fx.Transitions.Back.easeOut});
				//Yuck. Required as otherwise IE doesn't run the animation? Test now one domready event?
				fx.start({"background-position" : "0 0"});
				fx.start({"background-position" : "0 0"});
				fx.start({"background-position" : "0 0"});
				
				//Add the tweens to the backgrounds
				item.addEvents({
					"mouseenter" : function() { 
						fx.start({"background-position" : "0 -43"});
					},
					"mouseleave" : function() { 
						fx.start({"background-position" : "0 0"});
					}
				});	
			}
	});
	
	
	//-----------------------------
	// Set font size reading from cookie
	//-----------------------------
	setFontSizeFromCookie();
	
	//-----------------------------
	// Set font size onclick and set cookie
	//-----------------------------
	$('setTextSmall').addEvent('click', function(event){
		setTheFont('62.5%');
	});
	
	$('setTextMedium').addEvent('click', function(event){
		setTheFont('70%');
	});
	
	$('setTextLarge').addEvent('click', function(event){
		setTheFont('81.25%');
	});

	
	//-----------------------------
	// Hide any 'meet-the-team' lightboxes
	//-----------------------------
	$$('.meet-the-team').setStyle('display','none');
	
});


//-----------------------------
// Change the opacity of an object
//-----------------------------
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}


	
//-----------------------------
// Set font size reading from cookie
//-----------------------------
function setFontSizeFromCookie() {
	var SetFont = Cookie.read('sFont');
	if(SetFont=='62.5%') {
		document.body.style.fontSize='62.5%';
	} else if (SetFont=="70%") {
		document.body.style.fontSize='70%';
	} else if (SetFont=="81.25%") {
		document.body.style.fontSize='81.25%';
	}
}

// Set the font size cookie to maintain this
//-----------------------------
function setTheFont(fsize){	
	var fontCookie = Cookie.write('sFont', fsize, {duration: 7}); //Save font for a week
	document.body.style.fontSize = fsize;
	return false;
}

