﻿/// <reference path="/jquery-1.5-vsdoc.js" />

/* SETTINGS */
var Timing = 4.5;  // Seconds between animation
var Speed = 2.5; // Seconds animation duration


/* ADVANCED SETTINGS */
var Easing = 'easeOutSine';
var Wrapper = '.fader';


/* FUNCTIONS */
Timing = Speed + Timing * 1000;  // Convert to milliseconds
Speed = Speed * 1000;
var ImageHtmlList = new Array(); // Also find each stopping position
var CurrentItem = 0;
var IntervalFunction = 'FadeIn()';
var IntervalObject = setInterval(IntervalFunction, Timing);

// Check IE
var Browser = getInternetExplorerVersion();
if (Browser == -1) Browser = 100;

$(window).load(function () {
    // Get the HTML for all images and remove from DOM (except the first)
    $(Wrapper + " img").each(function () {
        ImageHtmlList.push($(this)[0]);
        if (ImageHtmlList.length > 1) $(this).remove();
    });
});

function FadeIn() {
    // Fade in the next item
    CurrentItem++;

    // Loop
    if (CurrentItem == ImageHtmlList.length) CurrentItem = 0;

    // Add item to DOM
    $(Wrapper).children().before(ImageHtmlList[CurrentItem]);
    // Make item visible
    $(Wrapper).children(':first').show();

    // Fade out top item then remove from DOM
    $(Wrapper).children(':last').fadeOut(Speed, Easing, function () {
        $(this).remove()
    });
}


/* IE Detection */
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
