/**
 * JavaScript by Jeffrey Ouma. Copyright© 2008 artkenya.net Ltd. All rights reserved.
 * 
 * Script name: cpanel.js Description: Defines general functions for CPANEL.NET
 */
// Create the CPANEL Namespace
CPANEL = {}
// Create the CPANEL.Main Namespace
CPANEL.main = {}
CPANEL.main.site = {
  Init: function() {
    try {
      // Initialize variables
      var elm, menuitem, itemArray;
      var imageGroup = new YAHOO.util.ImageLoader.group("bd", "mouseover", 2);
      imageGroup.className = "preload-image";
      // Obtain the table rows from the page
      elm = Dom.get("site-omnilink");
      if(!elm) {
        return false;
      }
      // Use the context menu constructor to create a context menu
      CPANEL.main.site.menu = new YAHOO.widget.ContextMenu("sitemenu", {
        trigger: elm,
        iframe: false,
        zindex: 10,
        effect: {
          effect: YAHOO.widget.ContainerEffect.FADE,
          duration: 0.25
        }
      });
      // Render the context menu (it will remain hidden until the trigger is clicked)
      CPANEL.main.site.menu.render(document.body);
      Dom.removeClass("sitemenu", "hide");
      // Define the site context menu items
      itemArray = CPANEL.main.site.menu.getItems();
      for( var i = 0; i < itemArray.length; i++) {
        if(Dom.hasClass(itemArray[i].element, "sitemenu-selected")) {
          itemArray[i].cfg.setProperty("disabled", true);
          itemArray[i].cfg.setProperty("checked", true);
          itemArray[i].cfg.setProperty("onclick", {
            fn: function() {
              try {
                return false;
              } catch(e) {
                errorHandler(e)
              }
            }
          });
        }
      }
    } catch(e) {
      errorHandler(e)
    }
  },
  Disable: function() {
    try {
      // Initialize variables
      var itemArray;
      // Disable the site context menu items
      itemArray = CPANEL.main.site.menu.getItems();
      for( var i = 0; i < itemArray.length; i++) {
        itemArray[i].cfg.setProperty("disabled", true);
      }
    } catch(e) {
      errorHandler(e)
    }
  }
};
// Initialization function
CPANEL.main.Init = function() {
  try {
    var elm, elmArray;
    // Detect browser and version
    BLEEZ.util.browserDetect.init();
    if(BLEEZ.util.browserDetect.browser == "Firefox" || BLEEZ.util.browserDetect.browser == "Google Chrome"
      || BLEEZ.util.browserDetect.browser == "Safari") { // IE6 detected
      Dom.setStyle("breadcrumbs", "display", "block");
      Dom.setStyle("main", "display", "block");
      Dom.setStyle("navigation", "display", "block");
      // Animate the main content box to fade in
      /*Dom.setStyle(elm, "opacity", "0");
      Dom.removeClass(elm, "hide");
      var anim = new YAHOO.util.Anim(elm, {
        opacity: {
          to: 1
        }
      }, 0.5, Easing.easeOutStrong);
      anim.animate();*/
    } else { // Display the main content box
      if(Dom.get("cpanelpath")) {
        // Redirect to the incompatible browser page
        location.href = Dom.get("cpanelpath").value + "browser/index.php";
      }
    }
    elmArray = Dom.getElementsByClassName("scrub");
    Event.addFocusListener(elmArray, function() {
      try {
        BLEEZ.util.Scrub(this);
      } catch(e) {
        errorHandler(e)
      }
    });
    CPANEL.main.site.Init();
  } catch(e) {
    errorHandler(e)
  }
}
// Execute initialization function after the document has rendered
try {
  Event.onDOMReady(CPANEL.main.Init);
} catch(e) {
  errorHandler(e)
}
