﻿
var baseCurrentSlide = 0;
var baseZIndex = 10000;

//var totalSlides = 0;
var currentSlide = baseCurrentSlide;
var contentSlides = "";

var noOfSlides = 0;

var moveForward = true;
var zIndex = baseZIndex;





$(document).ready(function () {

    var totalWidth = 0;

    $("#portfolioslideshow-holder").children().each(function () {

        $(this).css("z-index", zIndex);
        // $(this).attr("ID", "S" + currentSlide);

        totalWidth += this.clientWidth;

        zIndex--;
        noOfSlides++;
        currentSlide++
    });

    currentSlide = baseCurrentSlide;

    $("#portfolioslideshow-area img").show();


    if ($(".portfolioslideshow-content").length > 0) {
        var totalWidth = 0;
        contentSlides = $(".portfolioslideshow-content");
              
        $("#portfolioslideshow-holder").width(totalWidth);
        $("#portfolioslideshow-scroller").attr({ scrollLeft: 0 });

        updateContentText(currentSlide);
        updateButtons(currentSlide);

        setInterval(function () { runSlideShow() }, 8000);
    }
});




function runSlideShow(currentSlide) {

    showSlide();
}


function showSlide() {

    updateContentHolder();
    
}    

function updateContentText(position) {

    $("#clientUrl").attr("href", showcaseDetails[position][1]);
    $("#clientTitle").text(showcaseDetails[position][0]);
}


function updateContentHolder() {

    $("#S" + currentSlide).stop().animate({ marginLeft: -950 }, 800, function () {

        $("#S" + currentSlide).css("z-index", parseInt($("#S" + currentSlide).css("z-index")) - (noOfSlides));
        $("#S" + currentSlide).animate({ marginLeft: 0 }, 1);

        currentSlide = currentSlide + 1;

        if ((currentSlide - (noOfSlides)) == baseCurrentSlide)
            currentSlide = baseCurrentSlide;

        updateContentText(currentSlide);
        updateButtons(currentSlide);

    });

    
}

function updateButtons(position) {

    galleryControls = $(".gallerycontrol");
    galleryControls.each(function (i) {
        $(this).attr("onclick", "");

        if (i == (position)) {
            $(this).attr("src", "/Content/Images/case-study-gallery-icon-active.gif");
        }
        else {
            $(this).attr("src", "/Content/Images/case-study-gallery-icon.gif");
        }
    });

}


