﻿    /// <reference path="/jquery-1.4.4-vsdoc.js" />


/* Settings */
var t = 30; // Seconds to cross the screen
var containerPadding = 10; // Padding



/* Don't Touch */
// Initialisation
var d = 0; // Duration
var totalWidth = 0;

jQuery(window).load(function () {

    if (getInternetExplorerVersion() > 6 || getInternetExplorerVersion() == -1) {

        // Get the width of all the images together
        jQuery("#sponsors-container").children().children().each(function () {
            var itemWidth;

            // If the image is inside an <a> tag
            if (this.tagName == "A" && jQuery(this).children("img").exists()) {
                itemWidth = jQuery(this).outerWidth();
            } else {
                // Else it's just an image or link alone
                itemWidth = jQuery(this).outerWidth();
            }

            totalWidth += itemWidth;

        });

        /*
        Duration Function: (Created by Rhys Lloyd 2011)
        d = t(l/w) [in seconds]
        */

        // Calculate the duration time
        d = t * (totalWidth / jQuery("#sponsors-container").outerWidth()) * 1000;

        // Copy the div so we have a continuous flow
        var theHTML = jQuery("#sponsors-container").children().html();
        jQuery("#sponsors-container").children().children(':last-child').after(theHTML);

        // Set the width and start the animation
        jQuery("#sponsors-container").children().width(totalWidth * 2 + containerPadding);

        animatePanel();
    }
});

function animatePanel() {
    jQuery("#sponsors-container").children().animate({
        left: -(totalWidth + containerPadding) // container padding
    }, d,
        "linear",
        function () {
            jQuery(this).css("left", -containerPadding);
            animatePanel();
        }
    );
}

jQuery.fn.exists = function () { return jQuery(this).length > 0; }

/* 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;
}
