
$(document).ready(function(){
    if (device == 1){
        var PrototypesObject = new Prototypes();
        var noImages = images.length;
        var imageLoaded = new Array();
        var imageWidth = new Array();
        var imageHeight = new Array();
        var HTML = '';
        var i;
        var TransitionDelay = 2000;
        var TransitionDuration = 300;
        var currentImage = 0;
        var AnimationID;

        for (i=1; i<=(noImages); i++){
            HTML += '<div class="splash-image" id="splash-image'+i+'"></div>';
            imageLoaded[i] = false;
        }
        HTML += '<div class="splash-image" id="splash-logo"></div>';
        $('#splash-slideshow').html(HTML);

        $('#splash-slideshow').click(function(){
            window.location = 'main.php';
        });

        RPSplashSlideshow();
        loadImage(1);
        animation();

        $(window).resize(function(){
            RPSplashSlideshow();
        });

        function RPSplashSlideshow(){
            $('#splash-slideshow').width($(window).width());
            $('#splash-slideshow').height($(window).height());
            $('.splash-image').width($(window).width()-100);
            $('.splash-image').height($(window).height()-100);

            for (i=1; i<=(noImages); i++){
                if (imageLoaded[i]){
                    PrototypesObject.ResizeItem2('#splash-image'+i, $(window).width(), $(window).height(), imageWidth[i], imageHeight[i], 'center');
                }
            }
        }

        function loadImage(no){
            var img = new Image();
            $(img).load(function(){
                imageLoaded[no] = true;
                $('#splash-image'+no).html(this);
                imageWidth[no] = $(this).width();
                imageHeight[no] = $(this).height();
                PrototypesObject.ResizeItem2('#splash-image'+no, $(window).width(), $(window).height(), imageWidth[no], imageHeight[no], 'center');
                $('#splash-image'+no).css('display', 'none');
                if (no < noImages){
                    loadImage(no+1);
                }
            }).attr('src', images[no-1]);
        }

        function animation(){
            clearInterval(AnimationID);
            var previousImage = currentImage;
            var nextImage = currentImage+1;
            if (currentImage == noImages){
                nextImage = 1;
            }

            if (imageLoaded[nextImage] == true){
                currentImage = nextImage;

                if (previousImage > 0){
                    $('#splash-image'+previousImage).fadeOut(TransitionDuration, function(){
                        $('#splash-image'+currentImage).fadeIn(TransitionDuration, function(){
                            AnimationID = setInterval(animation, TransitionDelay);
                        });
                    });
                }
                else{
                    $('#splash-image'+currentImage).fadeIn(TransitionDuration, function(){
                        AnimationID = setInterval(animation, TransitionDelay);
                    });
                }
            }
            else{
                AnimationID = setInterval(animation, 300);
            }
        }
    }
    else{
        $('object').attr('height', $(window).height());
        $(window).resize(function(){
            $('object').attr('height', $(window).height());
        });
    }
});
