﻿function Navigation()
{
    var _this = this;
    this.eNavigationContainer = $("#navigation");
    this.aImages = $("> div > a:not(.Selected) > img", this.eNavigationContainer);

    this.aImages.each
    (
        function()
        {
            // parse out the file path
            var oImagePath = _this.parseFilePath($(this).attr("src"));
            
            // create the new path of the image to load
            var sPathToPreload = oImagePath.path + oImagePath.name + "_Over" + oImagePath.extension;
            
            // preload the images
            $("<img/>").attr("src", sPathToPreload);
        }
    )

    $(window).load
    (
        function()
        {
            _this.create();
        }
    )
}

Navigation.prototype.create = function()
{
    var _this = this;
    this.aImages.mouseover
    (
        function()
        {
            // parse out the file path
            var oImagePath = _this.parseFilePath($(this).attr("src"));

            $(this).attr("src", oImagePath.path + oImagePath.name + "_Over" + oImagePath.extension);
        }
    ).mouseout
    (
        function()
        {
            // parse out the file path
            var oImagePath = $(this).attr("src").replace("_Over", "");

            $(this).attr("src", oImagePath);
        }
    )
}

Navigation.prototype.parseFilePath = function(sRawPath)
{
    var oPathParts = new Object();
    oPathParts.path = sRawPath.substring(0, sRawPath.lastIndexOf("/") + 1);
    oPathParts.name = sRawPath.substring(sRawPath.lastIndexOf("/") + 1, sRawPath.lastIndexOf("."));
    oPathParts.extension = sRawPath.substring(sRawPath.lastIndexOf("."));
    return oPathParts;
}