$(function () {
    $('.RotationContainer').each(function (a, b) {
        var container = this;
        var prevAnchor = 0;
        var slideshow = $('.RotationArea', this).cycle({
            fx: 'fade',
            delay: 2000,
            speed: 700,
            timeout: 6000,
            next: $('.RotationNextButton', container),
            prev: $('.RotationPrevButton', container),
            pager: $('.RotationNavigation', container),
            pause: true,
            pagerAnchorBuilder: function (idx, slide) {
                if (idx == 1) {
                    $('<a href="#" class="RotationPauseButton">Pausa</a>')
								.click(function () {
								    $(this).css('display', 'none');
								    $('.RotationPlayButton', container).css('display', 'block');
								    slideshow.cycle('pause');
								    return false;
								}).appendTo($('.RotationNavigationHolder', container));
                    $('<a href="#" class="RotationPlayButton">Spela upp</a>')
								.click(function () {
								    $(this).css('display', 'none');
								    $('.RotationPauseButton', container).css('display', 'block');
								    slideshow.cycle('resume');
								    return false;
								}).appendTo($('.RotationNavigationHolder', container));
                }
                return '<a href="#">' + idx + '</a>';
            }
        });
        $('.RotationArea .RotationItem', this).each(function (a, b) {
            var a = $('a', this);
            if (a.size() > 0) {
                $(this).click(function () { location.href = a.attr('href'); }).css('cursor', 'pointer');
            }
        });
    });
});
