var navHighlight = true;
var otherHighlight = true;
var hasStarted = false;
var isPlaying = false;
var fileID = "";
var player = null; 

function playerReady(thePlayer) { 
	player = window.document[thePlayer.id];
	addListeners();
}

function stateListener(obj) {
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
	if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) endVideo();
}
	
function endVideo() {
	$("#flashvideo").empty().stop().slideUp(1000, this.remove);
	hasStarted = false;
	otherHighlight = true;
	isPlaying = false;
}

function playFlash() {
	if (!isPlaying) {
		isPlaying = true;
		$("#flashvideo").css("height", 362).css("background", "#fff url(http://www.abbeycollege.co.uk/images/layout/loader.gif) 50% 50% no-repeat").stop().slideDown(1000);

		var flashvars = {
				file:"http://www.abbeycollege.co.uk/flash/GS_0" + fileID + "_yuv.flv", 
				autostart:"true",
				frontcolor:"FFFFFF",
				lightcolor:"FFFFFF",
				screencolor:"FFFFFF",
				controlbar:"none",
				displayclick:"none",
				icons:"false"
		}
		var params = {
				allowfullscreen:"true", 
				allowscriptaccess:"always",
				wmode:"transparent"
		}
		var attributes = {
				id:"video",  
				name:"video"
		}
		
		$("#flashvideo").css("background", "#fff");
		$("#flashvideo").append('<div id="video"></div>');
		swfobject.embedSWF("http://www.abbeycollege.co.uk/flash/jwplayer.swf", "video", "450", "362", "9.0.115", false, flashvars, params, attributes);

		$("#flashvideo").append('<a href="#" title="Close" id="closebutton">&nbsp;</a>');
		$("#flashvideo").append('<div style="position:absolute;top:0;left:0;width:450px;height:362px;background:transparent url(http://www.abbeycollege.co.uk/images/layout/player-skin.gif) top left no-repeat"></div>');
		$("#closebutton").unbind().click(function() {
			endVideo();
			return false;
		});	
	}
}

$(document).ready(function(){
	$("#playvideo").click(function() {
		if (!isPlaying) {
			$("#flashvideo").css("height", 362).css("background", "#fff url(http://www.abbeycollege.co.uk/images/layout/loader.gif) 50% 50% no-repeat").stop().slideDown(1000, playFlash);
		}
		return false;
	});
});