﻿/*  
JScript File for jquery sliderviewer : slider core function and autoslide
june 2k10, alain werner, würth france sa
Last revision : july 2k10
*/

var cpt = 0;
var theTimerID;
var slide_frequency = 4000;     // slide period : change frequency here !

// init() : trigger on load; launch the slide and set the timer
function sliderInit() {

    // call of slideviewer main function
    $("div#WurthFranceHomepageSlider").slideView({
        easeFunc: "easeInOutSine",
        easeTime: 500,
        toolTip: false
    });

    // for kill interval purposes
    theTimerID = setInterval("autoSlide()", slide_frequency);   // timer set to 'slide_frequency' ms

    // redefine the click event to handle User's clicks
    jQuery('#stripTransmitter0 a').bind("click", function (evt) {

    	// to know if it is a click from users
    	if (evt.originalEvent) {

    		clearInterval(theTimerID);  // stop the timer

    		cpt = $(this).text() - 1;   // set the indexer to the current element; possible because link's anchors are number

    		theTimerID = setInterval("autoSlide()", slide_frequency); // re-set the timer to continue the slide
    	}
    	$('#stripTransmitter0 a').closest("li").removeClass("current");
    	$(this).closest("li").addClass("current");
    });

    $('#stripTransmitter0 a').first().trigger("click");
}

// autoSlide() : launch click event on each link
function autoSlide() {
    cpt++;
    if (cpt == $('#stripTransmitter0 a').length) {
    	cpt = 0;
    }
    $('#stripTransmitter0 a').eq(cpt).trigger("click");
}

$(window).bind("load", sliderInit);   // bind init function to the window Load Event
