﻿
//tells jquery to call the onDocumentLoaded function when the browser is ready
$(document).ready(loadFrontSlider);

//Used to store the TimeoutID
var slideShowTimeoutID;

//The current image showed
var currentImage = 0;

function loadFrontSlider()
{
    //We hide all images and all the info boxes
    $(".jq-info").hide();
    $(".jq-image").hide();
    
    //Set up an event that fires when we hover over a button
    $("#ChangeSolution .jq-button").hover(
        function() {
        jqButtonHover($(this));
        },function() {}
    );
    
    //We set the picture to the first one    
    jqSetPicture(1);
    
    //Reset the timer, and sets the timer
    jqResetTimer();
}

function jqResetTimer()
{
    clearTimeout(slideShowTimeoutID);
    slideShowTimeoutID = setTimeout("jqSlideShow()",10000);
}

//Called then the timer ticks
function jqSlideShow()
{
    var im = parseInt(currentImage);
    if(im == 3)
    {
        im = 1;
    }
    else
    {
        im = im +1;
    }
    
    jqSetPicture(im);
}

//Called then we are over the button
function jqButtonHover(theButton)
{
    
    var id = theButton[0].id;
    
    //Sets the picture with the same number as the buttons number (S1 > P1)
    jqSetPicture(id.substring(1));
    
}

//Sets the picture in the box
function jqSetPicture(id)
{
    //If it is the same image, then we dont need to face in and out
    if(currentImage != id)
    {
        //Sets the current image
        currentImage = id;
        
        //Sets all buttons to non-selected
        $("#ChangeSolution .jq-button").removeClass("Selected");
        
        //Sets the button for that image as selected
        $(".S" + id).addClass("Selected");
        
        //Fadeout all images, and fade the new one in
        $(".jq-image").fadeOut(1000);
        $(".P" + id).fadeIn(1000);
        
        //Faceout all the infoboxes and fade the new one in
        $(".jq-info").fadeOut(1000);
        $("." + "I" + id).fadeIn(1000);
       
    }
    //We reset the timer, so there will go 10 sec before it will show a new image
    jqResetTimer();

}

