YAHOO.widgets.Videos = function(params)
{
  this.pageId=params.pageId;
  this.containerId = params.containerId;
  this.playerId = params.playerId;
  this.thumbnailId = null;
  this.videoUri = null;
  this.videoId=0;
  this.artist=params.artist;
  this.width=params.width; 
  this.height=params.height; 
        
  this.currentlyPlayingTitleContainer=YUD.get(params.currentlyPlayingTitleContainer);

  if(params.auto_load.url ){
    this.play(unescape(params.auto_load.url),
              params.auto_load.video_id,
              params.auto_load.thumbnail_id,
              unescape(params.auto_load.title),
              0);
  }
}

YAHOO.widgets.Videos.prototype =
{
  play: function(videoUri, videoId, thumbnailId, title,autoPlay) 
  {
    this.videoId = videoId;
    if(this.thumbnailId != null) 
    {
      YUD.removeClass(this.thumbnailId, 'selected');
    }
    
    this.thumbnailId = thumbnailId;
    YUD.addClass(this.thumbnailId, 'selected');
    
    this.videoUri = videoUri;
    
    // Not Compatible with iPad
    //flashLoader.loadFlash(this.playerId, videoUri+'&enablejsapi=1&playerapiid=youtube_video', 'youtube_video', this.width,this.height, 'autoplay='+autoPlay+'&rel=0&color1=0xe1600f&color2=0xfebd01&border=0', 'opaque', 'default', 'all', false,true);
    document.getElementById('stageVideoObject').innerHTML = '<object height="320" width="480"><param name="movie" value="' + videoUri + '&amp;hl=en_US&amp;fs=1&amp;autoplay=1"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="' + videoUri + '&amp;hl=en_US&amp;fs=1&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="320" width="480"></object>';
    
    this.currentlyPlayingTitleContainer.innerHTML = title;
    
    log_artist='';
    if(this.artist!=null){
      log_artist='&artist='+escape(this.artist);
    }
    var dest = 0;
    var player=YUD.get(this.playerId);
    window.scrollTo(0,0);
    YAHOO.util.Connect.asyncRequest('GET', 'index.php?action=main.video_log&video_id='+thumbnailId+'&url='+escape(videoUri)+'&from='+this.pageId+log_artist);
  },
  handleYouTubePlayerError: function(error){
    YAHOO.util.Connect.asyncRequest('POST', 'index.php?action=main.invalid_video',null,'&video_id='+this.videoId+'&error='+error + "&post_id=" + document.getElementById('post_id').value);
  }
}


   

