/* Add the 'active' class to the active nav bar item */
function activateNavBar()
{
	$('#nav a').each(function() {
		var loc = document.location.toString();
		/* Prevent loc.match from always matching the home tab */
		if ((this.href == base_url && loc == base_url) || (this.href != base_url && loc.match(this.href) != null))
		{
			$(this).parent().addClass('active');
		}
	});
}

/* Add the deprecated target attribute to external links */
function externalLinks()
{
	$('a[rel="external"]').attr('target', '_blank').attr('title', 'Click to open external link in new window');
}

/* Add the 'first' class to the first child in the content block */
function contentFirst()
{
	$('#content > :first-child').addClass('first');
}

/* Add hover class to list items to emulate li:hover in IE6 */
function liHover()
{
	$('#content li').mouseover(function () {
		$(this).addClass('hover');
	});
	$('#content li').mouseout(function () {
		$(this).removeClass('hover');
	});
}

/* Rotate the featured project using AJAX */
function rotateProject(time)
{
//	$('#featured_project_details').animate({ opacity: 0 }, 1000, '', function() { rotateProjectFadeOutCallback(time); });
	$('#featured_project_details').slideUp(1000, function() { rotateProjectFadeOutCallback(time); });
}

function rotateProjectFadeOutCallback(time)
{
	// Get the project slug my splitting the details link href and popping the last segment	
	var projectSlug = $('#featured_project_details :last-child a').attr('href').split('/').pop();
	$('#featured_project_details').load(base_url + 'ajax/featured_project', { 'lastProjectSlug': projectSlug }, function() { rotateProjectLoadCallback(time); });
}

function rotateProjectLoadCallback(time)
{
//	$('#featured_project_details').animate({ opacity: 1 }, 1000, function() { setTimeout("rotateProject(" + time + ")", time); });
	$('#featured_project_details').slideDown(1000, function() { setTimeout("rotateProject(" + time + ")", time); });		
}

$(function() {
	activateNavBar();
	externalLinks();
	contentFirst();
//	liHover();
	setTimeout("rotateProject(15000)", 15000);
});
