/*
 *
 *  V.Kondratiev
 *  YouTube2 AddOn
 *
 *
 */

var youtube2 = $.inherit(Module, {

   __constructor: function(moduleDiv) {
      this.__base(moduleDiv);
      this.type = "youtube2";
      this.isResizing = true;
      this.keepAspectRatio = false;
      if( this.draghandle ) {
          this.draghandle.addHelpButton();
      }
   },


   // Function to be called only on published pages. Provides access to ajax functionality on published pages.
   initialize: function() {
      // Get the username and thumbnail count from the database,
      // save them to this object, then load the photos
      //this.getOptionsFromDb( createRef( this,this.loadContent ) );
   },


   // Get the options for this module instance from the database,
   // and possibly perform a callback function afterward
   getOptionsFromDb: function(callbackFunc) {
      _this = this;
      this.ajaxPost('getOptions', {},
         function(data, textSuccess) {
            // Save these options and then possibly call a callback functions
            (callbackFunc || $.noop)(data);
         }
      );
   },


   // This is called as a callback from loadModule.
   // It should also be called directly by modules that overload loadModule and avoid calls to frame2 on init (like customHtml).
   loadModuleCallback: function(data, textStatus) {
      // Store the returned data so we can access it later on
      this.moduleData = data;

      if (this.element.attr('style') == undefined) {
         this.element.css({'width':this.element.parent().width(),'height':this.element.parent().width()*0.5625});
      }
      
      // We need to use innerHTML here because of the (highly probable)
      // chance that the html we get back has <script> in it.  jQuery 1.4
      // tries to be smart and not insert non-standard code.
      this.container[0].innerHTML = data.html;

      // Handle actions to be taken after the saving of this module's settings
      if (this.postSaveData) {
         this.handleModuleSaveResult(this.postSaveData);
         this.setOptionsDb( this.postSaveData.options );
         this.postSaveData = '';
      }
      this.addDragHandle(data);

      // If a module has declared itself resizing, make it so...
      if (this.isResizing) {
            this.addResizing();
      }
   }
});

