/**
 * Controls the Drag & Drop actions for the page menu.
 *
 * When an item ".ui-draggable" is drag on top of an item ".ui-droppable" the box's aperture is light and a character
 * is displayed in the box's bottom hole. If item ".ui-draggable" is drop or move outside of the ".ui-droppable" area
 * the box recover its normal status.
 * Once ".ui-draggable" is drop into the ".ui-draggable" area, a new page will be loaded.
 */
 
jQuery(document).ready(function(){

  // Set draggable items
  jQuery(".ui-draggable").draggable({
    revert: "valid",
    opacity: 0.5
  });
  
  // Set droppable items
  jQuery(".ui-droppable").droppable({ 
    accept: ".page_item", 
    activeClass: "ui-droppable-active",
    hoverClass: "ui-droppable-hover",
    over: function(e) {
      $("#header-content").addClass("box-top-lit");
      $("#little-monster").show();
    },
    out: function(e) {
      $("#header-content").removeClass("box-top-lit");
      $("#little-monster").hide();
    },
    drop: function(ev, ui) {
      /* This code use the get method to display the page's content and avoid to load the entire page, except if the page where we want to go is the list of post.
      
      if (jQuery("#" + ui.draggable.attr("id") + " a:first").attr('title') == 'Blog') {
        window.location = jQuery("#" + ui.draggable.attr("id") + " a:first").attr('href');
      } 
      else {
        jQuery('#content').html("Loading new page...");
        $.get("/wp-content/themes/altrugon/ajax_page.php", { page_class: ui.draggable.attr("class") },
          function(data){
            jQuery('#content').hide();
            jQuery('#content').html(data);
            jQuery('#content').show('slow');
        });
      }*/
      window.location = jQuery("#" + ui.draggable.attr("id") + " a:first").attr('href');
      $("#header-content").removeClass("box-top-lit");
      $("#little-monster").hide();
      ui.draggable.revert = true;
    } 
  });
    
});