﻿var currentslide = 0;

$(document).ready(function()
{
    changeslider(0);
});

function changeslider(slide)
{
    hideSliders();
    $("#slider" + slide).fadeIn('slow');
    animateSlider0(slide);
    
    currentslide = slide;
    
    var nextslide;
    if (slide == 0)
    {
        nextslide = 0;
    }
    else
    {
        nextslide = slide;
    }
    
    $(document).oneTime(19000, function(i)
    {
        changeslider(nextslide);
    });
}

function hideSliders()
{
    $("#slider0").hide();
    $("#slider1").hide();
    $("#slider2").hide();
}

function resetThumbs()
{
    var tempindex = 1;
    while (tempindex<=5)
    {
        var thumb = document.getElementById("thumb" + tempindex);
        var path = thumb.src.replace("lg.png","sm.png");
        thumb.src = path;
        thumb.style.width = "51px";
        thumb.style.height = "50px";
        thumb.style.marginTop = "10px";
      
        tempindex = tempindex + 1;
    }
    $(document).stopTime();
}

function animateSlider0(slide)
{
    $(document).stopTime();
    if (slide == 0)
    {
        var i = 1;
        resetThumbs();
        $(document).everyTime(3000, function(i) {
            if (i == 6)
            {
                var path = $(this).find('#thumb5').attr('src').replace("lg.png","sm.png");
                $(this).find('#thumb5').attr("src",path);
                
                $(this).find('#thumb5').animate({
                    width: "51px",
                    height: "50px",
                    marginTop: "10px"
                  }, 600 );
            }
            else
            {
                if (i > 1)
                {
                        var x = i - 1;
                        var previouspath = $(this).find('#thumb' + x).attr('src').replace("lg.png","sm.png");
                        $(this).find('#thumb' + x).attr("src",previouspath);
                        
                          $(this).find('#thumb' + x).animate({
                            width: "51px",
                            height: "50px",
                            marginTop: "10px"
                          }, 600 );
                    }
                    
                    var path = $(this).find('#thumb' + i).attr('src').replace("sm.png","lg.png");
                    $(this).find('#thumb' + i).attr("src",path);
                    
                    $(this).find('#thumb' + i).animate({
                        width: "80px",
                        height: "70px",
                        marginTop: "0px"
                      }, 600 );

                    i = i + 1;
                }
            }, 6);
    }
}