var d = document;
var http = 'http://';
var sameWindowURLs = new Array('jsend.org','jsend.local','jsend2.local');
var spotTimer = null;
var spotRunning = false;
$(document).ready(function() { 
		$("a.fancybox").fancybox({ 
      'titleShow'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'overlayOpacity' : 0.6,
			'speedIn'		:	300, 
		  'speedOut'		:	200, 
      'overlayColor' : '#000' 
     }); 
    Cufon.now();
    Cufon.replace('h1, h2, h3', { fontFamily: 'ColaborateLight', hover: 'true' });
    $('#logo').mouseover(function() {
      $('#arrow').css({backgroundPosition: '0 -30px'});
      spotTimer = setTimeout(function() {
        if (!spotRunning) {
          spotRunning = true;
          $('#beam').css({display: 'block', width: '10px', height: '2px',opacity: '0.7'})
          $('#beam').animate({
            width: '540px',
            height: '1px',
            opacity: '0.1'
          },750, 'linear', function() {
              $('#beam').css({display: 'none'});
              spotRunning = false;
          });
        }
      },1250);
    });
    $('#logo').mouseout(function() {
      clearTimeout(spotTimer);
      $('#arrow').css({backgroundPosition: '0 0'});
    });
});

/* -----------------------------------------------------------------------------
   EVENTS
----------------------------------------------------------------------------- */
d.onclick = MClE;

function evtGlobal(e) {
  if (!e) e = window.event;
  e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
  var trg;
  if (e.target) trg = e.target; 
  else if (e.srcElement) trg = e.srcElement;
  if (trg.nodeType == 3) trg = trg.parentNode;
  return trg;
}

function MClE(e) {
  var trg = evtGlobal(e);
  var tmp;
  var pn = trg.parentNode;
  var rel;
  if (pn.href) {
    tmp = pn.href;
    rel = pn.rel;
   }
   else {
    tmp = trg.href;
    rel = trg.rel;
  }
  
  if (tmp&&!rel) {
    var atmp = [];
    if (tmp.match(/\?/)) atmp = tmp.split('?'); else atmp[0] = tmp;
    var lt = atmp[0];
    var openInSameWindow = 0;
    var rx = new RegExp('('+sameWindowURLs.join(')|(')+')','i');
    if (rx.test(lt)) openInSameWindow = 1;
    if (trg.className.indexOf('external')>-1) openInSameWindow = 0;
    if (!openInSameWindow) {
      window.open(lt);
      return false;
    }
  }
  return;
}

$('input').click(function() {
  this.blur();
});
$('a').click(function() {
  this.blur();
});

