/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// Speed of the automatic slideshow
var slideshowSpeed = 30000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var lar = screen.width;
var alt = screen.height;



if (lar <= 1024) {
    var photos = [
    { "image": "bg1_1024x768.jpg" }
    , { "image": "bg2_1024x768.jpg" }
    , { "image": "bg3_1024x768.jpg" }
    , { "image": "bg4_1024x768.jpg" }
    , { "image": "bg5_1024x768.jpg" }
    , { "image": "bg6_1024x768.jpg" }
    , { "image": "bg7_1024x768.jpg" }
    , { "image": "bg8_1024x768.jpg" }
    , { "image": "bg9_1024x768.jpg" }
    , { "image": "bg10_1024x768.jpg" }
    , { "image": "bg11_1024x768.jpg" }
    , { "image": "bg12_1024x768.jpg" }
    , { "image": "bg13_1024x768.jpg" }
    , { "image": "bg14_1024x768.jpg" }
    , { "image": "bg15_1024x768.jpg" }
    , { "image": "bg16_1024x768.jpg" }
    , { "image": "bg17_1024x768.jpg" }
    , { "image": "bg18_1024x768.jpg" }
    , { "image": "bg19_1024x768.jpg" }
    , { "image": "bg20_1024x768.jpg" }
    , { "image": "bg21_1024x768.jpg" }
    , { "image": "bg22_1024x768.jpg" }
    , { "image": "bg23_1024x768.jpg" }
    ];
}
if (lar == 1280) {
    var photos = [
    { "image": "bg1_1280x960.jpg" }
    , { "image": "bg2_1280x960.jpg" }
    , { "image": "bg3_1280x960.jpg" }
    , { "image": "bg4_1280x960.jpg" }
    , { "image": "bg5_1280x960.jpg" }
    , { "image": "bg6_1280x960.jpg" }
    , { "image": "bg7_1280x960.jpg" }
    , { "image": "bg8_1280x960.jpg" }
    , { "image": "bg9_1280x960.jpg" }
    , { "image": "bg10_1280x960.jpg" }
    , { "image": "bg11_1280x960.jpg" }
    , { "image": "bg12_1280x960.jpg" }
    , { "image": "bg13_1280x960.jpg" }
    , { "image": "bg14_1280x960.jpg" }
    , { "image": "bg15_1280x960.jpg" }
    , { "image": "bg16_1280x960.jpg" }
    , { "image": "bg17_1280x960.jpg" }
    , { "image": "bg18_1280x960.jpg" }
    , { "image": "bg19_1280x960.jpg" }
    , { "image": "bg20_1280x960.jpg" }
    , { "image": "bg21_1280x960.jpg" }
    , { "image": "bg22_1280x960.jpg" }
    , { "image": "bg23_1280x960.jpg" }
	];
}
if (lar > 1280 && lar <= 1440) {
    var photos = [
    { "image": "bg1_1440x960.jpg" }
    , { "image": "bg2_1440x960.jpg" }
    , { "image": "bg3_1440x960.jpg" }
    , { "image": "bg4_1440x960.jpg" }
    , { "image": "bg5_1440x960.jpg" }
    , { "image": "bg6_1440x960.jpg" }
    , { "image": "bg7_1440x960.jpg" }
    , { "image": "bg8_1440x960.jpg" }
    , { "image": "bg9_1440x960.jpg" }
    , { "image": "bg10_1440x960.jpg" }
    , { "image": "bg11_1440x960.jpg" }
    , { "image": "bg12_1440x960.jpg" }
    , { "image": "bg13_1440x960.jpg" }
    , { "image": "bg14_1440x960.jpg" }
    , { "image": "bg15_1440x960.jpg" }
    , { "image": "bg16_1440x960.jpg" }
    , { "image": "bg17_1440x960.jpg" }
    , { "image": "bg18_1440x960.jpg" }
    , { "image": "bg19_1440x960.jpg" }
    , { "image": "bg20_1440x960.jpg" }
    , { "image": "bg21_1440x960.jpg" }
    , { "image": "bg22_1440x960.jpg" }
    , { "image": "bg23_1440x960.jpg" }
	];
}
if (lar > 1440 && lar <= 1600) {
    alert(1600);
    var photos = [
    { "image": "bg1_1600x1200.jpg" }
    , { "image": "bg2_1600x1200.jpg" }
    , { "image": "bg3_1600x1200.jpg" }
    , { "image": "bg4_1600x1200.jpg" }
    , { "image": "bg5_1600x1200.jpg" }
    , { "image": "bg6_1600x1200.jpg" }
    , { "image": "bg7_1600x1200.jpg" }
    , { "image": "bg8_1600x1200.jpg" }
    , { "image": "bg9_1600x1200.jpg" }
    , { "image": "bg10_1600x1200.jpg" }
    , { "image": "bg11_1600x1200.jpg" }
    , { "image": "bg12_1600x1200.jpg" }
    , { "image": "bg13_1600x1200.jpg" }
    , { "image": "bg14_1600x1200.jpg" }
    , { "image": "bg15_1600x1200.jpg" }
    , { "image": "bg16_1600x1200.jpg" }
    , { "image": "bg17_1600x1200.jpg" }
    , { "image": "bg18_1600x1200.jpg" }
    , { "image": "bg19_1600x1200.jpg" }
    , { "image": "bg20_1600x1200.jpg" }
    , { "image": "bg21_1600x1200.jpg" }
    , { "image": "bg22_1600x1200.jpg" }
    , { "image": "bg23_1600x1200.jpg" }


	];
}

if (lar > 1600) {
    var photos = [
    { "image": "bg1_2000x1500.jpg" }
    , { "image": "bg2_2000x1500.jpg" }
    , { "image": "bg3_2000x1500.jpg" }
    , { "image": "bg4_2000x1500.jpg" }
    , { "image": "bg5_2000x1500.jpg" }
    , { "image": "bg6_2000x1500.jpg" }
    , { "image": "bg7_2000x1500.jpg" }
    , { "image": "bg8_2000x1500.jpg" }
    , { "image": "bg9_2000x1500.jpg" }
    , { "image": "bg10_2000x1500.jpg" }
    , { "image": "bg11_2000x1500.jpg" }
    , { "image": "bg12_2000x1500.jpg" }
    , { "image": "bg13_2000x1500.jpg" }
    , { "image": "bg14_2000x1500.jpg" }
    , { "image": "bg15_2000x1500.jpg" }
    , { "image": "bg16_2000x1500.jpg" }
    , { "image": "bg17_2000x1500.jpg" }
    , { "image": "bg18_2000x1500.jpg" }
    , { "image": "bg19_2000x1500.jpg" }
    , { "image": "bg20_2000x1500.jpg" }
    , { "image": "bg21_2000x1500.jpg" }
    , { "image": "bg22_2000x1500.jpg" }
    , { "image": "bg23_2000x1500.jpg" }
	];
}


$(document).ready(function () {

    var interval;
    $("#control").toggle(function () {
        stopAnimation();
    }, function () {
        // Change the background image to "pause"
        $(this).css({ "background-image": "url(bg/btn_pause.png)" });

        // Show the next image
        navigate("next");

        // Start playing the animation
        interval = setInterval(function () {
            navigate("next");
        }, slideshowSpeed);
    });


    var activeContainer = 1;
    var currentImg = 0;
    var animating = false;
    var navigate = function (direction) {
        // Check if no animation is running. If it is, prevent the action
        if (animating) {
            return;
        }

        function Rand() {

            var anter = currentImg;
            currentImg = Math.random() * 24;
            currentImg = Math.floor(currentImg);
            if (anter == currentImg) {
                currentImg = Rand();
            }
            if (currentImg == 0) {
                currentImg = Rand();
            }
            return currentImg
        }

        // Check which current image we need to show
        if (direction == "next") {
            //            currentImg++;
            //            if (currentImg == photos.length + 1) {
            //                currentImg = 1;
            //            }
            currentImg = Rand();
        } else {
            currentImg--;
            if (currentImg == 0) {
                currentImg = photos.length;
            }
        }

        // Check which container we need to use
        var currentContainer = activeContainer;
        if (activeContainer == 1) {
            activeContainer = 2;
        } else {
            activeContainer = 1;
        }


        showImage(photos[currentImg - 1], currentContainer, activeContainer);

    };

    var currentZindex = -1;
    var showImage = function (photoObject, currentContainer, activeContainer) {
        animating = true;

        // 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(bg/" + photoObject.image + ")",
            "display": "block",
            "background-position": "center bottom",
            "z-index": currentZindex
        });




        // Fade out the current container
        // and display the header text when animation is complete
        $("#headerimg" + currentContainer).fadeOut(function () {
            setTimeout(function () {
                $("#headertxt").css({ "display": "block" });
                animating = false;
            }, 500);
        });
    };

    var stopAnimation = function () {
        // Change the background image to "play"
        $("#control").css({ "background-image": "url(bg/btn_play.png)" });

        // Clear the interval
        clearInterval(interval);
    };

    // We should statically set the first image
    navigate("next");

    // Start playing the animation
    interval = setInterval(function () {
        navigate("next");
    }, slideshowSpeed);

});

