// Handle mute functionality. Logic by AP.

// The main problems that will occur with the scripting on this page
// is if the header frame containing the hidden variables
// doesn't load in time for this script to get hold of

// If an error occurs...
function handleError() {
	//alert("handleError() called");
	// ... just load the video with audio by default
	video.write("player");
	document.getElementById("input1").style.background = "transparent url(images/sound.gif) no-repeat center top";
	document.getElementById("input1").style.backgroundColor = "#dedede";
	return true;
}

window.onerror = handleError;

// Check the value of the hidden variable in the header frame
if (!readCookie("volume"))
{
	// AP 15 05 2009 - mute video by default
	createCookie("volume", "mute", 21);

	var video = null;
	var video = new SWFObject("videos/flvplayer.swf","single","176","169","7");
	video.addParam("allowfullscreen","false");
	video.addVariable("file", vidname);
	video.addVariable("image","videos/video.jpg");
	video.addVariable("width","176");
	video.addVariable("height","169");
	video.addVariable("enablejs","true");
	video.addVariable('autostart','true');
	video.addVariable('volume','0');
	video.addVariable('usefullscreen','false');

	video.write("player");
	
	document.getElementById("input1").style.background = "transparent url(images/nosound.gif) no-repeat center top";
	document.getElementById("input1").style.backgroundColor = "#dedede";
	
// If the audio is enabled...
} else if(readCookie("volume") == "sound"){

	// ...load the video object which has 100% sound volume
	var video = null;
	var video = new SWFObject("videos/flvplayer.swf","single","176","169","7");
	video.addParam("allowfullscreen","false");
	video.addVariable("file", vidname);
	video.addVariable("image","videos/video.jpg");
	video.addVariable("width","176");
	video.addVariable("height","169");
	video.addVariable("enablejs","true");
	video.addVariable('autostart','true');
	video.addVariable('volume','100');
	video.addVariable('usefullscreen','false');

	video.write("player");
	
	document.getElementById("input1").style.background = "transparent url(images/sound.gif) no-repeat center top";
	document.getElementById("input1").style.backgroundColor = "#dedede";
	document.getElementById("input1").title = "Click to disable audio";

}else if(readCookie("volume") == "mute"){
	
	// Otherwise load the FOmute object which has 0% volume
	var video = null;
	var video = new SWFObject("videos/flvplayer.swf","single","176","169","7");
	video.addParam("allowfullscreen","false");
	video.addVariable("file", vidname);
	video.addVariable("image","videos/video.jpg");
	video.addVariable("width","176");
	video.addVariable("height","169");
	video.addVariable("enablejs","true");
	video.addVariable('autostart','true');
	video.addVariable('volume','0');
	video.addVariable('usefullscreen','false');

	video.write("player");
	
	document.getElementById("input1").style.background = "transparent url(images/nosound.gif) no-repeat center top";
	document.getElementById("input1").style.backgroundColor = "#dedede";
	document.getElementById("input1").title = "Click to enable audio";
	
}


// If the user clicks the button, change the hidden variable in the header frame as appropriate
// This video frame will reload and load the changed value from the header frame
function toggleMute(){
	if(readCookie("volume") == "sound"){

		var video = null;
		var video = new SWFObject("videos/flvplayer.swf","single","176","169","7");
		video.addParam("allowfullscreen","false");
		video.addVariable("file", vidname);
		video.addVariable("image","videos/video.jpg");
		video.addVariable("width","176");
		video.addVariable("height","169");
		video.addVariable("enablejs","true");
		video.addVariable('autostart','mute');
		video.addVariable('volume','0');
		video.addVariable('usefullscreen','false');
 
		video.write("player");
		
		eraseCookie("volume");		
		createCookie("volume", "mute", 21);
		
		document.getElementById("input1").style.background = "transparent url(images/nosound.gif) no-repeat center top";
		document.getElementById("input1").style.backgroundColor = "#dedede";
		document.getElementById("input1").title = "Click to enable audio";
								
	}else if(readCookie("volume") == "mute"){
	
		var video = null;
		var video = new SWFObject("videos/flvplayer.swf","single","176","169","7");
		video.addParam("allowfullscreen","false");
		video.addVariable("file", vidname);
		video.addVariable("image","videos/video.jpg");
		video.addVariable("width","176");
		video.addVariable("height","169");
		video.addVariable("enablejs","true");
		video.addVariable('autostart','true');
		video.addVariable('volume','100');
		video.addVariable('usefullscreen','false');

		video.write("player");
		
		eraseCookie("volume");					
		createCookie("volume", "sound", 21);
		
		document.getElementById("input1").style.background = "transparent url(images/sound.gif) no-repeat center top";
		document.getElementById("input1").style.backgroundColor = "#dedede";
		document.getElementById("input1").title = "Click to disable audio";					
											
	}
}

