jQuery.fn.rotation_lead = function(length,type) {
    var $container = $(this).find(".rotation-container");
    var $nav = $(this).find(".rotation-nav");
    var $nav_links = $nav.find("a");
    var $promos = $container.find(".promo");
    var rotation = null;
    var currentPromo = 0;
        var promoWidth = $promos.filter(":first").outerWidth(true);
        if(type == 'fade') {
        $promos.css({"position":"absolute"}).filter(":not(:first)").css({"display":"none"}).hide();
        } else if(type == 'slide') {
            var slideCount = 0;
            $container.css({"width":"10000px", "position":"relative"});
            $(this).css({"overflow":"hidden"});
            var promoCount = $promos.length;
            //$promos.filter(':first').before($promos.slice(1).clone().addClass('copied'));
            $promos.filter(':last').after($promos.slice(0,-1).clone().addClass('copied'));
            $promos = $container.find(".promo");
            $container.css({"left":"0px"});
        }
    // Create onclick functions
    function fade(link) {
            $nav_links.removeClass('selected');
            $(link).addClass('selected');
            $promos.filter(link.hash).fadeIn(250);
            $promos.filter(":not("+link.hash+")").fadeOut(250);
            //$promos.filter(":not("+link.hash+")").animate({opacity:0},1000, $(this).hide);
            return false;
    }
        function slide(link) {
            $nav_links.removeClass('selected');
            $(link).addClass('selected');
            if($nav_links.index(link) == slideCount + 1) {
                slideCount += 1;
                if(slideCount > promoCount - 1) {
                    $container.animate({left:"-="+promoWidth+"px"}, 1000).animate({left:"0px"}, 0);
                    slideCount = 0;
                } else {
                    $container.animate({left:"-="+promoWidth+"px"}, 1000);
                }
            } else if($nav_links.index(link) != slideCount){
                var shiftCount; ;
                if($nav_links.index(link) > slideCount) {
                    shiftCount = $nav_links.index(link) - slideCount;
                } else {
                    shiftCount = Math.abs($nav_links.index(link) - slideCount - 1);
                    if(shiftCount >= promoCount) {
                        shiftCount = 1;
                    }
                }
                $container.animate({left:"-="+(promoWidth * shiftCount)+"px"}, 1000).animate({left:"-" + (promoWidth * $nav_links.index(link))+"px"}, 0);
                
                slideCount = $nav_links.index(link);
            }
            return false;
        }
    // Attach Clicks
    $nav_links.each(function() {
        $(this).click(function() {
            if(type == 'fade') {
                            fade(this);
                        } else if(type== 'slide') {
                            slide(this);
                        }
            return false;
        });
    });
    // Rotation Interval
    function startRotation() {
        currentPromo += 1;
        if(currentPromo >= $nav_links.length) {
            currentPromo = 0;
        }
                if(type == 'fade') {
            fade($nav_links.get(currentPromo));
                } else if(type == 'slide') {
                    slide($nav_links.get(currentPromo));
                }
    }
    // Start Rotation 
    rotation = setInterval(startRotation, length);
    // Kill rotation on Mouseover
    $promos.mouseover(function() {
            clearInterval(rotation)
        }).mouseout(function() {
            rotation = setInterval(startRotation, length);
        });
    $nav_links.mouseover(function() {
            clearInterval(rotation)
        }).mouseout(function() {
            rotation = setInterval(startRotation, length);
        });
}
$("#content-rotation").rotation_lead(8000, 'slide');