/**
 * jDotz
 *
 * @author Lukas Karasek <lukas@karasek.at>
 */
var jDotz = {
   webmode: {
      baseurl: "",
      init: function() {
         if ($( ".dotzmag" ).hasClass('interactive')) {
            $( ".widget-container-sortable" ).sortable('enable');
         } else {
            $( ".widget-container-sortable" ).sortable('disable');               
         }
      },
      observe: function() {
         var _jDotz = this;
         $(document).click(2000,function(){
            $.ajax({
               type: "GET",
               url: _jDotz.baseurl+"?webmode=toggle",
               success: function(response) {
                  if (response.webmode == 'default' || response.webmode == 'interactive') {
                     if (response.webmode == 'interactive') {
                     
                        // Tag body
                        $( ".dotzmag" ).removeClass('default');
                        $( ".dotzmag" ).addClass('interactive');
                        
                        // Enable sortables (and add protection for iframes and stuff)
                        $( ".widget-container-sortable" ).sortable('enable');
                        $( ".widget-container-sortable iframe, .widget-container-sortable .protector" ).parent().prepend('<div class="widget-sortable-protector" style="z-index: 2; position: absolute; left: 0; top: 0; bottom: 0; right: 0;"></div>');
                     
                     } else {
                     
                        // Tag body
                        $( ".dotzmag" ).removeClass('interactive');
                        $( ".dotzmag" ).addClass('default');
                        
                        // Disable sortables (and remove protection for iframes and stuff)
                        $( ".widget-container-sortable" ).sortable('disable');
                        $( ".widget-sortable-protector" ).remove();    
                     
                     }
                  }
               }
            });
         })         
      }
   }
}
