/*
 * image preview
 *
 */
this.imagePreview = function() {
  imagePreviewX = 460;
  imagePreviewY = -300;

  $("a.preview").hover(
    function(e) {
      $("body").append('<img src="' + this.href + '" alt="Image preview" id="preview" />');
      $("#preview")
        .css("top", (e.pageY - imagePreviewX) + "px")
        .css("left", (e.pageX + imagePreviewY) + "px")
        .fadeIn("fast");            
    },
    function() {
      $("#preview").remove();
    }
  ); 

  $("a.preview").mousemove(function(e) {
    $("#preview").css("top", (e.pageY - imagePreviewX) + "px");
    $("#preview").css("left", (e.pageX + imagePreviewY) + "px");
  });     
};


/*
 * tooltip
 *
 */
this.tooltip = function() {
  toolTipX = 10;
  toolTipY = 20;

  $("div.tooltip").hover(
    function(e) {
      html = $(this).find(".tooltip_content").html();
      $("body").append('<p id="tooltip">' + html + '</p>');
      $("#tooltip")
        .css("top", (e.pageY - toolTipX) + "px")
        .css("left", (e.pageX + toolTipY) + "px")
        .fadeIn("fast");
    },
    function() {
      $("#tooltip").remove();
    }
  );

  $("div.tooltip").mousemove(function(e) {
    $("#tooltip")
      .css("top", (e.pageY - toolTipX) + "px")
      .css("left", (e.pageX + toolTipY) + "px");
  });
};


/*
 * misc
 *
 */
$(document).ready(function() {
  $(".submenuitem").click(function() {
    $(".submenuitem").removeClass("active");
    $(this).addClass("active");
    $("div[id^=content]").hide();
    $("#content_" + $(this).attr("id").replace("submenu_", "")).show();
  });

  $(".inner_submenu .menuitem").click(function() {
    $(".inner_submenu .menuitem").removeClass("active");
    $(this).addClass("active");
    $("div[id^=inner_content]").hide();
    $("#inner_content_" + $(this).attr("id").replace("submenu_", "")).show();
  });

  imagePreview();
  tooltip();
});
