/*  jQuery Ghost Carousel
 *  Copyright (c) 2011 William Moynihan
 *  http://ghosttype.com
 *  Licensed under MIT
 *  http://www.opensource.org/licenses/mit-license.php
 *  May 31, 2011 -- v1.0
 *  Sep  6, 2011 -- v1.1 by Clvr Ninja
 */
 
$(function() {
    var content = '#featuredCycle #featuredContent';
    var section = content + ' > li';
    
    function ghostCarousel() {
        
        var v = $(window).width();
        var w = $(section).width();
        // Used w instead of c so c is no longer necessary
        //var c = (w * $(section).length - v) / 2;
        
        // Add 40 px to prevent snap loading from wrap affect
        $(content).width((w * $(section).length) + 40);
        // Used -w instead of -c because we have fixed overlay elements on top
        $(content).css('margin-left', -w);

        $('#featured a.left').click(function(e) {
            e.preventDefault();
            if ($(content).is(':animated')) return false;
            $(content).animate({ marginLeft: '-=' +w }, 400, function() {
                var first = $(section).eq(0);
                $(section).eq(0).remove();
                $(this).animate({ marginLeft: '+=' +w }, 0);
                $(this).append(first);
            });
        });
        $('#featured a.right').click(function(e) {
            e.preventDefault();
            if ($(content).is(':animated')) return false;
            $(content).animate({ marginLeft: '+=' +w }, 400, function() {
                var end = $(section).length - 1;
                var last = $(section).eq(end);
                $(section).eq(end).remove();
                $(this).animate({ marginLeft: '-=' +w }, 0);
                $(this).prepend(last);
            });
        });
        
    }
    
    ghostCarousel();
    
    $(window).resize(function() {
        var v = $(window).width();
        var w = $(section).width();
        // Used w instead of c so c is no longer necessary
        //var c = (w * $(section).length - v) / 2;
        $(content).css('margin-left', -w);
    });   
});
/* end "jQuery Ghost Carousel" */

