﻿$(document).ready(function () {
    $("#Player").click(function () {
        if ($("img", this).attr("alt") == "Arrêter")
            Stop();
        else
            Play();
    });

    $(".slidetabstop").tabs(".images > div", {

        // enable "cross-fading" effect
        effect: 'fade',
        fadeOutSpeed: 'slow',

        // start from the beginning after the last tab
        rotate: true

        // use the slideshow plugin. It accepts its own configuration
    }).slideshow();

    $(".slidetabs").tabs(".images2 > div", {

        // enable "cross-fading" effect
        effect: 'fade',
        fadeOutSpeed: 'slow',

        // start from the beginning after the last tab
        rotate: true

        // use the slideshow plugin. It accepts its own configuration
    }).slideshow();

    var _tabs = $(".slidetabstop").data("tabs");
    var _slideshow = $(".slidetabstop").data("slideshow");

    _tabs.onClick(function (sender, index) {
        var fake = null;

        switch (index) {
            case 0:
                fake = $("#diap1")[0];
                break;
            case 1:
                fake = $("#diap2")[0];
                break;
            case 2:
                fake = $("#diap3")[0];
                break;
            case 3:
                fake = $("#diap4")[0];
                break;
            case 4:
                fake = $("#diap5")[0];
                break;
            case 5:
                fake = $("#diap6")[0];
                break;
        }

        ChangeFakeTab.call(fake, index);
    });

    function ChangeFakeTab(index) {
        $("div.faketabs > a").removeClass("diap1c diap2c diap3c diap4c diap5c diap6c");
        $(this).addClass($(this).attr("id") + "c");
    }

    function ChangeTab(index) {
        _tabs.click(index);
    }

    function Play() {
        $("#Player img").attr("src", "Styles/images/pause.png").attr("alt", "Arrêter");
        _slideshow.play();
    }

    function Stop() {
        $("#Player img").attr("src", "Styles/images/play.png").attr("alt", "Démarrer");
        _slideshow.stop();
    }

    $("#diap1").click(function () { ChangeTab(0); });
    $("#diap2").click(function () { ChangeTab(1); });
    $("#diap3").click(function () { ChangeTab(2); });
    $("#diap4").click(function () { ChangeTab(3); });
    $("#diap5").click(function () { ChangeTab(4); });
    $("#diap6").click(function () { ChangeTab(5); });

    Play();

});
