  var players = new Array();
  function tube(divId,videoId,wdth,hght,bg,autopl){
    this.idDiv = divId;
    this.videoId = videoId;
    this.id = "player_"+this.idDiv;
    this.height = hght || 356;
    this.width = wdth || 480;
    this.offset = 0;
	this.autopl = autopl;
    if (($.browser.mozilla)||($.browser.opera)) this.offset-=2;
     
    this.bg = bg || "rgb(200,200,200)";
    this.load = function (){
                var params = { allowScriptAccess: "always" , wmode:"transparent"};
                var atts = { id: this.id };
                swfobject.embedSWF("http://www.youtube.com/v/"+videoId+"&rel=0&enablejsapi=1&autoplay="+this.autopl+"&playerapiid="+this.id+"&fmt=18", 
                                   "flash_"+divId, this.width, this.height, "8", null, null, params, atts);                
                }
    this.onstate = function (newstate){
                if (newstate == 0) this.showForm();
                if (newstate == 1) this.showVideo();
                }
    this.init = function(){
                var html = $("#"+this.idDiv).css({position:"relative"}).html();
                
                $("#"+this.idDiv).html("<div id='form_"+this.idDiv+"' style='display:none;position:absolute;left:0px;top:0px;'>"+html+"</div>"+
                                       "<div id='flash_"+this.idDiv+"'></div>"                                          
                                      )   
                $("#form_"+this.idDiv).css({width:this.width+this.offset+"px", 
                                            height:(this.height-25)+"px",
                                            "background-color":this.bg,
                                            "border-left":"1px solid #B5B2B5",
                                            "border-right":"1px solid #B5B2B5",
                                            "border-top":"1px solid #B5B2B5"
                                            });                                  

                }
    this.showForm = function(){
                  $("#form_"+this.idDiv).slideDown(500);
                  this.html.pauseVideo();
                }
    this.showVideo = function(){
                  $("#form_"+this.idDiv).slideUp(500);
                  //this.document.getElementById(this.id).startVideo();
                }
                                           
    var obj = this;
    
    players[this.id] = obj;
                
    $(function(){
      obj.init();
      obj.load();
    })            
  }

  function onYouTubePlayerReady(playerId) {
    var obj = players[playerId]; 
    players[playerId].html = document.getElementById(playerId);
    players[playerId].html.addEventListener("onStateChange", "players['"+playerId+"'].onstate");

  }
  function closeInfo(id){
    players["player_"+id].showVideo();
  }

