var timer,gprcTimer;
/*
player.playState
Value 	State 			Description
------------------------------------
0 	  	Undefined 		Windows Media Player is in an undefined state.
1 		Stopped 		Playback of the current media item is stopped.
2 		Paused 			Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location.
3 		Playing 		The current media item is playing.
4 		ScanForward 	The current media item is fast forwarding.
5 		ScanReverse 	The current media item is fast rewinding.
6 		Buffering 		The current media item is getting additional data from the server.
7 		Waiting 		Connection is established, but the server is not sending data. Waiting for session to begin.
8 		MediaEnded 		Media item has completed playback.
9 		Transitioning 	Preparing new media item.
10 		Ready 			Ready to begin playing.
11 		Reconnecting 	Reconnecting to stream.
*/
switch (NewState){
    case 1:
    	document.getElementById("status").innerHTML = "&nbsp;Stopped";
		if ( (global_state == "ended") && (global_play_type == "all")){
			getNextItemFromPlaylist('arryActivePlaylistAsset');
		} 
		else if ( (global_state == "ended") && (global_play_type == "single") ){
			showVideoStopAction();			
			clearInterval(timer);
		} 
		else if ( (global_state == "ended") && (global_play_type == "preRoll") ){
			global_preRoll_cursor = global_preRoll_cursor + 1;			
			
			if ( global_preRoll_cursor < preRollArray.length )
			{
				//alert("ijurq");
				var epassLoginId = getCookie("loginid");
				if ( epassLoginId == "" )
				{
					epassLoginId = "0";
				}	
				
				if ( preRollArray[global_preRoll_cursor].preRollUrl != "" ){
					document.getElementById("status").innerHTML = "Changing media...";
					setTimeout("loadAnotherPreRoll();",1000);
					//alert("abc");
				} 
				else{
					document.getElementById("status").innerHTML = "Changing media...";
					//alert("poi");
					//processDRM(	global_mediaId );
					setTimeout("processDRM(	global_mediaId )",1000);
					global_play_type = "single";		
				}	
				
				if ( preRollArray[global_preRoll_cursor].preRollSecUrl != "" ){
					document.all.divBannerPreRoll.innerHTML = '<a href="'+preRollArray[global_preRoll_cursor].preRollTargetUrl+'" onClick="sendStatsPrerollClick('+epassLoginId+','+preRollArray[global_preRoll_cursor].preRollId+');"><img src="'+preRollArray[global_preRoll_cursor].preRollSecUrl+'"></a>';
				} 			
			} 
			else
			{				
				document.getElementById("status").innerHTML = "Changing media";
				setTimeout("processDRM(	global_mediaId )",1000);
				//processDRM(	global_mediaId );
				global_play_type = "single";		
			}
		} 
		else if ( (global_state == "ended") && (global_play_type == "preRollAll") ){
			getNextItemFromPlaylist('arryActivePlaylistAsset');		
		}
		if((gbActionBy == "user") && (gbVideoName != "") && (gbVideoName != "undefined")){
			s.Media.stop(gbVideoName,'0');
		}
		break;
    case 2:
    	document.getElementById("status").innerHTML = "&nbsp;Paused.";
		global_state = "paused";
		break;
    case 3:
    	document.getElementById("status").innerHTML = "&nbsp;Playing...";
		if ( global_state == "outside region" ){
			stopMediaPlayer();
		} 
		else{
			global_state = "playing";
		}
		timer = setInterval("showPositionInfo()",1000);		
		if((gbActionBy == "user") && (gbVideoName != "") && (gbVideoName != "undefined")){
			if((typeof(s.Media.play(gbVideoName,'0')) != "undefined") || (typeof(s.Media.play(gbVideoName,'0')) != null)){  
				s.Media.play(gbVideoName,'0');				
			}			
		}
    	break;
    case 6:
    	document.getElementById("status").innerHTML = "&nbsp;Buffering...";
    	break;
    case 7:
    	document.getElementById("status").innerHTML = "&nbsp;Waiting...";
    	break;
    case 8:
    	document.getElementById("status").innerHTML = "&nbsp;Media Ended.";
		global_state = "ended";		
		if((gbActionBy == "user") && (gbVideoName != "") && (gbVideoName != "undefined")){			
			s.Media.close(gbVideoName,'0');
		}
    	break;
    case 9:
		document.getElementById("status").innerHTML = "&nbsp;Transitioning...";
		break;
    case 10:
		document.getElementById("status").innerHTML = "&nbsp;Ready.";
		if((gbActionBy == "user") && (gbVideoName != "") && (gbVideoName != undefined) && (gbDuration != "") && (gbDuration != "undefined")){			
			var tmpDuration = parseInt(gbDuration)*60;			
			s.Media.open(gbVideoName,tmpDuration,"MediaPlayer");
		}
		break;
    default:
    	document.getElementById("status").innerHTML = "&nbsp;Processing...";
}