//
// SLIDER STRONA GŁÓWNA
//

$(document).ready(function() {
	//Wy&#182;wietla paging I aktywuje jego pierwszy link
$(".paging").show();
$(".paging a:first").addClass("active");

//Pobiera rozmiar obrazków albo div-ow oraz ich ilosc i na tej podstawie definiuje rozmiar warstwy image_reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

//Definiuje nowy rozmiar warstwy image_reel
$(".image_reel").css({'width' : imageReelWidth});

//Paging  and Slider Function
rotate = function(){
    var triggerID = $active.attr("rel") - 1; //Pobiera liczbę przesunięć
    var image_reelPosition = triggerID * imageWidth; //Definiuje odległo&#182;ć o jaką musi przesunąć się imege_reel

    $(".paging a").removeClass('active'); //czy&#182;ci wszystkie aktywne klasy
    $active.addClass('active');
    //Slider Animation
    $(".image_reel").animate({
        left: -image_reelPosition
    }, 1500 );

};

//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){
        $active = $('.paging a.active').next();
        if ( $active.length === 0) {
            $active = $('.paging a:first');
        }
        rotate();
    }, 4000); //Czas pomiędzy przesunięciami (7 sekund)
};

rotateSwitch();


//Akcja po najechaniu kursorem na slider
$(".image_reel a").hover(function() {
    clearInterval(play); //Zatrzymuje rotacje
}, function() {
    rotateSwitch(); //Podejmuje na nowo liczenie czasu
});

//Po kliknięciu
$(".paging a").click(function() {
    $active = $(this);
    //Reset timera
    clearInterval(play); //Zatrzymuje rotacje
    rotate();
    rotateSwitch(); // Wznawia rotacje
    return false;
});

});

