$(function() {
	//create tabs, reformat last tab and set overflow

	$('#feature-panels>ul').tabs({
		/*
		cookie expires set to null i.e. session only. Setting the cookie enables the previously 
		active tab to be reloaded if the user navigates away from the page and then clicks 
		the back button
		*/
		cookie:{ expires: null, path: '/', domain: 'anglia.ac.uk'}		    		  
	});

	$("#feature-panels>ul>li:last").css('margin-right', '0').css('width', '141px');

	//reduce height of last navigation item
	$("#audience-navigation li:last").css('height', '-100px');

	//	If the length of the events causes a scroll bar to appear, hide the last event item
	//	RR: Added confdition to prevent resize if in CQ Edit Mode
	if(!cqEditMode)
	{
		if (document.getElementById("forthcoming-events").scrollHeight > document.getElementById("forthcoming-events").clientHeight)
		{
			$(".event-item:last").css('display', 'none');
		}	
	}

	var imageUrl;

	if (cqAuthorMode)
		imageUrl = '/author/medianew/images/google_anglia.jpg';
	else
		imageUrl = '/medianew/images/google_anglia.jpg';
	
	if ($("#words").attr("value") == "")
		$("#words").css("background-image", "url('" + imageUrl + "')").css("background-repeat", "no-repeat").css("background-position", "center center");
	else
		$("#words").css("background-image", "");

	$("#words").blur( function () { if ($("#words").attr("value") == "") $("#words").css("background-image", "url('" + imageUrl + "')").css("background-repeat", "no-repeat").css("background-position", "center center"); } );

	$("#words").focus( function () { $("#words").css("background-image", ""); } );
});

//onload event for checkSWFEmbedSuccess()
$(window).load(function () {
	checkSWFEmbedSuccess();
});


//Script hides relevant jQuery tabs while page loads 
function hideTabsWhileLoading()
{	
	var featurePanelArray = 
	[
		"feature-panels-your-university", 
		"feature-panels-student-essentials", 
		"feature-panels-find-us", 
		"feature-panels-students-union"
	];

	for(count=0;count<featurePanelArray.length;count++)
	{
		if(document.getElementById(featurePanelArray[count]))
		{
			document.getElementById(featurePanelArray[count]).className="ui-tabs-panel ui-tabs-hide";
		}
	}
}


//swfobject embed checks
var swfParentContainer = "media-banner-container";
var swfReplacementContainer = "media-banner";
var fallbackContainer = "media-banner-noscript-content";
var flashInfoContainer = "browser-check-flash-information";
var flashVer = "7.0.0";

//create a message to instruct user that page requires specific version of Flash or greater
var flashPlayerMessage = "The video content used on this site requires Flash version " + flashVer + " or greater"

function locateSWFEmbedObject(objSWFContainer)
{
	/*
	containerObj is the DIV that will be replaced by the SWFObject embed.
	This DIV initially contains some hidden content (in a DIV) that will be used in the 
	event that the embed action fails. In such a scenario the hidden container's content 
	will be written back to containerObj
	*/
	var containerObj = document.getElementById(objSWFContainer);	

	if(containerObj)
	{	
		/*
		this is the parent container that SWFobject will write the swf <object> element to.
		i.e .overwriting containerObj		
		*/
		var swfParentContainerObj = document.getElementById(swfParentContainer);
		var swfParentContainerHTML = swfParentContainerObj.innerHTML;	
		
		/*
		test for successful creation of OBJECT by looking at the inner HTML of the parent 
		container. If no match then the object doesn't exist for some reason
		if the embed failed due to a flash version issue or flash being disabled on the 
		client, the SWFobject script (via PHP) will have handled the issue, as a result, the 
		fallback container object below will not exist as it's contents will have been written to the 
		main media banner container and therefore have been overwritten
		*/
						
		if(swfParentContainerObj && swfParentContainerHTML.match("<object|<OBJECT", "gi")==null)
		{
			/*
			find the fallback container - this is security for the object embed failing 
			due to the SWF host server becoming unavailble i.e. SWFObject can't handle the 
			fallback and the fallback container exists. If this is the case then we need 
			to get it's innerHTML and write it to it's parent container
			*/
			var fallbackObj = document.getElementById(fallbackContainer);

			if(fallbackObj)
			{										
				//get the HTML content from the fallback 
				var fallbackHTML = fallbackObj.innerHTML;			

				//replace the content of the parent container with the static image from CQ
				containerObj.innerHTML = fallbackHTML;			
			}
			else
			{						
				return false;
			}
		}

		else
		{	
				return false;
		}
	}
	else
	{			
			return false;
	}
}

function checkSWFEmbedSuccess()
{
	var swfEmbedCheckTimer = setTimeout("locateSWFEmbedObject('"+ swfReplacementContainer + "')", 5000);
}

//returns an epoch timestamp
function timeStamp()
{
	var theDate = new Date();
	return theDate.getTime();;
}