function YtPlayer(ytPlayer){
  this._ytPlayer = ytPlayer;
  this.playerState = -1;
  this.controllsContainer = $('#controlls-container');
  this._volume = 100;

  // Funciones uqe manejan los efectos en el player
  this._SetVolume = function(newVolume){
                      newVolume = parseInt(newVolume);
                      if(100<newVolume||newVolume<0) return false;
                      this._ytPlayer.setVolume(newVolume);
                      this._volume = newVolume;
                      this._UpdateStatusVolume(newVolume);
                    }
  this._UpdateStatusVolume = function(newVolume){
                               var icoVolume  = this.icoVolume;
                               var dttdVolume = $('#DottedVolume div');
                               var icoClass   = 'v100';
                               if(70<=newVolume)      icoClass  = 'v100';
                               else if(50<=newVolume) icoClass  = 'v60';
                               else if(20<=newVolume) icoClass  = 'v30';
                               else if(0<newVolume)   icoClass  = 'v10';
                               else if(0==newVolume)  icoClass  = 'v0';
                               var w = Math.floor(newVolume/10)*6;
                               icoVolume.attr('class',icoClass);
                               dttdVolume.width(w);
                             }
  this._ShowHideIcoVol = function(status){
                            if(status=='show'){
                              this.icoVolume.css({'display':'block'});
                              this.btns['pP'].css({'display':'none'});
                            }else{
                              this.icoVolume.css({'display':'none'});
                              this.btns['pP'].css({'display':'block'});
                            }
                         }
  this._reproductionState = 'play';
  this._PlayPause = function(status){
                       var status = this._reproductionState;
                       if(status!='play'){
                         this._ytPlayer.playVideo();
                         this.btns['pP'].attr('class','paused');
                         if(isIE6())
                            this.btns['pP'].css({'background-position':'0 -72px'});
                         if(status=='replay')
                           $('#Player-controlls #controlls-container').removeClass('show');
                         this._reproductionState = 'play';
                       }else{
                         this._ytPlayer.pauseVideo();
                         this.btns['pP'].removeAttr('class');
                         if(isIE6())
                            this.btns['pP'].css({'background-position':'0 0'});                         
                         this._reproductionState = 'paused';
                       }
                    }
   this._FormatMinSec = function(numero){
                         var dS = parseInt(numero);
                         var mm = parseInt(dS/60);
                         var ss = dS%60;
                         if(mm<10) mm='0'+mm;
                         if(ss<10) ss='0'+ss;
                         return mm+':'+ss;
                       }

  // Obtengo los botones
  this.btns = new Array();
  this.btns['vU'] = $('#PlayerBtn-vUp'      , this.controllsContainer);
  this.btns['vD'] = $('#PlayerBtn-vDown'    , this.controllsContainer);
  this.btns['pP'] = $('#PlayerBtn-PlayPause', this.controllsContainer);
  this.icoVolume  = $('#IcoVolume'          , this.controllsContainer);
  this.showTimer  = null; //

  this._intervalTimer = null;
  this.Interval       = function(){var self=this; self._intervalTimer=setInterval(function(){self._UpdateTime();},500);}
  this._UpdateTime    = function(){
                            if(this.playerState==1){
                              if(this.showTimer==null){
                                var div = $('#Player-timer',this.controllsContainer);
                                div.html('<span>00:00</span> / '+this._FormatMinSec(this.Duration()) );
                                this.showTimer = $('span',div);
                              }else{
                                this.showTimer.html( this._FormatMinSec(this.CurrentTime()) );
                              }
                            }else if(this.playerState==0){
                                this._reproductionState = 'replay';
                                $('#Player-controlls #controlls-container').addClass('show');
                                this.btns['pP'].attr('class','replay');
                                if(isIE6())
                                  this.btns['pP'].css({'background-position':'0 bottom'});
                            }
                        }

  // Load video
  this.LoadVideo = function(id,frame){this._ytPlayer.loadVideoById(id,frame);this._SetVolume(100);this._ytPlayer.addEventListener('onStateChange', 'SaveNewState');this.Interval();}
  // Tiempos
  this.Duration    = function(){return this._ytPlayer.getDuration();}
  this.CurrentTime = function(){return this._ytPlayer.getCurrentTime();}

  // Activo las funciones en lo botones
  this._SetActions = function(){
                        var self = this;
                        // Volumen
                        this.btns['vU'].click(function(){self._SetVolume(self._volume+10);})
                                       .hover(function(){self._ShowHideIcoVol('show');},function(){self._ShowHideIcoVol();});
                        this.btns['vD'].click(function(){self._SetVolume(self._volume-10);})
                                       .hover(function(){self._ShowHideIcoVol('show');},function(){self._ShowHideIcoVol();});
                        // Play and pause
                        this.btns['pP'].click(function(){self._PlayPause()});
                     }
  this._SetActions();
}
function SaveNewState(newState){Player.playerState=newState;}
function onYouTubePlayerReady() {
        var ytplayer = document.getElementById("myytplayer");
        Player = new YtPlayer(ytplayer);
        Player.LoadVideo(idYTVideo,0);
}

if(typeof(isIE6)!='function')function isIE6(){if($.browser.msie&&parseInt($.browser.version)<7)return true;return false;}
