﻿// JScript File
//Declaration: Global Variables.
    //To hold the Current Player Object
    var cp;
    //To hold the Current Playing Media Object
    var cm;
    //Holds the Media duration string
    var mediaDurationDiv;
    //Holds the Player Object ELEMENT Tag
    var playerHolder;
    //Hold the index enumerations of the Array for Low/Medium/High
    var Low = 0;
    var Medium = 1;
    var High = 2;
    //Array holder to accomodate the URLS. Have to be three.
    var cMediaURLs;
    //var DefaultRes = Medium;
    //Actual URL of the media.    
    var mediaURL;
    //Dimensions Max*Minum.
    var maxMediaWidth = 450;
    var maxMediaHeight = 261;
    var minMediaWidth = 150;
    var minMediaHeight = 161;
        
    //Dimensions Width and Height for OBJECT Tag
    var mediaWidth = maxMediaWidth;
    var mediaHeight = maxMediaHeight;
    //Default Volume Level
    var volumeLevel = 10;
    //Max and Minimum volume levels
    var maxVolume = 100;
    var minVolume = 0;
    //Value holding to be used when increasing or decreasing width using [-] or [+] icons.
    var mediaWidthHeightLevel = 50;
    //Current Position of the Media
    var currentPosition=0;
    //To store the Media Title TEXT to be shown above the media.
    var mediaTitle;
    //To store the Media Advertisement Title TEXT to be shown above the media.
    var mediaSubTitle;
    //To store the Media Advertisement Title TEXT to be shown above the media if the AD is Windows MediaAd.
    var mediaSubTitleForWindowsMediaAd;
    mediaSubTitleForWindowsMediaAd='This is an advertisement, your selected video will be played shortly';
    //The div element to store the Title
    var mediaTitleHolder;
    //The div element to store the Advertisement string
    var mediaSubTitleHolder;   
    // Vandana 8 May 2007 : Add two variable to define the Agency name and dateLine
    var mediaAgencyName;   
    var mediaDateLine;   

    var mediaAgencyNameHolder;   
    var mediaDateLineHolder;   
    //To show the advertisement or not
    var isAdToBeShown = false;
    //To set Auto Start or not
    var autoStart = false;
    //Element ID for the Object Tag
    var PlayerID = "Player";
    var ADPlayerID = "AdPlayer";
    //mms server URL - not used;
    var WindowsMediaServerURL;
    //Is the download is a windows media content;
    var isWindowsMediaContent=true;
    var nonWindowsMediaContent='';
    //The advertisement duration the default is 10 seconds. It could be started by setting the value from server side. 
    var AdvtDuration = 50000; // In milli seconds 10000 ms equals 10 seconds
    var AdvtCountDown = AdvtDuration;
    var iconsImagePath = "images/VolumeSlices/";
    var mediaAdSubTitlePrefix = 'This is an advert, your selected video will begin in ';
    var mediaAdSubTitleSuffix = ' seconds.';
    var oneSecond = 1000; // 1000 Milliseconds equals one second;
    //For WMP Detection.
    var isWMPAvailable =true;    
    var isWMPScriptable = false;
    //Objects Holding setTimeOut and setInterval items. 
    //Having setTimeOut and setInterval Items in another objects would help in clearing the same.
    var clearAdTitleTimer;
    var clearAdStopTimer;
    var isAudioProduct = false;
    var AudioContent= '';
    var isWindowMediaAd = false;
    var WindowMediaAdUrl='';
    var maxWindowsMediaAdDuration = 30*oneSecond; //maximum 30 seconds. For Windows Media Advt. :)
    var unsupportedBrowserErrorMessage='Sorry, the Windows media player is unavailable in the system or not supported by your browser.';//This is also overwritten by Code behind if set. This error message is thrown when browser does not support
    var MediaUnavailableErrorMessage='Sorry, the media requested could not be played or unavailable';//This is also overwritten by Code behind if set. This is not used for now.
    
//PlayState Change Events
//0	The playback state is undefined.
//1	Playback is stopped.
//2	Playback is paused.
//3	The player is playing a stream.
//4	The player is scanning a stream forward.
//5	The player is scanning a stream in reverse.
//6	The player is buffering media.
//7	The player is waiting for streaming data.
//8	The player has reached the end of the media.
//9	The player is preparing new media.
//10	The player is ready to begin playback.

//Methods implementation

    //TogglePlayerControls- Hides SliderRow, ControlPanel, BandWidthDiv based on true or false for toShow parameter
    function TogglePlayerControls(Visibility)
    {
        if (Visibility==true)
        {
             SetElementDisplay('SliderRow',true);
             SetElementDisplay('ControlPanel',true);
             SetElementDisplay('BandWidthDiv',true);
        }
        else {
                SetElementDisplay('SliderRow',false);
                SetElementDisplay('ControlPanel',false);
                //SetElementDisplay('BandWidthDiv',false);
             }
    }

    //ToggleAdvtControls- Hides Elements related to Advertisement.
    function ToggleAdvtControls(Visibility)
    {
        if (Visibility==true)
        {
             SetElementDisplay('MediaAd',true);
             SetElementDisplay('SkipAd',true);
             SetElementDisplay('MediaSubTitleHolder',true);
        }
        else {
             SetElementDisplay('MediaAd',false);
             SetElementDisplay('SkipAd',false);
             SetElementDisplay('MediaSubTitleHolder',false);
             }
    }
    //Toggles Audio Section
    function ToggleAudioSection()
    {   
        if (isAudioProduct)
            {
               SetElementDisplay('AudioContent',true);
               SetElementDisplay('PlayerHolderControl',false);
               document.getElementById('AudioContent').innerHTML = AudioContent;
            }
        else 
            {
                SetElementDisplay('AudioContent',false);
                SetElementDisplay('PlayerHolderControl',true);
            }
    }

//The initial method to show the advertisement and kick off the media playing after the specified duration.
    function ShowAdvertisement()
    {
        try{
            //Title is not shown when ad is displayed
           /*Vishwak Team: 27 Feb 2007. Title Should be shown always. Requirement Changed :) */
                        mediaTitleHolder =document.getElementById('MediaTitleHolder');
            	        mediaTitleHolder.innerHTML=mediaTitle;
            	    
            	    // Vandana : 8 May 07    
                    var mediaAgencyNameHolder = document.getElementById('mediaAgencyNameHolder');
                    if(mediaAgencyNameHolder != null)
                        mediaAgencyNameHolder.innerHTML = mediaAgencyName;
                    
                    var mediaDateLineHolder = document.getElementById('mediaDateLineHolder');
                    if(mediaDateLineHolder != null)
                        mediaDateLineHolder.innerHTML = mediaDateLine;
            //Ad to be skipped in case of non windows media content as per 15 Feb 2007 requirement.            
            if (isAdToBeShown == true && isWindowsMediaContent==true)
                {

                    //Displaying and hiding the required div elements
                    SetElementDisplay('MediaStreamEnded',false);
                    SetElementDisplay('PlayerHolderControl',false);
                    SetElementDisplay('MediaAd',true);
                    SetElementDisplay('SkipAd',true);
                    SetElementDisplay('MediaSubTitleHolder',true);
                    TogglePlayerControls(false);
                    
                    
                    
                    //Setting up the advertisement title
                    document.getElementById('MediaSubTitleHolder').innerHTML = mediaSubTitle;
                   
                    
                    isAdToBeShown = false;
                    
                    try{
                        if (isWindowMediaAd==true)
                        {
                        document.getElementById('MediaSubTitleHolder').innerHTML =mediaSubTitleForWindowsMediaAd;
                        //clearAdStopTimer=setTimeout("StopAdvertisement()",maxWindowsMediaAdDuration);
                        SetMediaAdvt(WindowMediaAdUrl);
                        }
                        else {
                         
                         clearAdTitleTimer=setInterval('changeMediaAdTitle()', oneSecond);
                        //To fire up the media playing after the specified AdvtDuration.
                        clearAdStopTimer=setTimeout("StopAdvertisement()",AdvtDuration);
                        }
                    }catch(e){}
                    
                    
                    
                }
             else {            
                    SkipAdvertisement();
                 }
         }
         
         catch(e){} 
    }
    function changeMediaAdTitle(){
        try{
            if (AdvtCountDown>0){  
                AdvtCountDown  -= oneSecond; 
                document.getElementById('MediaSubTitleHolder').innerHTML = mediaAdSubTitlePrefix + (AdvtCountDown/oneSecond) + mediaAdSubTitleSuffix;
                }
                else {clearInterval(clearAdTitleTimer);}
        }catch(e){}
    }
    
    //Skips the Advertisement and continue loading the media requested
    function SkipAdvertisement()
    {
            try
            {
                isAdToBeShown = false;
                 //To fire up the media playing 
                 StopAdvertisement();
             }
             catch(e){}
    }
    //Starting up the media to play
    function StopAdvertisement()
    {
        try
        {     
            if (isAdToBeShown == false)
                {
                    //Hiding all  other than player object. Player object is set to visible in SetPlayerHolder
                    mediaTitleHolder =document.getElementById('MediaTitleHolder');
        	        mediaTitleHolder.innerHTML=mediaTitle;
        	        
        	        // Vandana : 8 May 07
        	        mediaAgencyNameHolder =document.getElementById('MediaAgencyName');
        	        mediaAgencyNameHolder.innerHTML=mediaAgencyName;
        	        
        	        mediaDateLineHolder =document.getElementById('MediaDateLine');
        	        mediaDateLineHolder.innerHTML=mediaDateLine;
        	        
                    SetElementDisplay('MediaStreamEnded',false);            
                    SetElementDisplay('MediaAd',false);
                    SetElementDisplay('SkipAd',false);
                    SetElementDisplay('MediaSubTitleHolder',false);
                    SetElementDisplay('PlayerHolderControl',true);
                                        
                    if (isWindowsMediaContent==true )
                        {
                            SetPlayerHolder(mediaURL);                            
                            //If WMP Unsupported
                            if (isWMPAvailable == true && isWMPScriptable==true)
                            {
                            //Media playing methods.
                            SetElementDisplay('SliderRow',true);
                            SetElementDisplay('ControlPanel',true);
                            SetElementDisplay('BandWidthDiv',true);
                            initPlayer();
                            ToggleAudioSection();
                            }
                            else {TogglePlayerControls(false)};
                            
                        }
                        else {
                            playerHolder.innerHTML = nonWindowsMediaContent;
                            SetElementDisplay('SliderRow',false);
                            SetElementDisplay('ControlPanel',false);
                            SetElementDisplay('BandWidthDiv',false);
                         }
                }
        }
        catch(e){} 
    }

 //The method that is fired from Slider.Js  Method to set the current position to the desired position
    function SetCurrentPosition(NewPosition){
     try{ 
            if (NewPosition!=undefined)   
                {
                              
                    maxWidth =maxMediaWidth;
                    mediaDuration =GetDuration();
                    originalPosition = GetCurrentPosition();
                    //Calculate the desired position in seconds for Media. The NewPosition will be the slider position
                    modifiedPosition = Math.round((NewPosition / maxWidth)*mediaDuration);
                    //Resetting the Media Position.
                    cp.controls.currentPosition = modifiedPosition;                 
                }          
        }
        catch (e){}  
    }
    
    
    
    //Initializing the Media URLs array. Creating the Array.
    function setMediaURLs(url1,url2,url3)
    {    
        try
        {            
            cMediaURLs = new Array(url1,url2,url3);
        }
        catch(e){}        
    }
    
    //This initializes the objects and sets the title. Also calls the method to attach the events
    function initPlayer()
    {
        //initializes some of the global variables.
        try{
            cp = document.getElementById(PlayerID);
	        cm = cp.currentMedia;
	        mediaDurationDiv = document.getElementById('MediaDuration');
	        mediaSubTitleHolder=document.getElementById('MediaSubTitleHolder');	
	        // Vandana : 8 May 2007
	        mediaAgencyNameHolder = document.getElementById('MediaAgencyName');	
	        mediaDateLineHolder = document.getElementById('MediaDateLine');	        
	        //Calls method to attach the events.
            setupFileProperties();
        }
        catch(e){}
        
    }
    
    //This initializes the objects and sets the title for Windows Media AD. Also calls the method to attach the events
    function initAdPlayer()
    {
        //initializes some of the global variables.
        try{
            var cpAdvt = document.getElementById(ADPlayerID);
	        //cmAdvt = cpAdvt.currentMedia;	        
	        //mediaDurationDiv = document.getElementById('MediaDuration');
	        mediaSubTitleHolder=document.getElementById('MediaSubTitleHolder');	     
	           
	        mediaSubTitleHolder.innerHTML='This is an advertisement, your selected video will be played shortly';
	       
            try{               
                cpAdvt.attachEvent("playstatechange", watchMediaAdvt); 
                }
           catch(e){}
        }
        catch(e){}        
    }
    
    //Attaching the events and call to change the slider position.
    function setupFileProperties() {  
        //Attaches the playstatechange event.
        try{
            cp.attachEvent("playstatechange", showFileProperties); 
        }
        catch(e){}      
               
        
        //cp.attachEvent("statuschange", showStatus); 
        
        //Calls the method to change the slider position every second.
        try{setInterval('changeSliderPosition()', oneSecond);}catch(e){}
    }
    //not used for now.
    function showStatus(){
        try{
            var playState = GetPlayState();    
            if (playState==3){             
            }
        }
        catch(e){}
    }
    
    //Gives the current state of the media object.
    function GetPlayState(){
        var currentPlayState = 0;
        try{
        currentPlayState = cp.playState;
        }catch(e){}
        return (currentPlayState);
    }
    
    //Event attached for Media ADvt.
    function watchMediaAdvt(playState){    
//        if (playState==3){
//        //alert(GetDuration());
//        }
         if (playState == 8){        
             StopAdvertisement();
         }
    }
   
    //Event fired up during the play state change.
    function showFileProperties(playState) {    

            try{
                 //Hide the advertisement.
                SetElementDisplay('MediaAd',false);
                //To set the duration string.
                if (playState == 3) 
                    {                    
                        SetElementDisplay('MediaStreamEnded',false);
			SetElementDisplay('MediaBuffer',false);
                        SetElementDisplay('PlayerHolderControl',true);
                        setDurationString();
                        ToggleAudioSection();
                    }
                //To enable the Media stream ended jpg on stopping of the media play
                if (playState == 8)
                {
                    SetElementDisplay('MediaStreamEnded',true);
                    SetElementDisplay('PlayerHolderControl',false);
		    SetElementDisplay('MediaBuffer',false);
                    //Hiding the AudioContent Also - Vishwak team: 2 March 2007
                    SetElementDisplay('AudioContent',false);
                    try{
                    document.getElementById('FastRewindVideo').style.cursor='default';
                    document.getElementById('StopMedia').style.cursor='default';
                    //document.getElementById('PlayMedia').style.cursor='default';
                    document.getElementById('PauseMedia').style.cursor='default';
                    document.getElementById('FastForwardVideo').style.cursor='default';
                    document.getElementById('MuteVideo').style.cursor='default';
                    document.getElementById('VolumeControl1').style.cursor='default';
                    document.getElementById('VolumeControl2').style.cursor='default';
                    document.getElementById('VolumeControl3').style.cursor='default';
                    document.getElementById('VolumeControl4').style.cursor='default';
                    document.getElementById('VolumeControl5').style.cursor='default';
                    document.getElementById('FullScreen').style.cursor='default';
                    document.getElementById('ZoomIn').style.cursor='default';
                    document.getElementById('ZoomOut').style.cursor='default';
                    }catch(e){}
                    
                    
                }
		//To check whether the playstate is buffering or not
                if (playState == 6) 
                    {
                        SetElementDisplay('MediaBuffer',true);
                        SetElementDisplay('PlayerHolderControl',false);                        
                        SetElementDisplay('MediaStreamEnded',false);
                    }
            }
            catch(e){}    
           
        
        }
        
    // A helper method to set the visibility of an element.
    function SetElementDisplay(ControlName, Visibility){
        try{
            var objDisplay =document.getElementById(ControlName);
            if (objDisplay!=null || objDisplay!='undefined')
            {
                if (Visibility)
                {                
                  objDisplay.style.display='inline';
                }
                else {
                    objDisplay.style.display='none';
                }
            }
        }
        catch(e){}
    }
    
       // A helper method to toggle the visibility of the an element.    
    function ToggleDisplay(ControlName){
    try{
        var objDisplay =document.getElementById(ControlName);
        if (objDisplay!=null || objDisplay!='undefined')
        {
            if (objDisplay.style.display =='none')                
                objDisplay.style.display='inline';
            else objDisplay.style.display='none';
        }
       }
    catch(e){}
    }

    //Adjusting the Volume level to desired level. Adheres to the Minimum and Maximum volume levels.
    function AdjustVolume(ChangeVolumeLevel){
        try{
                var currentVolume = cp.settings.volume;
                //var maxVolume = 100;
                //var minVolume = 0;
                if (currentVolume>=minVolume && currentVolume<=maxVolume)
                    {cp.settings.volume = ChangeVolumeLevel;}
                var incVolume = (ChangeVolumeLevel/volumeLevel)
                var baseImageID = 'volume';
                var volImage = 'vol';              
                var imgExtension = '.gif';
                var imgVolumeID;
                var currentImage;
                var onprefix = '_on';
                var offprefix = '_off';
                var onimage;
                var offimage;
                for (var iVolume=0; iVolume<=maxVolume; iVolume+=20)
                {
                    currentImage=baseImageID + iVolume;                    
                    imgVolumeID = document.getElementById(currentImage);
                    onimage = iconsImagePath + volImage + iVolume + onprefix+ imgExtension;;
                    offimage = iconsImagePath + volImage + + iVolume +offprefix+ imgExtension;;
                    //alert(imgVolumeID);
                    if (imgVolumeID!=undefined){   
                        if (ChangeVolumeLevel<iVolume){
                            imgVolumeID.src =  offimage;
                           
                        }
                        else {imgVolumeID.src =  onimage;}
                    }                    
                }
                SetSpeakerImage();
            }
         catch(e){}
    }

    //To increase or decrease the dimension of the object element.
    function ControlPlayerDimensions(IsIncrease)
    {
        try{
            var currentWidth = parseInt(cp.width);
            var currentHeight = parseInt(cp.height);
            if (IsIncrease)
                    {
                    
                        currentWidth +=mediaWidthHeightLevel;
                        currentHeight +=mediaWidthHeightLevel;
                    }
                    
                else 
                   { 
                        currentWidth -=mediaWidthHeightLevel;
                        currentHeight-=mediaWidthHeightLevel;
                   }
                if (currentWidth>maxMediaWidth)        
                        {currentWidth = maxMediaWidth;
                        try{document.getElementById('ZoomIn').style.cursor='default';}catch(e){}
                        } else {try{document.getElementById('ZoomIn').style.cursor='pointer';}catch(e){}}
                if (currentWidth<minMediaWidth)
                {
                   currentWidth = minMediaWidth; 
                   try{document.getElementById('ZoomOut').style.cursor='default';}catch(e){}
                } else {try{document.getElementById('ZoomOut').style.cursor='pointer';}catch(e){}}
                            
                if (currentHeight>maxMediaHeight)        
                        currentHeight = maxMediaHeight;        
                if (currentHeight<minMediaHeight)
                        currentHeight = minMediaHeight;
                cp.width = currentWidth;
                cp.height = currentHeight;
            }
            catch(e){}
    
    }
    
    //Increase or decrease the volume level; This is helpful to increase to the predefined increment/decrement value. But this method is not being used.
    function ControlVolume(IsIncrease){
        try {
            var currentVolume = cp.settings.volume;    
            if (IsIncrease)
                currentVolume +=volumeLevel;
            else 
                currentVolume -=volumeLevel;            
            if (currentVolume>maxVolume)        
                    currentVolume = maxVolume;        
            if (currentVolume<minVolume)
                    currentVolume = minVolume;        
            cp.settings.volume = currentVolume; 
        }
        catch(e){}
    }
    
    
        
    //Mute toggler
	function ToggleMute(){	
        try{
           var isMute = cp.settings.mute; 
           var currentVolume =parseInt(cp.settings.volume); 
           var speakerImg = document.getElementById('SpeakerImage');
           if (isMute==true || currentVolume ==0){
                speakerImg.src = iconsImagePath + "volume_on.gif"
   	            cp.settings.mute=false;
   	            cp.settings.volume=maxVolume;
   	            }
   	        else  {
   	        cp.settings.mute=true;
   	        cp.settings.volume=minVolume;
   	        speakerImg.src = iconsImagePath + "mute_on.gif"
   	        }
        }
        catch(e){}
      	
    }
   //Just debugger method to use what are the attributes available from the current media; 
   function GetAttributes() {
        try{
            var atCount = cm.attributeCount;		
	        for(var i=0; i < atCount; i++){
	           alert( cm.getAttributeName(i) + cm.getItemInfo(cm.getAttributeName(i)));	 
	           }
        }
        catch(e){}

	}
	
	
    
 


   //Retrieves the Media Duration in seconds
   function GetDuration(){
       var mduration =0;
       try{
            mduration = cm['duration'];
        }
        catch(e){}
        return (mduration);
   }
   //Retrieves the Media Duration in string format like 00:00
   function GetDurationString(){
       var mdurationString ='00:00';
       try{
            mdurationString = cm['durationString'];
        }
        catch(e){}
        return (mdurationString);        
   }
   //Rewinds the media to the start;
   function RewindMe() {
        try{
            if (cp.controls.isAvailable('CurrentPosition'))
			    {cp.controls.currentPosition = 0;}	    
        }
        catch(e){}
		  
   }
   
   
   
   //Forwards the media to the end.
   function ForwardMe() {
        try{
            cp.controls.fastForward();
        }
        catch(e){}
       
   }
   //Shows the media for Full Screen.
   function ShowFullScreen(){
        try{	
	        if (cp.playState != 3)
	            StartMeUp();
             if (cp.playState == 3) 
               cp.fullScreen = 'true';
         }
         catch(e) {}
        
   }
   //Plays the Media;
   function StartMeUp() {
       //Resets the slider position to the start if the playstate is not paused;
       try{if (GetPlayState()!=2){A_SLIDERS[0].f_setValue(0)};} catch(e){}
       
       try{
           //Make visible the media;
           cp.style.display='inline';
           cp.controls.play();
           SetSpeakerImage();
           setDurationString();
           }
       catch(e){}
   }
   
   
   
   //To find out whether media is playing.
   function IsMediaPlaying(){
        var mediaPlay = false;
        try{        
            var playState = GetPlayState();
            if (playState==3)    
                {
                mediaPlay = true;
                }
         }
         catch(e) {}
            return mediaPlay;
     }
   //Change slider position when media is being played. It is called through SetInterval call in setupfile properties.
   
   
   function changeSliderPosition(){ 
        try{        
            var currentMediaPosition =0;
            if (IsMediaPlaying())    
                {
                    maxWidth =maxMediaWidth;
                    mediaDuration =GetDuration();
                    currentMediaPosition= GetCurrentPosition();    
                    
                    currentMediaPosition=Math.round(currentMediaPosition);        
                    setDurationString();
                    try{
                    //Calculating the new slider position;
                    sliderPosition= Math.floor((currentMediaPosition/mediaDuration)*maxWidth);
                    //alert(sliderPosition);        
                       A_SLIDERS[0].f_setValue(sliderPosition,1);
                    }
                    catch(e){}
                 }
          }
        catch(e){}
   }
  //This ensures Speaker Image is toggled correctly.
  function SetSpeakerImage()
  {
  try{
        var currentVolume =parseInt(cp.settings.volume);
        var speakerImg = document.getElementById('SpeakerImage');
        if (currentVolume<=0){
                speakerImg.src = iconsImagePath + "mute_on.gif"   	            
   	            }
   	        else{   	        
   	        speakerImg.src = iconsImagePath + "volume_on.gif"
   	        }
   	} catch(e){}
  }
   //Retrieves the Media URL on change of the radio change
   function GetMediaPath(BandWidth){    
        var mediaURL ='';
        try{
            var idxURL = Medium;
            if (BandWidth!=null || BandWidth!='undefined' || BandWidth!='')
            {
               switch (BandWidth.toLowerCase()){
                    case "low":
                        idxURL = Low;
                       break;        
                    case "high":
                       idxURL = High;
                       break;
               }
            }
            mediaURL = cMediaURLs[idxURL];
        }
        catch(e){}
        return (mediaURL);
   }
   //Pause media
   function PauseMe(){
       try{
        cp.controls.pause();
       }
       catch(e){}
   }
   //Stops the media
   function ShutMeDown(){
      try{
        cp.controls.stop();
       }
       catch(e){}
   }
   
   //Retrieves the current Position which is being played
   function GetCurrentPosition(){
       try{         
           if (cp.controls.isAvailable('CurrentPosition'))
			        currentPosition=cp.controls.currentPosition;
	    } catch(e){}
        return (currentPosition);
   }
   
   //Sets the duration of the media as string in the div
   function setDurationString(){
       try{
           var durationText = GetDurationString();
           var durationTextPrefix = 'Duration: ';
           if (durationText!='00:00')      
                mediaDurationDiv.innerHTML = durationTextPrefix + durationText;
                //       if (IsMediaPlaying()){
                //        var currentMediaPosition=GetCurrentPosition();
                //        currentMediaPosition=Math.floor(currentMediaPosition);
                //        mediaDurationDiv.innerHTML += ' Playing ' + currentMediaPosition;
                //        }
           }
           catch(e){}              
   }
   //Toggles the play for the Different type of media bandwidth
   function ToggleMedia(BandWidth){
        var strBandWidth;
        try{
            if (BandWidth!='undefined'){
                var arrayOfChoices= BandWidth.getElementsByTagName('input');  
                for (i=0;i<arrayOfChoices.length;i++){
                        element = arrayOfChoices[i];
                        if (element.type == "radio")
                        {
                            if (element.checked == true)
                            {
                             strBandWidth=element.value;
                            }
                        }
                     }           
                 if (strBandWidth!=null && strBandWidth!='undefined' && strBandWidth!=''){
                   var mediaURL = GetMediaPath(strBandWidth);              
                   ShutMeDown();
                   SetPlayerHolder(mediaURL);
                   initPlayer();     
                   ToggleAudioSection();  
                   StartMeUp();
                   //cp.URL = mediaURL;
                 }
             }
        }
        catch(e){}
   }
   //Retrieves the object tag for media player
   function SetPlayerHolder(MediaURL){
        var mediaHTML = '';
        try{
            if (isWindowsMediaContent==true)
                {
                    mediaHTML=GetMediaPlayerObjectHTML(MediaURL, PlayerID);
                    //alert(mediaHTML);
                 }
            playerHolder.innerHTML = mediaHTML;
         } catch(e){}
         if (mediaHTML =='') {SetElementDisplay('SliderRow',false);
                    SetElementDisplay('ControlPanel',false);
                    SetElementDisplay('BandWidthDiv',false);}
   }
   
    function SetMediaAdvt(AdMediaURL){
        var mediaHTML = '';        
        try{
            
            autoStart=true;            
            mediaHTML=GetMediaPlayerObjectHTML(AdMediaURL, ADPlayerID);
            /////document.write (mediaHTML); 
            
            if (isWMPAvailable == true && isWMPScriptable==true){
            document.getElementById('MediaAd').innerHTML =mediaHTML;
//            var cd = document.getElementById(ADPlayerID);
//            alert(cd.currentMedia['duration']);
            isWindowMediaAd = true;
            initAdPlayer();
            autoStart=false;
            isAdToBeShown=false;
            } else {
                SkipAdvertisement();//for the video to be played automatically in the Mozilla
            }
         } catch(e){}
        SetElementDisplay('SliderRow',false);
        SetElementDisplay('ControlPanel',false);
        SetElementDisplay('BandWidthDiv',false);        
   }
   
   function GetMediaPlayerObjectHTML(MediaURL, wmpid){
        var objMediaHTML = '';
        var detectionResults = detectWMP();


	autoStart = true;
	TogglePlayerControls(false);
	ToggleAdvtControls(false);


        //if and only WMP is available.
        
        //if(detectionResults.installed)
	//    {	
	        isWMPAvailable = true;
          //  isWMPScriptable=true;
	  //    if  (detectionResults.scriptable==false)
	  //      {   
	  //        window.alert("FIreFox");
	 //           autoStart = true;
	           // TogglePlayerControls(false);
	            
	  //      }else
		// {
	//	        isWMPAvailable = true;
	//		//isWMPScriptable=true;
	//		}
        try{
            //Using ActiveX control of version 6.4. Older control methods and properties would change.
            objMediaHTML += '<object id="' + wmpid +'" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading Media... Few moments..." CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"  TYPE="application/x-oleobject" width="'+mediaWidth+'" height="'+mediaHeight+'">';
            if (isAdToBeShown==true)
            {objMediaHTML += '<param name="autoStart" value="'+autoStart+'" />';}
            //objMediaHTML += '<param name="AutoRewind" value="false" />';
            //objMediaHTML += '<param name="balance" value="0" />';
            //objMediaHTML += '<param name="captioningID" value="0" />';
            //objMediaHTML += '<param name="currentMarker" value="0" />';
            //objMediaHTML += '<param name="currentPosition" value="0" />';
            objMediaHTML += '<param name="enableContextMenu" value="false" />';
            //objMediaHTML += '<param name="enabled" value="false" />';
            //objMediaHTML += '<param name="fullScreen" value="false" />';
            //objMediaHTML += '<param name="InvokeURLs" value="false" />';
            //objMediaHTML += '<param name="Mute" value="false" />';
            ////objMediaHTML += '<param name="PlayCount" value="999" />';
            //objMediaHTML += '<param name="Rate" value="1.0" />';
            //objMediaHTML += '<param name="stretchToFit" value="True" />';
            //objMediaHTML += '<param name="uiMode" value="none" />';
            objMediaHTML += '<param name="URL" value="'+ MediaURL +'" />'
            objMediaHTML += '<param name="src" value="'+ MediaURL +'" />'
            objMediaHTML += '<param name="Volume" value="100" />';
            //objMediaHTML += '<param name="windowlessVideo" value="false" />';
            //objMediaHTML += '<param name="SendPlayStateChangeEvents" value="True" />';
            objMediaHTML += '<param name="ShowControls" value="true" />';
            //objMediaHTML += '<param name="ShowDisplay" value="false" />';

            objMediaHTML += '<param name="ShowStatusBar" value="true" />';
            //objMediaHTML += '<param name="ShowTracker" value="True" />';
            //objMediaHTML += '<param name="Loop" value="False" />';
//             <EMBED TYPE="application/x-mplayer2" 
//    PLUGINSPAGE="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=Media&amp;sba=Plugin"
//    SRC="mms://10.1.0.224/htvideos/2007/2/pinball.wmv"
//    NAME="MediaPlayer"
//    WIDTH="184"
//    HEIGHT="90">
//  </EMBED>
             objMediaHTML += '<EMBED TYPE="application/x-mplayer2" id="' + PlayerID +'2" PLUGINSPAGE="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=Media&amp;sba=Plugin" src="' + MediaURL + '" width="'+mediaWidth+'" height="'+mediaHeight+'"  NAME="MediaPlayer" WIDTH="184" HEIGHT="90" ShowControls="1" ShowDisplay="0" ShowStatusBar="1" ShowPositionControls="1" ShowTracker="1" AnimationAtstart="0" autostart="'+ autoStart+'"></EMBED>';
            //objMediaHTML += '<EMBED name="player" id="player2" pluginspage="http://www.microsoft.com/windows/windowsmedia/download/" type="application/x-mplayer2" src="'+MediaURL +'" width="'+mediaWidth+'" height="'+mediaHeight+'" ShowControls=0 ShowDisplay=0 ShowStatusBar=0 autostart=0 autorewind=0 ShowPositionControls=0 ShowTracker=0></embed>'
            objMediaHTML += '</object>';
            //alert(objMediaHTML);
            //document.write (objMediaHTML);
        }
        catch(e){}
      //  }
     //   else 
     //       {
     //       objMediaHTML = '<div class=\"downloadavlinks\"><h4>'+ unsupportedBrowserErrorMessage +'</h4></div>'
     //       }            
       return objMediaHTML;
   }
   
  
   //Detecting WMP
//Detect ActiveX Architecture on Both IE and on Gecko
//Defer to plugin architecture for other browsers
//http://devedge-temp.mozilla.org/viewsource/2003/windows-media-in-netscape/first-detection.js.txt
function detectWMP()
{
	var wmpInfo = {
		installed: false,
		scriptable: false,
		type: null,
		versionInfo: null
	};
	var wmp64 = "MediaPlayer.MediaPlayer.1";
	var wmp7 = "WMPlayer.OCX.7";
	

	if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject)
	{
		wmpInfo.type = "ActiveX";
		var player = createActiveXObject(wmp7);
		if(player)
		{
			wmpInfo.installed = true;
			wmpInfo.scriptable = true;
			wmpInfo.versionInfo = player.versionInfo;
			return wmpInfo;
		}
		else
		{
			player = createActiveXObject(wmp64);
			
			if(player)
			{
				wmpInfo.installed = true;
				wmpInfo.scriptable = true;
				wmpInfo.versionInfo = "6.4";
				return wmpInfo;
			}
			else
			{
				wmpInfo.versionInfo = "none";
				return wmpInfo;
			}
		}
	}
	else if(navigator.mimeTypes)
	{
		wmpInfo.type = "NetscapePlugin";
		
		var player = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
		if(player)
		{	
			
			wmpInfo.installed = true;
			//wmpInfo.scriptable = false;
			wmpInfo.versionInfo = "PluginVersion";
			return wmpInfo;
		}
		return wmpInfo;
	}

}

function createActiveXObject(id)
{
  var error;
  var control = null;

  try
  {
    if (window.ActiveXObject)
    {
      control = new ActiveXObject(id);
    }
    else if (window.GeckoActiveXObject)
    {
      control = new GeckoActiveXObject(id);
    }
  }
  catch (error)
  {
    ;
  }
  return control;
}
	

function printResults()
{
    try{
	    var detectionResults = detectWMP();
	    document.write("Browser architecture supports: " + detectionResults.type + "\n");
	    document.write("Windows Media Player Installed: " + detectionResults.installed + "\n");
	    if(detectionResults.installed)
	    {
		    document.write("Windows Media Scriptable: " + detectionResults.scriptable + "\n");
		    document.write("Windows Media Version: " + detectionResults.versionInfo + "\n");
	    }
	}
	catch(err)
	{}
	
}



