Event.observe(window,'load', function() {
  // add IE6 selectors
  if (Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) {
    if ($('top-signup-wrap')) {
      $('top-signup-wrap').observe('mouseenter', function(event) {
        this.addClassName('over');
      });
      $('top-signup-wrap').observe('mouseleave', function(event) {
        this.removeClassName('over');
      });
    }
    if ($('top-share-wrap')) {
      $('top-share-wrap').observe('mouseenter', function(event) {
        this.addClassName('over');
      });
      $('top-share-wrap').observe('mouseleave', function(event) {
        this.removeClassName('over');
      });
    }
    if ($('top-login-wrap')) {
      $('top-login-wrap').observe('mouseenter', function(event) {
        this.addClassName('over');
      });
      $('top-login-wrap').observe('mouseleave', function(event) {
        this.removeClassName('over');
      });
    }
    if ($('share-wrap')) {
      $('share-wrap').observe('mouseenter', function(event) {
        this.addClassName('over');
      });
      $('share-wrap').observe('mouseleave', function(event) {
        this.removeClassName('over');
      });
    }
    if ($$('.green-button')) {
      $$('.green-button').each(function(e) {
        e.observe('mouseenter', function(event) {
          this.addClassName('over');
        });
        e.observe('mouseleave', function(event) {
          this.removeClassName('over');
        });
      });      
    }
    if ($$('#main-nav li')) {
      $$('#main-nav li').each(function(e) {
        e.observe('mouseenter', function(event) {
          this.addClassName('over');
        });
        e.observe('mouseleave', function(event) {
          this.removeClassName('over');
        });
      });
    }
  }

  // print this page
  if ($('aside-print')) {
    $('aside-print').observe('click', function(event) {
      window.print();
      Event.stop(event);
    });
  }

  // email to a friend
  if ($('aside-email')) {
    $('aside-email').observe('click', function(event) {
      var width  = 580;
      var height = 580;
//      var left   = (screen.width  - width)/2;
//      var top    = (screen.height - height)/2;
      newwin = window.open(this.href, "emailafriend", "status=no,toolbar=no,resizable=yes,scrollbars=1,width="+width+",height="+height);
      if (window.focus) { newwin.focus(); }
      Event.stop(event);
    });
  }

  if ($$('a[class="external"]')) {
    $$('a[class="external"]').each(function(e) {
      e.observe('click', function(event) {
        window.open(e.href);
        Event.stop(event);
      });
    });
  }
  
  // homepage partner slideshow
  if ($('showcaseScroller')) {
    var len = parseInt($('showcaseScroller').getStyle('width'));
    var DELAY = 3;
    var BETWEEN = 5;
    var IS_ANIMATING = false;

    function moveNext() {
      if ( ! IS_ANIMATING ){
        IS_ANIMATING = true;
        new Effect.Move($('showcaseScroller'), { x:-310, y:0, duration:DELAY, fps:100, transition:Effect.Transitions.easeInOutCubic,
          afterFinish: function(){
            $$('#showcaseScroller li').slice(0, 2).each(function(item){
              $('showcaseScroller').insert({ bottom:Element.clone(item, true) });
              item.remove();
              $('showcaseScroller').setStyle({ left: '0px' });
            });
            IS_ANIMATING = false;
          }
        });
      }
    }

    var timer = setTimeout(function() {moveNext();}, 1);
    timer = setInterval(function() {moveNext();}, BETWEEN*1000);
  }

});

function trackClickEvent (id, category, action, label, value)
{
  value = value === undefined ? null : value;
  $(id).observe('click', function (e) {
    var pageTracker = _gat._getTracker();
    pageTracker._trackEvent(category, action, label, value);
    setTimeout(change_page.curry(id), 100);
    e.stop();
  });
}

function change_page(id)
{
  window.location = $(id).href;
}
