
$(document).ready(function() {
  init_over_labels();
  init_hover_boxes();
  init_hover_footer();
});


function init_over_labels() {
  if (!document.getElementById) return;  	

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // LABELs with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
	
    if (labels[i].className == 'overlabel') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hide_label(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hide_label(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hide_label(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to LABEL elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hide_label(field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
      return true;
    }
  }
}

function init_hover_boxes() 
{
  if (document.all&&document.getElementById) 
  {
    var userbox = document.getElementById('userbox');
    var adminbox = document.getElementById('adminbox');
    
    if (userbox) 
    {
      userbox.onmouseover = function() {this.className = "hover"};
      userbox.onmouseout = function() {this.className = ""};
    };
    
    if (adminbox) 
    {
      adminbox.onmouseover = function() {this.className = "hover"};
      adminbox.onmouseout = function() {this.className = ""};
    };
  }
}


function init_hover_footer() 
{
  if (document.all&&document.getElementById) 
  {
    var footer = document.getElementById('footer');
    var blocks = footer.getElementsByTagName('div');
    for (var i = blocks.length - 1; i >= 0; i--)
    {
      blocks[i].onmouseover = function() {this.className = "hover"};
      blocks[i].onmouseout = function() {this.className = ""};
    };
  }
}

function init_hover_bookmark()
{  
  document.getElementById("sb_delicious").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Delicious';};
  document.getElementById("sb_delicious").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};
  
  document.getElementById("sb_google").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Google';};
  document.getElementById("sb_google").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};
  
  document.getElementById("sb_wong").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Mister Wong';};
  document.getElementById("sb_wong").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};
  
  document.getElementById("sb_linkarena").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Linkarena';};
  document.getElementById("sb_linkarena").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};
  
  document.getElementById("sb_alltagz").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Alltagz';};
  document.getElementById("sb_alltagz").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};
  
  document.getElementById("sb_folkd").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Folkd';};
  document.getElementById("sb_folkd").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};
  
  document.getElementById("sb_face").onmouseover = function(){document.getElementById('sb_hover').innerHTML = 'Facebook';};
  document.getElementById("sb_face").onmouseout = function(){document.getElementById('sb_hover').innerHTML = '...';};

}



