﻿// Speed of the automatic slideshow
var slideshowSpeed = 7000;
var isHover = false;

function setHover(hovering) {
	isHover = hovering;
}

// images 
var bgimages;

function setImageArray(pageName) {

    bgimages = new Array();

    switch (pageName){
        case "homepage":        
            bgimages[0] = "images/StrategyRollover.jpg";
            bgimages[1] = "images/DesignRollover.jpg";
            bgimages[2] = "images/ExecutionRollover.jpg";
            bgimages[3] = "images/EvaluationRollover.jpg";
            slideshowSpeed = 7000;
            break;
        case "design":
            bgimages[0] = "images/Design.jpg";
            bgimages[1] = "images/DesignRollover.jpg"; 
            slideshowSpeed = 12000;
            break;
        case "strategy":
            bgimages[0] = "images/Strategy.jpg";
            bgimages[1] = "images/StrategyRollover.jpg";
            slideshowSpeed = 12000;
            break;
        case "execution":
            bgimages[0] = "images/Execution.jpg";
            bgimages[1] = "images/ExecutionRollover.jpg";
            slideshowSpeed = 12000;
            break;
        case "evaluation":
            bgimages[0] = "images/Evaluation.jpg";
            bgimages[1] = "images/EvaluationRollover.jpg";
            slideshowSpeed = 12000;
            break;
    }

}

function bindSlideshow() {

     // control variables
    var activeContainer = 1;
    var currentImg = 0;
    var navigate = function (direction) {

		if (isHover) return;
	
        // Check which current image we need to show
        if (direction == "next") {
            currentImg++;
            if (currentImg == bgimages.length + 1) {
                currentImg = 1;
            }
        } else {
            currentImg--;
            if (currentImg == 0) {
                currentImg = bgimages.length;
            }
        }

        // Check which container we need to use
        var currentContainer = activeContainer;
        if (activeContainer == 1) {
            activeContainer = 2;
	    $("#hdnActive").val("2");
        } else {
            activeContainer = 1;
	    $("#hdnActive").val("1");
        }

        showImage(bgimages[currentImg - 1], currentContainer, activeContainer);

    };

    var currentZindex = -1;
    var showImage = function (photoObject, currentContainer, activeContainer) {

        // Make sure the new container is always on the background
        currentZindex--;

        // Set the background image of the new active container
        $("#headerimg" + activeContainer).css({
            "background-image": "url(" + photoObject + ")",
            "display": "block",
            "z-index": currentZindex
        });
        
        // Fade out the current container
        // and display the header text when animation is complete
        $("#headerimg" + currentContainer).fadeOut(1500);
		
		// Set current photo to hidden field
		 $("#bkgrnd").val(photoObject);

    };

    // We should statically set the first image
    navigate("next");

    // Start playing the animation
    interval = setInterval(function () {
        navigate("next");
    }, slideshowSpeed);

}
