  $(document).ready(function(){
    // Aktivera paging
    $("#paging_offers").show();
    $("#paging_offers a:first").addClass("active");
    document.getElementById("e1").src = "http://www.dumsnal.se/images/slider/e1_hover.png";

        //Get size of images, how many there are, then determin the size of the image reel.
        var imageWidth = $("#focus_campaign").width();
        var imageSum = $("#offer img").size();
        var imageReelWidth = imageWidth * imageSum;

        //Adjust the image reel to its new size
        $("#offer").css({'width' : imageReelWidth});

        //Paging + Slider Function
        rotate = function(){
                var triggerID = $active.attr("rel") - 1; //Get number of times to slide
                var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
                var hover_id = triggerID + 1;

                $("#paging_offers a").removeClass('active'); //Remove all active class
                $active.addClass('active');

                //Slider Animation
                $("#offer").animate({
                        left: -image_reelPosition
                }, 500 );

                for(i=1;i<=imageSum;i++){
                  $("#e" + i).attr("src", "http://www.dumsnal.se/images/slider/e" + i + ".png");
                }
                $('#e' + hover_id).attr("src", "http://www.dumsnal.se/images/slider/e" + hover_id + "_hover.png");
        };

        //Rotation + Timing Event
        rotateSwitch = function(){
                play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds

                        $active = $('#paging_offers a.active').next();
                        if ( $active.length === 0) { //If paging_offers reaches the end...
                                $active = $('#paging_offers a:first'); //go back to first
                        }
                        rotate(); //Trigger the paging and slider function
                }, 8000); //Timer speed in milliseconds (3 seconds)
        };

        rotateSwitch(); //Run function on launch

        //On Hover
        $("#offer").hover(function() {
                clearInterval(play); //Stop the rotation
        }, function() {
                rotateSwitch(); //Resume rotation
        });

        //On Click
        $("#paging_offers a").click(function() {
                $active = $(this); //Activate the clicked paging
                //Reset Timer
                clearInterval(play); //Stop the rotation
                rotate(); //Trigger rotation immediately
                rotateSwitch(); // Resume rotation
                return false; //Prevent browser jump to link anchor
        });
});


