///////////////////////////////////////
// On DOM Load
///////////////////////////////////////

$(document).ready(function() {
	$('nav li.logo a').scrollify();
	$('nav li').tipify('nav');
});

///////////////////////////////////////
// Scroll to top
///////////////////////////////////////

$.fn.scrollify = function() {	
	return	this.click(function() {
		$('html, body').animate({ scrollTop: 0 }, 600);	
		return false;
	});
}


///////////////////////////////////////
// Tooltip
///////////////////////////////////////

var tooltipTemplate = '<div class="tooltip"><span></span></div>';
var linkTitle = '';

$.fn.tipify = function(type) {	
	return	this.hover(
		function() {
			// Just in case
			$('.tooltip', type).remove();
			
			link = $('a', $(this));
			linkTitle = link.attr('title');
			link.attr('title', '');
			newTip = $(tooltipTemplate).clone();
			$(type).append(newTip);
			$('.tooltip span', type).html(linkTitle);
			linkPosition = $( 'li', type).index(this);
			switch (linkPosition) {
				case 0 :
					// Kill the function
					break;
				case 1 : 
					newPosition = '59px';
					$('.tooltip', type).css('top', newPosition).fadeIn(600);
					break;
				default :
					newPosition = ((linkPosition + 1) * 36);
				$('.tooltip', type).css('top', newPosition).fadeIn(600);
					break;
			}
		},
		function() {
			$('.tooltip', type).fadeOut(50, function() {
				$(this).remove();
			});
			link.attr('title', linkTitle);
	});
}

///////////////////////////////////////
// Event Tracking
///////////////////////////////////////

function recordOutboundLink(category, action) {	
    _gat._getTrackerByName()._trackEvent(category, action);
}

