
//===========================================
//===========================================
//CONTROL:   MEDIAPLAYER
//DATE:      23/05/2007
//AUTHOR:    OTÁVIO DIAS
//VERSION:   1.2
//===========================================
//===========================================

System.Controls.MediaPlayer = $class();

//ObjControl
System.Controls.MediaPlayer.objControl = new Hashtable();

//Dependency
Type.setDependency('System.Page.UI.Dragger');
Type.setDependency('System.Controls.Slider');

//Alias
Type.registerClassAlias(System.Controls.MediaPlayer, 'MediaPlayer');

//---------------------
//Enums
//---------------------

//PUBLIC:
var playerError = {
    embedDisabled: 0,
    loadVideo: 1
};

//PUBLIC:
var playerStatus = {
    stopped: 0,
    paused: 1,
    playing: 2,
    scanForward: 4,
    scanRewind: 5, 
    ready: 6,   
    waiting: 3,
    closed: 8,
    playing2x: 9
};

//---------------------
//Class
//---------------------

System.Controls.MediaPlayer.prototype = {
    //PUBLIC:
    initialize: function(div){
        
        //PRIVATE: Properties
        this.obj = null;
        this.player = MediaPlayer.ui.detectActiveX();        
        this.div = (typeof div == 'object' ? div : $(div)); //DivPlayer
        this.id = this.div.id;
        this.config = {};
        this.config.isMac = (navigator.platform.indexOf('Mac') != -1);
	this.config.isSafari = (navigator.userAgent.indexOf('Safari') != -1);
        this.config.isFirefox = (navigator.userAgent.indexOf('Firefox') != -1);
        this.slider = {
            video: null,
            volume: null
        };
        this.timerBar = null;
        this.disposed = false;
        this.slider.btnVideo = null;
        this.slider.divVideo = null;
        this.slider.btnVolume = null;
        this.slider.divVolume = null;
        this.slider.directionVideo = null;
        this.slider.directionVolume = null;
        this.autoStart = false;
        this.oldState = 3;
        
        //PUBLIC: Properties
        this.url = '';
        this.height = 240;
        this.width = 320;
        this.minWidth = this.width;
        this.minHeight = this.height;
        this.maxWidth = this.width;
        this.maxHeight = this.height;
        this.enableEmbed = true;  
        this.fullscreenMessage = null;    
        this.startPosition = 0;  
        this.endPosition = 0;
        this.maxDuration = 0;
        this.currentPosition = 0;
        this.isEmbedPlayer = (!this.player.isActiveX);
        this.sliderVideoBgColor = 'red';
        this.sliderVolumeBgColor = 'red';
        this.sliderVideoBgImage = null;
        this.sliderVolumeBgImage = null;
        
        //PUBLIC: Events
        this.onError = null;
        this.onPause = null;
        this.onPlay = null;
        this.onStop = null;
        this.onForward = null;
        this.onRewind = null;
        this.onPlaying = null;
        this.onBuffering = null;
        this.onPlay2x = null;
        this.onMute = null;
        this.onReady = null;
        this.onChangeVolume = null;
        this.onChangePosition = null;
        
        //PRIVATE: ObjControl
        MediaPlayer.objControl.add(this.id, this);
    },
    //===============================
        
    //PUBLIC:
    init: function(){
        if(!this.isEmbedPlayer){
            //ActiveX Player
            if(this.disposed){
                if(this.slider.divVideo!=null){
                    this.setSliderVideo(this.slider.divVideo, this.slider.btnVideo, this.slider.directionVideo);                
                }            
                if(this.slider.divVolume!=null){
                    this.setSliderVolume(this.slider.divVolume, this.slider.btnVolume, this.slider.directionVolume);
                }
                this.disposed = false;
            }
            
            if(this.slider.video != null){
                if(this.sliderVideoBgColor != null){
                    this.slider.video.progressBarColor = this.sliderVideoBgColor;
                }
                if(this.sliderVideoBgImage != null){
                    this.slider.video.progressBarImage = this.sliderVideoBgImage;
                }
            }
            
            if(this.slider.volume != null){
                if(this.sliderVolumeBgColor != null && this.slider.volume != null){
                    this.slider.volume.progressBarImage = this.sliderVolumeBgImage;
                }
                if(this.sliderVolumeBgImage != null){
                    this.slider.volume.progressBarImage = this.sliderVolumeBgImage;
                }
            }
        
            if(this.timer != null){
                clearInterval(this.timer);
            }
            this.timer = setInterval("MediaPlayer.ui.eventManager('" + this.id + "');", 500);
            
            //Iframe Element
            if(!$('NajaWmpObjIframe_' + this.id)){

                var iframe = document.createElement('iframe');
                iframe.id = 'NajaWmpObjIframe_' + this.id;
                iframe.name = 'NajaWmpObjIframe_' + this.id;
                iframe.style.height = this.height + 'px';
                iframe.style.width = this.width + 'px';
                iframe.style.display = 'block';
                iframe.scroll = 'no';
                iframe.scrolling = 'no';
                iframe.style.border = '0px #000000 solid';
                iframe.frameBorder = '0';
                
                this.div.appendChild(iframe);
            }else{
                $('NajaWmpObjIframe_' + this.id).style.display = 'block';	
            }
    	                
            var idFrame = 0;
            for(var i = 0; i < window.frames.length; i++){
                if(window.frames[i].frameElement.id == 'NajaWmpObjIframe_' + this.id){
                    idFrame = i;
                    i = window.frames.length+1;    
                }	        	        
            }
            
            //Html
            var htmlPlayer = this.renderObj();
	    //alert('isEmbedPlayer:' + this.isEmbedPlayer + '\r\n' + htmlPlayer);
            window.frames[idFrame].document.open("text/html","replace");
            window.frames[idFrame].document.write(htmlPlayer);
            window.frames[idFrame].document.close();
            
            this.autoStart = true;
            this.obj = window.frames[idFrame].document.getElementById('NajaWmpObjActiveX_' + this.id);
            
        }else{
            var htmlPlayer = this.renderObj();
	    //alert('ELSE !!!!!!!!!!! isEmbedPlayer:' + this.isEmbedPlayer + '\r\n' + htmlPlayer);
            this.div.innerHTML = htmlPlayer;
        }
    },
    //===============================
    
    //PUBLIC:
    dispose: function(onlySliders){
        if(!this.isEmbedPlayer){
            this.disposed = true;
            if(this.slider.video != null){
                this.slider.video.dispose();
                this.slider.video = null;
            }
            if(this.slider.volume != null){
                this.slider.volume.dispose();
                this.slider.volume = null;
            }
        }
        if(!onlySliders){
            if(!this.isEmbedPlayer){
                if(this.timer != null){
                    clearInterval(this.timer);
                }
                if(this.timerBar != null){
                    clearInterval(this.timerBar);
                }
                this.timer = null;
                this.timerBar = null;
                
                var idFrame = 0;
                for(var i = 0; i < window.frames.length; i++){
                    if(window.frames[i].frameElement.id == 'NajaWmpObjIframe_' + this.id){
                        idFrame = i;
                        i = window.frames.length+1;    
                    }	        	        
                }    	    
                window.frames[idFrame].document.open("text/html","replace");
                window.frames[idFrame].document.write("");
                window.frames[idFrame].document.close(); 
                $('NajaWmpObjIframe_' + this.id).style.height = this.height + 'px';
                $('NajaWmpObjIframe_' + this.id).style.width = this.width + 'px'; 
                $('NajaWmpObjIframe_' + this.id).style.display = 'none';
            }else{  
                this.div.innerHTML = "";                
            }
        }
    },
    //===============================  
    
    //PUBLIC:
    setSliderVideo: function(sld, sld_btn, moveD){
        if(this.player.isActiveX){
            this.slider.btnVideo = (typeof sld_btn == 'object' ? sld_btn : $(sld_btn));
            this.slider.divVideo = (typeof sld == 'object' ? sld : $(sld));   
            this.slider.directionVideo = moveD;  
            this.slider.video = new Slider(this.slider.divVideo, this.slider.btnVideo, moveD);
            this.slider.video.progressBarActive = true;   
            this.slider.video.progressBarColor = this.sliderVideoBgColor;
            this.slider.video.progressBarImage = this.sliderVideoBgImage;
            this.slider.video.onMove = MediaPlayer.ui.setOnChangePosition;
            this.slider.video.onMoveStop = MediaPlayer.ui.setPosition;
            this.timerBar = setInterval("MediaPlayer.ui.setRangeBar('" + this.id + "')", 100);
            MediaPlayer.objControl.add(this.slider.btnVideo.id, this);
        }
    },
    //===============================
    
    //PUBLIC:
    setSliderVolume: function(sld, sld_btn, moveD){
        if(this.player.isActiveX){
            this.slider.btnVolume = (typeof sld_btn == 'object' ? sld_btn : $(sld_btn));
            this.slider.divVolume = (typeof sld == 'object' ? sld : $(sld));   
            this.slider.directionVolume = moveD;  
            this.slider.volume = new Slider(this.slider.divVolume, this.slider.btnVolume, moveD);
            this.slider.volume.progressBarActive = true;   
            this.slider.volume.progressBarColor = this.sliderVolumeBgColor;
            this.slider.volume.progressBarImage = this.sliderVolumeBgImage;
            this.slider.volume.onMove = MediaPlayer.ui.setVolume;
            MediaPlayer.objControl.add(this.slider.btnVolume.id, this);
        }
    },
    //===============================
    
    //PUBLIC:
    setUrl: function(url){
        //Set URL
        this.url = url;
        
        if(this.isEmbedPlayer){
            //Embed
            this.dispose();
            this.init();            
        }else{
            //ActiveX            
            if(!$('NajaWmpObjIframe_' + this.id)){
                this.init();
            }else{
                this.obj.FileName = this.url;
                if(this.slider.video != null){
                    this.setPosition(this.startPosition);
                }
                this.obj.Play();                
                if(this.slider.volume != null){
                    this.setVolume(this.slider.volume.currentValue);
                }
                this.autoStart = true;
            }                         
        }       
    },
    //===============================  
    
    //PUBLIC:
    setVolume: function(nivel){
        this.slider.volume.setPosition(nivel);
    },
    //=============================== 
    
    //PUBLIC:
    setPosition: function(pos){
        MediaPlayer.ui.setPosition(pos, this);
        this.slider.video.setPosition(pos);
    },
    //===============================  
    
    //PUBLIC:
    setDimensions: function(height, width){ 
        try {
            var iframe = $('NajaWmpObjIframe_' + this.id);
            if(width >= this.minWidth && width <= this.maxWidth){
                this.obj.width = width;
                iframe.style.width = width + 'px';
            }
            if(height >= this.minHeight && height <= this.maxHeight){
                this.obj.height = height;
                iframe.style.height = height + 'px';
            }
            this.obj.DisplaySize = 4;
            this.checkResizeFF();
        } catch (e) { }
    },
    //=============================== 
    
    //PRIVATE:
    checkResizeFF: function(){
        MediaPlayer.ui.checkResizeFF(this.id);
    },
    //===============================         
    
    //PUBLIC:
    getType: function(){
        return 'System.Controls.MediaPlayer';
    },
    //===============================
    
    //PUBLIC:
    getStatus: function(){
        try{
            if(this.obj.HasError){                
                return playerStatus.error;
            }else if(this.maxDuration > 0 && this.obj.CurrentPosition >= this.maxDuration){
                this.stop();
                return playerStatus.stopped;                
            }else{
                if(this.obj.PlayState==playerStatus.playing){
                    if(this.obj.Rate == 2){
                        return playerStatus.playing2x;
                    }else{
                        return playerStatus.playing;    
                    }
                }else{
                    return parseInt(this.obj.PlayState);
                }
            }
        }catch(e){
            return 3; //waiting
        }
    },
    //=============================== 
    
    //PUBLIC:
    getBandwidth: function(){
        try{
            return parseInt(this.obj.Bandwidth / 1024);
        }catch(e){
            return 0;
        }
    },
    //=============================== 
    
    //PUBLIC:
    getPosition: function(returnSeconds){
        return MediaPlayer.ui.getPosition(returnSeconds, this);
    },
    //=============================== 
    
    //PUBLIC:
    getVolume: function(){
        return this.slider.volume.currentValue;
    },
    //=============================== 
    
    //PUBLIC:
    getDuration: function(returnSeconds){
        return MediaPlayer.ui.getDuration(returnSeconds, this);
    },
    //===============================  
    
    //PUBLIC:
    play: function(){
        if(!this.isEmbedPlayer){
            this.obj.Rate = 1;
            this.obj.Play();
            //-----------------------
            //PUBLIC Event: onPlay
            if(typeof this.onPlay == 'function'){
                this.onPlay();    
            }
            //-----------------------
        }
    },
    //=============================== 
    
    //PUBLIC:
    stop: function(){
        if(!this.isEmbedPlayer){
            this.obj.Stop();
            //-----------------------
            //PUBLIC Event: onStop
            if(typeof this.onStop == 'function'){
                this.onStop();    
            }
            //-----------------------
        }
    },
    //===============================
    
    //PUBLIC:
    pause: function(){
        if(!this.isEmbedPlayer){
            this.obj.Pause();
            //-----------------------
            //PUBLIC Event: onPause
            if(typeof this.onPause == 'function'){
                this.onPause();    
            }
            //-----------------------
        }
    },
    //===============================

    //PUBLIC:
    forward: function(){
        this.setPosition(this.currentPosition + 5);
    },
    //===============================
    
    //PUBLIC:
    rewind: function(){
        this.setPosition(this.currentPosition - 5);
    },
    //===============================
    
    //PUBLIC:
    mute: function(){
        if(!this.isEmbedPlayer){
            if(this.obj.Mute){
                this.obj.Mute = false;
            }else{
                this.obj.Mute = true;
            }
            //-----------------------
            //PUBLIC Event: onMute
            if(typeof this.onMute == 'function'){
                this.onMute(this.obj.Mute);    
            }
            //-----------------------
        }
    },
    //=============================== 
    
    //PUBLIC:
    play2x: function(){
        if(!this.isEmbedPlayer){
            this.obj.Rate = 2;
            this.obj.Play();

            //-----------------------
            //PUBLIC Event: onPlay2x
            if(typeof this.onPlay2x == 'function'){
                this.onPlay2x();    
            }
            //-----------------------
        }
    },
    //===============================      
    
    //PUBLIC:
    fullscreen: function(){
        if(!this.isEmbedPlayer){
            var troca = true;                
            if(this.fullscreenMessage != null){
                troca = confirm(this.fullscreenMessage);
            }
            if(troca){
                this.obj.DisplaySize = 3;
            }
        }
    },
    //=============================== 
    
    //PUBLIC:
    zoomIn: function(){
        var height = parseInt(this.obj.height / 48 + 1) * 48;
        var width = parseInt(this.obj.width / 64 + 1) * 64;
        this.setDimensions(height, width);
    },
    //===============================   
    
    //PUBLIC:
    zoomOut: function(){
        var height = parseInt(this.obj.height / 48 - 1) * 48;
        var width = parseInt(this.obj.width / 64 - 1) * 64;
        this.setDimensions(height, width);
    },
    //===============================
    
    //PUBLIC:
    zoomMax: function(){
        this.setDimensions(this.maxHeight, this.maxWidth);
    },
    //===============================      
    
    //PUBLIC:
    actualSize: function(){
        this.setDimensions(this.height, this.width);
    },
    //===============================        
    
    //PRIVATE:
    renderObj: function(){
	    var sb = new StringBuilder();
	    
	    if(!this.isEmbedPlayer){
	        sb.append('<html><body style="overflow: hidden; margin: 0px 0px 0px 0px; border: 0px 0px 0px 0px;">');
	    }
	    
        //ActiveX - Only Windows
	    if(!(this.config.isSafari && this.config.isMac)){ 
            sb.appendFormat('<object id="NajaWmpObjActiveX_{2}" name="NajaWmpObjActiveX_{2}" height="{0}" width="{1}" ', this.height, this.width, this.id);
            sb.append(' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95">');
            sb.appendFormat('<param name="FileName" value="{0}" />', this.url);
            sb.appendFormat('<param name="URL" value="{0}" />', this.url);
            sb.append('<param name="AutoSize" value="0" />');
            sb.append('<param name="AutoStart" value="True" />');
            sb.append('<param name="DisplaySize" value="4" />');
            sb.append('<param name="defaultFrame" value="mainFrame" />');                                            
   	    sb.append('<param name="ShowControls" value="0" />');
	    
        }
            
        //Embed Player
        if(this.enableEmbed){        
            sb.appendFormat('<embed id="NajaWmpObjEmbed_{0}" name="NajaWmpObjEmbed_{0}"', this.id);
            if(this.config.isMac) {
                sb.appendFormat(' type="video/x-ms-wmv" src="{0}"', this.url);
            } else {
                sb.appendFormat(' type="application/x-mplayer2" FileName="{0}"', this.url);
            }
            sb.appendFormat(' width="{0}" height="{1}"', this.width,  (this.height + 69));
            sb.append(' showcontrols="1" showpositioncontrols="0" showstatusbar="1" showdisplay="0"');
            sb.append(' displaysize="0"');
            //sb.append(' autosize="1"');
            sb.append(' ></embed>');                 
        }
        
        //Only Windows
        if(!this.config.isSafari){
            sb.append('</object>');
        }       
        
        if(!this.isEmbedPlayer){
            sb.append('</body></html>');
        }
        return sb.toString();
    }
    //===============================
};


//---------------------
//UI
//---------------------

System.Controls.MediaPlayer.ui = {
    objControl: null,
    playerInfo: {},
    tempo: 0,
    muteState: false,
    timerZoomFF1: null,
    timerZoomFF2: null,
    //===============================
    
    //PRIVATE: 
    checkResizeFF: function(id){
        var objControl = MediaPlayer.objControl.getValue(id);        
        if (objControl.config.isFirefox){
            var w = objControl.obj.width;
            var h = objControl.obj.height;
            MediaPlayer.ui.timerZoomFF1 = window.setTimeout('MediaPlayer.ui.resizeFF(' + (w-1) + ',' + (h-1) + ', "' + id + '", MediaPlayer.ui.timerZoomFF1)', 100);
            MediaPlayer.ui.timerZoomFF2 = window.setTimeout('MediaPlayer.ui.resizeFF(' + w + ',' + h + ', "' + id + '", MediaPlayer.ui.timerZoomFF2)', 200);
        }
    },
    //===============================
    
    //PRIVATE: 
    resizeFF: function(w, h, id, timer){
        var objControl = MediaPlayer.objControl.getValue(id);
        objControl.obj.width = w;
        objControl.obj.height = h;
        clearTimeout(timer);
        timer = null;
    },
    //===============================
    
    //PRIVATE: 
    setRangeBar: function(id){
        var objControl = MediaPlayer.objControl.getValue(id);
        var time = MediaPlayer.ui.getDuration(true, objControl);
        if(time != 0 && time != -1){
            objControl.slider.video.setRange(objControl.startPosition, parseInt(Math.round(time)));
            clearInterval(objControl.timerBar);
            objControl.timerBar = null;
        }            
    },
    //===============================
    
    
    //PRIVATE:
    eventManager: function(id){
        var objControl = MediaPlayer.objControl.getValue(id);
        var status = objControl.getStatus();
        
        //IE bug on WMP 6.4
        //----------------------------------
        if(objControl.autoStart){
            if(status == 3 || status == 0){
                objControl.obj.Play();    
            }else{
                objControl.autoStart = false;                
            }
        }
        //----------------------------------
        
        if(status == playerStatus.error){
        
            //Error
            //-----------------------
            //PUBLIC Event: onError
            if(typeof objControl.onError == 'function'){
                objControl.onError({code: objControl.obj.ErrorCode, description: objControl.obj.ErrorDescription});    
            }
            //-----------------------
            
        }else{
            
            var time = MediaPlayer.ui.getPosition(true, objControl);
            var formatedTime = MediaPlayer.ui.getPosition(false, objControl);
            var timeDuration = MediaPlayer.ui.getDuration(false, objControl);
            
        
            //Slider Video
            if(objControl.slider.video != null){
                if(objControl.slider.video.currentValue != time) {
                    objControl.slider.video.setPosition(time);
                }
            }

            //-----------------------
            //PUBLIC Event: onPause
            if(typeof objControl.onPause == 'function' && (objControl.oldState != status) && (status == playerStatus.paused)){
                objControl.onPause();    
            }
            //-----------------------
            //-----------------------
            //PUBLIC Event: onStop
            if(typeof objControl.onStop == 'function' && (objControl.oldState != status) && (status == playerStatus.stopped)){
                objControl.onStop();
            }
            //-----------------------
            //-----------------------
            //PUBLIC Event: onPlay
            if(typeof objControl.onPlay == 'function' && (objControl.oldState != status) && (status == playerStatus.playing || status == playerStatus.playing2x)){
                objControl.onPlay();
            }
            //-----------------------
           //-----------------------
            //PUBLIC Event: onMute
            if(typeof objControl.onMute == 'function' && MediaPlayer.ui.muteState != objControl.obj.Mute){
                MediaPlayer.ui.muteState = objControl.obj.Mute;
                objControl.onMute(objControl.obj.Mute);    
            }
            //-----------------------
            
            //-----------------------
            //PUBLIC Event: onPlaying
            if(typeof objControl.onPlaying == 'function' && (status == playerStatus.playing || status == playerStatus.playing2x)){
                objControl.onPlaying({position: formatedTime, duration: timeDuration});    
            }
            //-----------------------
            
            //-----------------------
            //PUBLIC Event: onBuffering
            if(typeof objControl.onBuffering == 'function' && status == playerStatus.waiting){                
                objControl.onBuffering(objControl.obj.BufferingProgress);    
            }
            //-----------------------

            //-----------------------
            //PUBLIC Event: onForward
            if(typeof objControl.onForward == 'function' && status == playerStatus.scanForward){
                objControl.onForward({position: formatedTime, duration: timeDuration});    
            }
            //-----------------------

            //-----------------------
            //PUBLIC Event: onRewind
            if(typeof objControl.onRewind == 'function' && status == playerStatus.scanRewind){
                objControl.onRewind({position: formatedTime, duration: timeDuration});    
            }
            //-----------------------
            
            //-----------------------
            //PUBLIC Event: onReady
            if(typeof objControl.onReady == 'function' && status == playerStatus.ready){
                objControl.onReady();    
            }
            //-----------------------
        }        
        if (objControl.oldState != status) {
            objControl.oldState = status;
        }
    },
    //===============================
    
    //PRIVATE:
    setVolume: function(nivel, obj){
        try{
            var objControl;
            if(obj == null){
                objControl = MediaPlayer.objControl.getValue(Dragger.ui.obj.id);
            }else{
                objControl = obj;
            }
            var vol = 0;    
            if (nivel > 100) { 
                nivel = 100; 
            } else if (nivel < 0) { 
                nivel = 0; 
            }
        
            if (nivel > 0) { 
                vol = (Math.log(100 + ((nivel - 100) / 1.7)) / Math.log(100) - 1) * 10000; 
            } else { 
                vol = -10000; 
            }

            if (vol > 0) { 
                vol = 0; 
            } else if (vol < -10000) { 
                vol = -10000; 
            }
            objControl.obj.Volume = vol;
            //-----------------------
            //PUBLIC Event: onChangeVolume
            if(typeof objControl.onChangeVolume == 'function'){
                objControl.onChangeVolume(nivel);    
            }
            //-----------------------
        }catch(e){}
    },
    //===============================
    
    //PRIVATE:
    setOnChangePosition: function(pos){
        try{
            var objControl = MediaPlayer.objControl.getValue(Dragger.ui.obj.id);
            var formatedTime = MediaPlayer.ui.formatTime(Math.round(pos));
            var timeDuration = MediaPlayer.ui.getDuration(false, objControl);
            if(objControl.slider.video.click){
                MediaPlayer.ui.setPosition(pos + 1, objControl);
            }
            //-----------------------
            //PUBLIC Event: onChangePosition
            if(typeof objControl.onChangePosition == 'function'){
                objControl.onChangePosition({position: pos, time: formatedTime, duration: timeDuration});    
            }
            //-----------------------
        }catch(e){}            
    },
    //===============================
    
    //PRIVATE:
    setPosition: function(pos, obj){
        var objControl;
        if(obj == null){
            objControl = MediaPlayer.objControl.getValue(Dragger.ui.obj.id);
        }else{
            objControl = obj;
        }
        try{
            if(objControl.startPosition == 0 && objControl.maxDuration == 0){
                objControl.obj.CurrentPosition = pos;
                objControl.currentPosition = pos;
            }else{
                if(pos > objControl.maxDuration){
                    objControl.obj.CurrentPosition = objControl.maxDuration; 
                    objControl.currentPosition = objControl.maxDuration;                   
                }else{
                    objControl.obj.CurrentPosition = pos;
                    objControl.currentPosition = pos;
                }                
            }        
        }catch(e){ }
    },
    //===============================
    
    //PRIVATE:
    detectActiveX: function(){
        var playerInfo = {};
//        try{
//            if (window.ActiveXObject) {
//                playerInfo.exists = new ActiveXObject("MediaPlayer.MediaPlayer.1");
//                playerInfo.type = 'activex';
//            } else if (window.GeckoActiveXObject) {
//                playerInfo.exists = new GeckoActiveXObject("MediaPlayer.MediaPlayer.1");
//                playerInfo.type = 'activex';
//            } else {
//                playerInfo.exists = navigator.mimeTypes["application/x-mplayer2"].enabledPlugin;
//                playerInfo.type = 'embed';		
//            }
//        }catch(e){   
//            playerInfo.exists = true;
//            playerInfo.type = 'embed';	
//        }
        var tryPlayer = null;
        playerInfo.exists = false;
        playerInfo.isActiveX = false;
        //playerInfo.version7 = false;
        playerInfo.type = null;
        try 
        {
            if (window.ActiveXObject)
            {
                try { tryPlayer = new ActiveXObject("MediaPlayer.MediaPlayer.1"); }
                catch(e) { }
                playerInfo.exists = (tryPlayer != null);
                playerInfo.isActiveX = true;
                playerInfo.type = 'ActiveXObject';
            }
            if (!playerInfo.exists && window.GeckoActiveXObject)
            {
                try { tryPlayer = new GeckoActiveXObject("MediaPlayer.MediaPlayer.1"); }
                catch(e) { }
                playerInfo.exists = (tryPlayer != null);
                playerInfo.isActiveX = true;
                playerInfo.type = 'GeckoActiveXObject';
            }
            if (!playerInfo.exists && navigator.mimeTypes)
            {
                // Plugin code using navigator.mimeTypes
                try { tryPlayer = navigator.mimeTypes["application/x-mplayer2"].enabledPlugin; }
                catch(e) { 
                    try { tryPlayer = navigator.mimeTypes["video/x-ms-wmv"].enabledPlugin; }
                    catch(e) { }
                }
                playerInfo.exists = (tryPlayer != null);
                playerInfo.isActiveX = false;
                playerInfo.type = 'navigator.mimeTypes';
            }
            if (!playerInfo.exists && navigator.plugins)
            {
                for(var p=0; p<navigator.plugins.length; p++)
                {
                    var plugin=navigator.plugins[p];
                    for (var m=0; m < navigator.plugins[p].length; m++)
                    {
                        var plugin=navigator.plugins[p][m];
                        if(plugin.type == "application/x-mplayer2"
                        || plugin.type == "video/x-ms-wmv")
                        {
                            tryPlayer = plugin;
                            break;
                        }
                    }
                    if (tryPlayer != null)
                    {
                        playerInfo.exists = true;
                        playerInfo.isActiveX = false;
                        break;
                    }
                }
                playerInfo.type = 'navigator.plugins';
		    }
        }
        catch(e) { }
        return playerInfo;
    },
    //===============================
    
    //PRIVATE:
    getPosition: function(returnSeconds, objControl){
        try{  
            var status = objControl.getStatus();      
            if(status == playerStatus.stopped){
                return (returnSeconds ? 0 : "00:00");                
            }else{
                //var objControl = MediaPlayer.ui.objControl;
                if(returnSeconds){
                    return (parseInt(objControl.obj.CurrentPosition) - objControl.startPosition);
                }else{
                    if((parseInt(objControl.obj.CurrentPosition) - objControl.startPosition) > 0){
                        return this.formatTime((parseInt(objControl.obj.CurrentPosition) - objControl.startPosition)).replace(/-1/g,"0");
                    }else{
                        return "00:00";
                    }
                }
            }
        }catch(e){
            return (returnSeconds ? 0 : "00:00");
        }   
    },
    //===============================    
    
    //PRIVATE:
    getDuration: function(returnSeconds, objControl){
        try{
            //var objControl = MediaPlayer.ui.objControl;
            if(objControl.startPosition == 0 && objControl.maxDuration == 0){
                if(returnSeconds){
                    return objControl.obj.Duration;
                }else{
                    return this.formatTime(objControl.obj.Duration);
                }
            }else{
                var total = objControl.maxDuration - objControl.startPosition;
                if(returnSeconds){
                    return total;
                }else{
                    return this.formatTime(total);
                }                
            }
        }catch(e){
            return (returnSeconds ? 0 : "00:00");
        }
    },
    //===============================
    
    //PRIVATE:
    formatTime: function(sec) {
        var h, m, s;
        
        h = parseInt(sec / 3600);
        sec = sec % 3600;
        m = parseInt(sec / 60);
        if(m < 10) {
            m = '0' + m;
        }
        s = parseInt(sec % 60);
        if(s < 10) {
            s = '0' + s;
        }
        return ((h > 0) ? (h + ':') : '') + m + ':' + s;
    }
    //===============================

};

//===========================================
//===========================================