var cTimer;
var cPause = false;
var cCount = $('#carousel ul li').length;
var cWidth = 244;
var cSpeed = 300;
var cInterval = 2000;

$('#carousel ul').css('width', (cCount * cWidth) + 'px');

function moveCarousel(){
	$('#carousel ul').animate(
		{'margin-left': '-' + cWidth + 'px'},
		cSpeed,
		function(){
			toShift = $('#carousel ul li:first');
			$('#carousel ul li:first').remove();
			$('#carousel ul').append(toShift).css('margin-left', '0px');
		}
	);
}

$('#carousel').hover(
	function(){
		cPause = true;
		clearTimeout(cTimer);
	},
	function(){
		cPause = false;
		cTimer = setTimeout("run()", cInterval);
	}
);


$('#carousel li a').live(
	'mouseover',
	function(){
		$(this).children('span').css('opacity', 0.5).show();
	}
);

$('#carousel li a').live(
	'mouseout',
	function(){
		$(this).children('span').hide();
	}
);
function run(){
	if(!cPause){
		moveCarousel();
		cTimer = setTimeout("run()", cInterval);
	}
}

cTimer = setTimeout("run()", cInterval);

$('.portfolio-item, #content').hover(
	function(){
		$(this).children('.intro-text').css('background', '#ff0');
	},
	function(){
		$(this).children('.intro-text').css('background', '#eee');
	}
);

$('.portfolio-item').click(
	function(){
		window.location = $(this).children('.intro-text').children('h2').children('a').attr('href');
	}
);

$('#content').click(
	function(){
		window.location = $(this).children('.intro-text').children('h1').children('a').attr('href');
	}
);
