/**************************************************
 
   Purpose: Defines functions used for credit div
   Author:  FullAhead
   Date:    2007/04/04

 **************************************************/

// 
$(window).load(function(){ 

  // Setup colorbox links
  $.fn.colorbox.settings.maxWidth = "90%";
  $.fn.colorbox.settings.maxHeight = "90%";
  $.fn.colorbox.settings.opacity = 0.7;
  $.fn.colorbox.settings.preloading = true;
  $.fn.colorbox.settings.overlayClose = true;
  $.fn.colorbox.settings.slideshow = false;
  $("a[rel*=lightbox]").colorbox();
  
  
  // Create the mouseover magnifying glass
  var overlay = $('<div id="lightbox-overlay"/>');  
  
  if($.support.opacity){
    overlay.css({'opacity': 0});
  } else {
    overlay.hide();
  }
  
  
  $('#content').append(overlay);

  // Loop through all images with a rel=lightbox
  $("a[rel*=lightbox] img").each(
    function(){
      $(this).hover(      
        function(){
          overlay.stop(); 
          
          // Adjust for the image being inside a <td>
          var tdAdjust = $(this).parents('td').length > 0 ? 10 : 0;
          
          var pos = $(this).position()
          overlay.css({
            'left': pos.left + $(this).width() - 40 + tdAdjust,
            'top': pos.top + $(this).height() - 40
          }); 
          
          // Check if the browser supports opacity fade on a .png
          if($.support.opacity){
            overlay.css({'opacity': 0}); 
            overlay.fadeTo(200, 1);
          } else {
            overlay.show();
          }
        },
        function(){
          overlay.stop();
          if($.support.opacity){
            overlay.fadeTo(200, 0);
          } else {
            overlay.hide();
          }          
    
        }   
      );  
    }
  );  
  
});
 
 
 var px = window.opera ? 0 : "px";
 
 // Show the credit div
 function showCredit(){   
   var credit = document.getElementById('credit');
   
   if(credit && credit.style) {
     viewport.getAll();

     credit.style.top = getTop(credit) + px;
     credit.style.left = getLeft(credit) + px;           
   }  
 }
 
 // Hide the credit div
 function hideCredit(){
   var credit = document.getElementById('credit');
   
   if(credit && credit.style) {
     credit.style.top = "-3000" + px;
     credit.style.left = "-3000" + px;   
   }  
 }
 
 // Get the top position of the div
 function getTop(credit){
   return (viewport.height - credit.offsetHeight)/2 + viewport.scrollY;
 }
 
  // Get the left position of the div
 function getLeft(credit){
   return (viewport.width - credit.offsetWidth)/2 + viewport.scrollX;
 }
 
 // Used to calculate the window width/height and total amount of scroll
 // Author: Dyn-Web (http://dyn-web.com)
 var viewport = {
   getWinWidth: function () {
     this.width = 0;
     if (window.innerWidth) this.width = window.innerWidth - 18;
     else if (document.documentElement && document.documentElement.clientWidth) 
      this.width = document.documentElement.clientWidth;
     else if (document.body && document.body.clientWidth) 
      this.width = document.body.clientWidth;
   },
   
   getWinHeight: function () {
     this.height = 0;
     if (window.innerHeight) this.height = window.innerHeight - 18;
    else if (document.documentElement && document.documentElement.clientHeight) 
      this.height = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight) 
      this.height = document.body.clientHeight;
   },
   
   getScrollX: function () {
     this.scrollX = 0;
    if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
    else if (document.documentElement && document.documentElement.scrollLeft)
      this.scrollX = document.documentElement.scrollLeft;
    else if (document.body && document.body.scrollLeft) 
      this.scrollX = document.body.scrollLeft; 
    else if (window.scrollX) this.scrollX = window.scrollX;
   },
   
   getScrollY: function () {
     this.scrollY = 0;    
     if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
     else if (document.documentElement && document.documentElement.scrollTop)
      this.scrollY = document.documentElement.scrollTop;
    else if (document.body && document.body.scrollTop) 
      this.scrollY = document.body.scrollTop; 
    else if (window.scrollY) this.scrollY = window.scrollY;
   },  
  
   getAll: function () {
     this.getWinWidth(); this.getWinHeight();
     this.getScrollX();  this.getScrollY();
   }
   
}
