﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

var currentImg = 1;
var totImg = 7;
var imageDelay = 5000;
var textDelay = 3000;
var firstRun = true;
$(document).ready(function() {
    update();
    /*Banner effects*/
    //setTimeout(runFade, 3000);
    $(function() {
        //setInterval(update, 10000); USED WHEN INNER IMAGE IS PROVIDED
        update();
        setInterval(update, 10000);
    });

    function update() {
        if (firstRun) {
            //Generate a random starting point
            currentImg = randomXToY(1, totImg);

            //Show the next image in the banner then fade in the text after the specified delay. Do this only until total images have been reached.
            $("#img_" + currentImg + " img.main").fadeIn(1);

            //$("#img_" + currentImg + "  div.info").delay(3000).animate({ opacity: 10 }, { duration: textDelay });
            //$("#img_" + currentImg + " div.info").delay(1000).fadeIn(textDelay); LATEST

            firstRun = false;
            currentImg += 1;
        } else {
            if (currentImg <= totImg) {
                //console.log(currentImg);
                //Fade out the last text line.
                //$("#img_" + (currentImg - 1) + " div.info").animate({ opacity: 0 }, { duration: textDelay });
                $("#img_" + (currentImg - 1) + " div.info").fadeOut(textDelay);
                $("#img_" + (currentImg - 1) + " img.main").delay(2000).fadeOut(imageDelay);


                //Show the next image in the banner then fade in the text after the specified delay. Do this only until total images have been reached.
                $("#img_" + currentImg + " img.main").delay(2000).fadeIn(imageDelay);


                //$("#img_" + currentImg + "  div.info").delay(5000).animate({ opacity: 10 }, { duration: textDelay });
                //$("#img_" + currentImg + " div.info").delay(5000).fadeIn(textDelay); LATEST


                currentImg += 1;
            } else if (currentImg > totImg) {
                //It's back to the beginning again so fade out the last image. ie: totImg
                //console.log("back to beginning: " + currentImg);

                //$("#img_" + totImg + "  div.info").animate({ opacity: 0 }, { duration: textDelay });
                //$("#img_" + totImg + " div.info").fadeOut(textDelay);LATEST

                //$("#img_" + totImg + " img.main").delay(2000).fadeOut(imageDelay);
                $("#img_" + 1 + " img.main").delay(2000).fadeIn(imageDelay);

                //$("#img_" + 1 + "  div.info").delay(5000).animate({ opacity: 10 }, { duration: textDelay });
                //$("#img_" + 1 + " div.info").delay(5000).fadeIn(textDelay);
                currentImg = 2; //This is set to 2 as 1 has effectively run as this last image here. ie: 1 over totImg
            }
            //            else if (currentImg = totImg) {
            //                console.log("total image number: " + currentImg);
            //                $("#img_" + currentImg + " img.main").fadeIn(imageDelay);
            //                //And reset the counter
            //                currentImg = 1;
            //            }
        }
    }


    //    function removeFilter() {

    //        $("#img_" + currentImg + " span").removeAttr("filter");
    //        console.log("Filter removed from: #img_" + currentImg + " span" );
    //    }



    //$(".notice")
    //   .fadeIn(function() {
    //       setTimeout(function() {
    //           $(".notice").fadeOut("fast");
    //       }, 2000);
    //   });



    //Hide the feedback dropdown if it has been completed successfully.
    function runFade() {

        //console.log(currentImg)

        currentImg += 1;


    }

    //Generate random number upto the current number between those supplied.
    function randomXToY(minVal, maxVal, floatVal) {
        var randVal = minVal + (Math.random() * (maxVal - minVal));
        return typeof floatVal == 'undefined' ? Math.round(randVal) : randVal.toFixed(floatVal);
    }

});


    
    
    
