$(document).ready(function() {
    // variables
    var imageDisp = 3;
    var delay = 5000;
    var width = 0;
    var count = 1;
    var ul = $('.portfolio ul#slideshow');
    var lis = $('.portfolio ul#slideshow > li.port_slide').size();
    var rotations = lis / imageDisp;
    var timer;

    // find and set total width of slideshow
    $('.portfolio ul li.port_slide').each(function() {
        width += $(this).outerWidth(true);
    });
    ul.css('width', width);
    var scrollDist = width / rotations;

    //click functionality
    $('#work-nav-prev').click(function() {
        dotimer();
        if (ul.css('left') == '15px') {
            return;
        } else {
            ul.animate({
                "left": "+=" + scrollDist + "px"
            },
            800);
            count -= 1;
            return false;
        }
    });
    $('#work-nav-next').click(function() {
        dotimer();
        slideSwitch();
    });

    var dotimer = function(x) {
        if (timer != null)
        clearInterval(timer);
        timer = setInterval(function() {
            slideSwitch();
        },
        delay);
    }
    dotimer();
    $(ul).hover(function() {
        clearInterval(timer);
    },
    function() {
        dotimer();
    });
    function slideSwitch() {
        if (count >= rotations) {
            ul.animate({
                "left": "15px"
            },
            800);
            count = 1;
            return;
        }
        ul.animate({
            "left": "-=" + scrollDist + "px"
        },
        800);
        count += 1;
    }
	$('.portfolio li').hover(
		function(){
			$('.cover', this).fadeTo(1000,1);	
			$('.cover div', this).animate({
			"margin-top":"0px",
			"height":"250px"
			}, 350);
		},
		function(){
			$('.cover', this).fadeTo(800,0.9);
			$('.cover div', this).animate({
			"margin-top":"170px",
			"height":"80px"
			}, 200);	
	});
});



