var projectThumbDefault1 = 'obi.gif';
var projectThumbDefault2 = 'ps.gif';
var projectThumbDefault3 = 'gpm.gif';
var projectThumbDefault4 = 'bfc.gif';
var projectThumbDefault5 = 'fq.gif';
var projectThumbDefault6 = 'ife.gif';


var projectThumbHighlight1 = 'obi-over.gif';
var projectThumbHighlight2 = 'ps-over.gif';
var projectThumbHighlight3 = 'gpm-over.gif';
var projectThumbHighlight4 = 'bfc-over.gif';
var projectThumbHighlight5 = 'fq-over.gif';
var projectThumbHighlight6 = 'ife-over.gif';

var clickCounter = 0;

jQuery(document).ready(function() {
	initHovers();
	initClicks();

	// fade in first project
	
	jQuery('#splash #project-1').fadeIn('slow');
	jQuery('#splash #project-1').addClass('selected');
	jQuery('#splash .featured ul li a#featured-1 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight1);

});

function initClicks()
{
	resetClickCounter();
	
	jQuery('#splash .featured ul li a#featured-1').click(function() {
		unbindClicks(true);
		swapProject(1); return false;
	});
	
	jQuery('#splash .featured ul li a#featured-2').click(function() {
		unbindClicks(true);
		swapProject(2); return false;
	});
	
	jQuery('#splash .featured ul li a#featured-3').click(function() {
		unbindClicks(true);
		swapProject(3); return false;
	});

	jQuery('#splash .featured ul li a#featured-4').click(function() {
		unbindClicks(true);
		swapProject(4); return false;
	});
	
	jQuery('#splash .featured ul li a#featured-5').click(function() {
		unbindClicks(true);
		swapProject(5); return false;
	});
	
	jQuery('#splash .featured ul li a#featured-6').click(function() {
		unbindClicks(true);
		swapProject(6); return false;
	});					
}

function initHovers()
{
	// featured thumbs
	jQuery('#splash .featured ul li a#featured-1').hover(function() {
		jQuery('#splash .featured ul li a#featured-1 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight1);
			}, function() {
		jQuery('#splash .featured ul li a#featured-1 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault1);
	});
	
	jQuery('#splash .featured ul li a#featured-2').hover(function() {
		jQuery('#splash .featured ul li a#featured-2 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight2);
			}, function() {
		jQuery('#splash .featured ul li a#featured-2 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault2);
	});	
	
	jQuery('#splash .featured ul li a#featured-3').hover(function() {
		jQuery('#splash .featured ul li a#featured-3 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight3);
			}, function() {
		jQuery('#splash .featured ul li a#featured-3 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault3);
	});	
	
	jQuery('#splash .featured ul li a#featured-4').hover(function() {
		jQuery('#splash .featured ul li a#featured-4 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight4);
			}, function() {
		jQuery('#splash .featured ul li a#featured-4 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault4);
	});	
	
	jQuery('#splash .featured ul li a#featured-5').hover(function() {
		jQuery('#splash .featured ul li a#featured-5 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight5);
			}, function() {
		jQuery('#splash .featured ul li a#featured-5 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault5);
	});	
	
	jQuery('#splash .featured ul li a#featured-6').hover(function() {
		jQuery('#splash .featured ul li a#featured-6 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbHighlight6);
			}, function() {
		jQuery('#splash .featured ul li a#featured-6 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault6);
	});	
}

function unbindClicks(initCC)
{
	jQuery('#splash .featured ul li a#featured-1').unbind('click');
	jQuery('#splash .featured ul li a#featured-2').unbind('click');
	jQuery('#splash .featured ul li a#featured-3').unbind('click');
	jQuery('#splash .featured ul li a#featured-4').unbind('click');
	jQuery('#splash .featured ul li a#featured-5').unbind('click');
	jQuery('#splash .featured ul li a#featured-6').unbind('click');
	
	if(initCC == true)
		initClickCounter();
}

function initClickCounter()
{
	jQuery('#splash .featured ul li a#featured-1').click(function() {
		checkClickCounter();
		return false;
	});
	
	jQuery('#splash .featured ul li a#featured-2').click(function() {
		checkClickCounter();
		return false;
	});
	
	jQuery('#splash .featured ul li a#featured-3').click(function() {
		checkClickCounter();
		return false;
	});
	
	jQuery('#splash .featured ul li a#featured-4').click(function() {
		checkClickCounter();
		return false;
	});
	
	jQuery('#splash .featured ul li a#featured-5').click(function() {
		checkClickCounter();
		return false;
	});
	
	jQuery('#splash .featured ul li a#featured-6').click(function() {
		checkClickCounter();
		return false;
	});
}

function checkClickCounter()
{
	clickCounter++;
	if(clickCounter == 2)
		alert('Click much?');
}

function resetClickCounter()
{
	clickCounter = 0;
	unbindClicks(false);
}

function resetProjects()
{
	jQuery('#splash .featured ul li a#featured-1 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault1);
	jQuery('#splash .featured ul li a#featured-2 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault2);
	jQuery('#splash .featured ul li a#featured-3 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault3);
	jQuery('#splash .featured ul li a#featured-4 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault4);
	jQuery('#splash .featured ul li a#featured-5 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault5);
	jQuery('#splash .featured ul li a#featured-6 img').attr("src","/themes/deversus/images/deversus/splash/" + projectThumbDefault6);
}

function fadeSelectedProject()
{
	jQuery('#splashWrapper').fadeOut('fast');
	jQuery('#splash .selected').hide();
	jQuery('#splash .selected').removeClass('selected');
}

function showSelectedProject(id)
{
	jQuery('#splash #project-' + id).addClass('selected');
	jQuery('#splash .selected').show();
	jQuery('#splashWrapper').fadeIn('normal');
}

function swapProject(id)
{
	jQuery('#splash .featured ul li a#featured-' + id).unbind();
	var imgPath = '/themes/deversus/images/deversus/splash/';
	var leftMargin = '-3px';
	var bottomDefault = '-3px';
	var bottomHidden = '-80px';
	var defaultThumb = '';
	var highlightThumb = '';
	
	switch(id)
	{
		case 1:
			leftMargin = '-3px';
			defaultThumb = projectThumbDefault1;
			highlightThumb = projectThumbHighlight1;
		break;
		case 2:
			leftMargin = '112px';
			defaultThumb = projectThumbDefault2;
			highlightThumb = projectThumbHighlight2;
		break;
		case 3:
			leftMargin = '227px';
			defaultThumb = projectThumbDefault3;
			highlightThumb = projectThumbHighlight3;
		break;
		case 4:
			leftMargin = '342px';
			defaultThumb = projectThumbDefault4;
			highlightThumb = projectThumbHighlight4;
		break
		case 5:
			leftMargin = '457px';
			defaultThumb = projectThumbDefault5;
			highlightThumb = projectThumbHighlight5;
		break;
		case 6:
			leftMargin = '572px';
			defaultThumb = projectThumbDefault6;
			highlightThumb = projectThumbHighlight6;
		break;
	}
	
	
	initHovers();
	
	// reset the thumb
	resetProjects();
	
	fadeSelectedProject();
	// slide the highlighter down
	jQuery('#splash .featured #highlighter').animate({
		bottom: bottomHidden
	},
	'fast',
	function()
	{
		// set the left margin
		jQuery('#splash .featured #highlighter').css('margin-left', leftMargin);
		showSelectedProject(id);
	}
	);
	
	// slide the highlighter up
	jQuery('#splash .featured #highlighter').animate({
		bottom: bottomDefault
	},
	'normal',
	function()
	{
		jQuery('#splash .featured ul li a#featured-'+id+' img').attr("src",imgPath + highlightThumb);
		initClicks();
	}
	);	
	
	//setTimeout(initClicks(), 500);
	
}