var cross = new Image();
cross.src = "/lib/images/home/cross_button.png";
cross = $(cross);

$(document).ready(function() {
  var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
  
  $("#featured-navigation-links a").hover(
    function() {
      return;
      
      var overlay = $('<div class="screen-overlay"></div>').css({
        width:          $(window).width(),
        height:         $(window).height(),
        opacity:        0,
        background:     '#000',
        position:       'absolute',
        top:            '0px',
        left:           '0px',
        zIndex:         104
      });
      
      $(document.body).append(overlay);
      
      $(this).css({ zIndex: 105 });
      overlay.fadeTo(300, 0.1);
      $(this).animate({ fontSize: '1.5em' }, 500);
  },
  function() {
    return;
    
    $(this).css({ zIndex: 101 });
    $(".screen-overlay").remove();
    $(this).animate({ fontSize: '1.25em' }, 250);
  });
  
  /*
    Wiring for the countdown timer
  */
  var doorKnock = new Date(Date.UTC(2009, 4, 4, 0, 00));
  var containers = {
    days:     $("#id_days .timeVal"),
    hours:    $("#id_hours .timeVal"),
    minutes:  $("#id_minutes .timeVal") };
  
  var updateProc = function() {
    var seconds = Math.floor((doorKnock.getTime() - (new Date()).getTime()) / 1000);
    containers.days.html( Math.floor((seconds / 86400) ).toString() );
    containers.hours.html( Math.floor((seconds / 3600) % 24).toString() );
    containers.minutes.html( Math.floor((seconds / 60) % 60).toString() );
  };
  
  setInterval(updateProc, 10000);
  updateProc();
  
  /*
    Wiring for the home page bubble graph
  */
  var dimOthers = function(me) {
    $('#bubble-navigation .bubble').each(function(){
      if(me.id != this.id)
        $(this).fadeTo((Math.random() * 2000), (Math.random() * 0.6) + 0.4);
    });
  };
  
  var undimAll = function() {
    $("#bubble-navigation .bubble").each(function(){
      $(this).fadeTo((Math.random() * 1000), 1);
    });
  };
  
  $('#bubble-navigation .bubble').each(function(n) {
    var bubble = $(this);
    var a = bubble.find('a').remove();
    var link = a.attr("href");
    var caption = bubble.text();
    var images = bubble.find("img").hide();
    
    bubble.html("");
    bubble.append(cross.clone());
    
    bubble.append(a)
      .append($('<div class="caption">'+caption+'</div>').hide())
      .append(images)
      .addClass('closed');
    
    bubble.click(function() {
      document.location.href = link;
    });
    
    bubble.hover(
      function() {
       /* dimOthers(this);*/
        $(this).find(".background, .foreground").show();
        
        $(this)
          .css('z-index', '100')
          .removeClass("closed")
          .find(".caption")
          .fadeIn();
      },
      function() {
       /* undimAll();*/
        $(this).find(".background, .foreground").hide();
        $(this)
          .css('z-index', '60')
          .addClass("closed")
          .find(".caption")
          .hide();
      });
    
    setTimeout(function() { bubble.fadeIn("slow") }, (Math.random() * 2000));
  });
});