

// VARIABLES THAT MIGHT BE SET IN THE CALLING FILE
	//by default we use an invisible player -- use height and width 0 to make it invisible
	//since if you set the css display attribute to none to hide it, some browsers won't instantiate it
	if (typeof(window['playerWidth']) =="undefined"){
		var playerWidth='0';
	}

	if (typeof(window['playerHeight']) =="undefined"){
		var playerHeight='0';
	}

	if (typeof(window['playerBuffer']) =="undefined"){
		var playerBuffer='10';
	}


	if (typeof(window['playerName']) =="undefined"){
		var playerName='playerEAS';
	}

	if (typeof(window['playerDefaultFIle']) =="undefined"){
		var playerDefaultFIle='';
	}

	if (typeof(window['playerAuto']) =="undefined"){
		var playerAuto='false';
	}

	if (typeof(window['playerScrColor']) =="undefined"){
		var playerScrColor='333333';
	}

	if (typeof(window['playerBkColor']) =="undefined"){
		var playerBkColor='666666';
	}

	//'playerDiv'
	if (typeof(window['playerDivName']) =="undefined"){
		var playerDivName='playerDiv';
	}
	
	if (typeof(window['playerMinVersion']) =="undefined"){
		var playerMinVersion='9.0.115';
	}


//	
	//internal vars that we use for the player that the caller is not going to set
	var player=null;
	var curPlaying=null;
	
	try { var myReady = playerReady;} catch (err){}
	playerReady = function(obj) {
		//alert('test');
		player = document.getElementById(obj['id']); //this does not work with IE but works in every other browser
		addListeners();
		try {
			myReady(obj);
	
		} catch (err){
		}
	}

	//INSTANTIATE THE PLAYER
	var flashvars = {
		width		: playerWidth,
		height		: playerHeight,
		bufferlength	: playerBuffer, //'10',
		file 		:	playerDefaultFIle ,
		autostart : playerAuto,
		screencolor : playerScrColor,
		backcolor : playerBkColor
	}
	
	var params = {
		allowfullscreen: 'false',
		allowscriptaccess: 'always',
		wmode: 'opaque'
		};

	var attributes = {
		'id': playerName,
		'name': playerName
	};
	
	swfobject.embedSWF('/RESOURCES/jwplayer/player-licensed.swf', playerDivName, playerWidth, playerHeight, playerMinVersion, '/RESOURCES/flashdetect/expressInstall.swf', flashvars, params, attributes);
	//Flash version required might be 9.0.115 maybe use 10
	
	

function soundPlayerSetClickActions(){
	var playerCount = 0;
		$(".soundToPlay").click(function(){playItem(this); return false;});
		$(".soundToPlay").each(function(){
			$(this).attr("id", "playerItem" + playerCount);
			playerCount++;
		});	
}

	function setPlayerStatus(label,status){
		//document.getElementById('playerStatus').innerHTML=status;
		//document.getElementById('statusLabel').innerHTML=label;
	}
		
	  function playItem(anObj){
	  	//alert('test');
		if (curPlaying && (curPlaying==anObj.id)){ //if the user clicked on the play/stop button while the sound was playing stop it
				player.sendEvent("PLAY",false);
				$(anObj).removeClass('playing');
				$(anObj).removeClass('waiting');
				curPlaying = null;
				//setPlayerStatus("Now Playing:","Click any item to play");
		} else {
			//document.getElementById('playerStatus').innerHTML=anObj.title;
			$(".waiting").removeClass('waiting');
			$("#" + curPlaying).removeClass("playing");
			$(anObj).addClass("waiting");
			player.sendEvent("LOAD", anObj.href);
			player.sendEvent("PLAY",true);
			curPlaying = anObj.id;
		}
	  }
	  
	function stateListener(obj){
			//alert("State is: " + obj.newstate + " curPlaying is : " + curPlaying );
			//document.getElementById('statusLabel').innerHTML=obj.newstate; //for debug only
			switch(obj.newstate) {
			case "BUFFERING" :
				//document.getElementById('statusLabel').innerHTML="LOADING AUDIO:";
				$("#" + curPlaying).addClass("waiting");
				break;
			case "PLAYING" :
				//document.getElementById('statusLabel').innerHTML="Now Playing:";
				//alert("State is: " + obj.newstate + " curPlaying is : " + curPlaying );
				$("#" + curPlaying).removeClass("waiting");
				$("#" + curPlaying).addClass("playing");
				break;
			case "COMPLETED" :
			case "IDLE" :
				//if the sound has played to completion OR the user pressed stop
				//alert(curPlaying);
				//alert("State is: " + obj.newstate + " curPlaying is : " + curPlaying );
				$("#" + curPlaying).removeClass("playing"); // for some reason this isn't working
				$("#" + curPlaying).removeClass("waiting"); // for some reason this isn't working
				//document.getElementById('statusLabel').innerHTML=obj.newstate + " removing waiting from " + curPlaying;//for debug only 
				curPlaying = null;
				//setPlayerStatus("Now Playing:","Click any item to play");
				//alert('done');
				break;
			}
	}	  
	  
	  function addListeners(){
			player.addModelListener("STATE",'stateListener');
			//document.getElementById('statusLabel').innerHTML='NEW STATE DISPLAYED HERE';//for debug only
	}

	function easCheckFlashVersion(minversion,needFlashDiv){
		// This routine is for displaying the expressinstall swf if the installed flash version isn't adequate
		//it is needed because the soundplayer is often sized too small to be used for the expressinstall.swf (i.e. the sound player
		// is often just a control bar OR even invisible
		//minversion is the minimum version needed by the page
		//needFlashDiv is the ID of a div or span where the expressinstall.swf should be instantiated
		//normally it is in a div whose display is 'none' the display is only changed if the express install
		// needs to be displayed
		
		//assumes that swfobject has been loaded
		// assumes that there is a div with the id "xpressinstall" which will be replaced by the xpressinstall swf
		// if the flash version is not the minimum version
			if (!swfobject.hasFlashPlayerVersion(minversion)) {
				//alert("You need a newer version of Flash. You currently have: " + playerVersionString);
				document.getElementById(needFlashDiv).style.display="block";

				var flashvars = {
					};
			
				var params = {
					allowfullscreen: 'false',
					allowscriptaccess: 'always',
					wmode: 'opaque'
					};
				var attributes = {
					'id': 'xpress',
					'name': 'xpress'
				 	};
				  //214 * 138 is the minimum size possible for the expressinstall.swf
				swfobject.embedSWF('/RESOURCES/flashdetect/expressInstall.swf', 'xpressinstall', '214', '138',"6.1");
			}
		}
	
