// jQuery callback that fires at DOM-ready
jQuery(function($){

  // jQuery UI tabs
  if( $().tabs ) {
    $('.titlebar-tabs').tabs({ event: 'mouseover' });
    $('.filecard-tabs').tabs();
  }
  
  // hover states on the static widgets
  $('#dialog_link, ul#icons li').hover(
    function() { $(this).addClass('ui-state-hover'); }, 
    function() { $(this).removeClass('ui-state-hover'); }
  );
  
  // patch around IE's broken hover behavior for the navigation flyouts
  if (window.attachEvent) {
    $("#nav>li").each(function() {
      this.onmouseover = function() {
        this.className += " over";
      }
      this.onmouseout = function() {
        this.className = this.className.replace(new RegExp(" over\\b"), "");
      }
    });
  }
  
  /* ---------------
   * install the code to allow the login field labels to float over their
   * respective fields (to act as placeholders)
   * 
   */
  function toggleLabel( id, visible ) {
    $("label.overlabel-apply[for='" + id + "']").toggleClass("hidden", !visible);
  }
  
  $("label.overlabel[for]").each(function(){
    var id = $(this).attr("for");
    var fld = $("#" + id);
    
    // if the label's for doesn't point to a real field, skip
    if( !id || fld.length === 0 ) return;
    
    // activate the label
    $(this).addClass("overlabel-apply").removeClass("overlabel");
    
    // hide the label if the field isn't empty
    if( fld.val() ) toggleLabel(id, false);
    
    // install the necessary event handlers
    $(this).click(function(){ fld.focus(); });
    fld.focus(function(){ toggleLabel(this.id, false); });
    fld.blur(function(){ if( !$(this).val() ) toggleLabel(this.id, true); });
  });

});


