﻿function Rotate(
    containerClass,
    random,
    speed,
    timeout) {
    $('.' + containerClass).cycle({
        fx: 'fade',
        speed: speed,
        random: random,
        timeout: timeout
    });
}

function mainmenu() {
    $(" #nav ul ").css({ display: "none" }); // Opera Fix
    $(" #nav li").hover(function() {
        $(this).find('ul:first:hidden').css({ visibility: "visible", display: "none" }).show(400);
    }, function() {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
}

jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++)
        jQuery("<img>").attr("src", arguments[i]);
}

$(document).ready(function() {

    // Setup Main Menu
    mainmenu();

    //Initialise Rotator
    Rotate('Head', 1, 400, 4000);
    $('.Head').css("display", "block");
});


function pageLoad(sender, args) {

    // dynamically preload over images
    $(".jrollover").each(
        function() {
            var overSrc = "";
            if (this.src.endsWith(".gif"))
                overSrc = this.src.replace(".gif", "_Over.gif");
            if (this.src.endsWith(".jpg"))
                overSrc = this.src.replace(".jpg", "_Over.jpg");
            if (this.src.endsWith(".png"))
                overSrc = this.src.replace(".png", "_Over.png");

            jQuery("<img>").attr("src", overSrc);
        }
    );

    // setup rollover actions
    $(".jrollover").hover(
        function() {
            if (this.src.search("_Over") < 0) {
                var overSrc = "";
                if (this.src.endsWith(".gif"))
                    overSrc = this.src.replace(".gif", "_Over.gif");
                if (this.src.endsWith(".jpg"))
                    overSrc = this.src.replace(".jpg", "_Over.jpg");
                if (this.src.endsWith(".png"))
                    overSrc = this.src.replace(".png", "_Over.png");

                this.src = overSrc;
            }
        },
        function() {
            this.src = this.src.replace("_Over", "");
        }
    );
}
