$(function() {
	var links = $('#portfolio-links a');
	var content = $('#portfolio-content');
	var children = $('#portfolio-content > li');
	var totalWidth = 900 * children.length + "px";
	$('#portfolio-links a:first').addClass('active');
	$('#portfolio-content').css({"width":totalWidth}).addClass('slider-active').wrap('<div id="portfolio-content-wrapper"></div>');
	
	links.click(function() {
		var index = links.index(this);
		var margin = (index * -900);
		content.animate({"marginLeft":margin});
		links.removeClass('active').filter(this).addClass('active');
		content.stopTime('slider');
		return false;
	});
	
	function startSlider() {
		content.everyTime(5000, 'slider', function() {
			var next = links.filter('.active').parent().next().find('a');
			var a = $('#portfolio-links a').index(next);
			if (a > -1) {
				$(this).animate( {"marginLeft": (a * -900) });
				links.removeClass('active').filter(next).addClass('active');
			} else { 
				$(this).animate( {"marginLeft": 0});
				links.removeClass('active').filter(':first').addClass('active');
			}
		});
	}
	
	startSlider();

	$('div.meta').css({ 'height':'0' })
	$('ul#portfolio-content').removeClass('static').mouseover(function() {
		$(this).find('div.meta').stop().animate({ 'height':'45px', 'opacity':'1' }, 750);
		content.stopTime('slider');
	}).mouseout(function() {
		$(this).find('div.meta').stop().animate({ 'height':'0' }, 750);
		startSlider();
	});
});