﻿(function($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)

// namespace
$.AmicaConnections = {
    global: {}
};

$.AmicaConnections.HideContent = function() {
    //hide as soon as possible for better transition
    // if (!$.browser.msie) $("#wrap").hide();
    //$("#wrap").hide();
};



$(document).ready(function() {

    //hide as soon as possible for better transition   

    /*** Preload ***/
//    jQuery.preLoadImages("/_images/main-nav-sprite.png",
//                                "/_css/images/have-a-story-hover.png",
//                                "/_css/images/nav-story-category-hover.gif",
//                                "/_css/images/stories-share-hover.png",
//                                "/_css/images/stories-next-hover.png");


    var pathToFind = (window.location.pathname);
    var firstPathPartArray = pathToFind.split("/");

    if (firstPathPartArray.length > 1) {

        firstPathPart = firstPathPartArray[1];



        /*** Style nav for story sub-types ***/

        if (firstPathPart.length != 0) {
            $("#left-nav a[href*='" + firstPathPart + "']").addClass("current");
        }

        if (firstPathPart == "Auto.aspx" ||
                firstPathPart == "Home.aspx" ||
                firstPathPart == "Life.aspx" ||
                firstPathPart == "Employee.aspx" ||
                firstPathPart == "Map.aspx" ||
                firstPathPart == "/road-trip/") {
            $("#left-nav a[href^='" + "/Stories.aspx" + "']").addClass("current");
        }

        if (firstPathPart.length != 0) {
            /*** Style current page link ***/
            $("#story-nav a[href^='" + "/" + firstPathPart + "']").addClass("nav-story-current");
            $("#story-nav a[href^='" + "/" + firstPathPart + "']").css("text-decoration", "none");
        }


        if (firstPathPart == "Products.aspx" ||
                    firstPathPart == "About-Amica.aspx") {
            $("#footer-asterisk").css("display", "inline");
        }


    }







    $(".nav-get-a-quote").hover(
    function() {
        $(this).stop().animate({ "opacity": "0" }, "slow");
    },
    function() {
        $(this).stop().animate({ "opacity": "1" }, "slow");
    });

    $(".nav-stories").hover(
    function() {
        if (!$(this).hasClass("current"))
            $(this).stop().animate({ "opacity": "0" }, "fast");
    },
    function() {
        $(this).stop().animate({ "opacity": "1" }, "fast");
    });

    $(".nav-ads").hover(
    function() {
        if (!$(this).hasClass("current"))
            $(this).stop().animate({ "opacity": "0" }, "fast");
    },
    function() {
        $(this).stop().animate({ "opacity": "1" }, "fast");
    });

    $(".nav-about").hover(
    function() {
        if (!$(this).hasClass("current"))
            $(this).stop().animate({ "opacity": "0" }, "fast");
    },
    function() {
        $(this).stop().animate({ "opacity": "1" }, "fast");
    });

    $(".nav-products").hover(
    function() {
        if (!$(this).hasClass("current"))
            $(this).stop().animate({ "opacity": "0" }, "fast");
    },
    function() {
        $(this).stop().animate({ "opacity": "1" }, "fast");
    });

    $(".nav-rt").hover(
    function () {
        if (!$(this).hasClass("current"))
            $(this).stop().animate({ "opacity": "0" }, "fast");
    },
    function () {
        $(this).stop().animate({ "opacity": "1" }, "fast");
    });





    //change to window.load at a later point
    // FADE IN, IE uses a page transition via a meta tag in the conditional comments
    // if (!$.browser.msie) {
    /*       
    var $container = $("#wrap");
    $container.fadeIn(600);

        $(".fadelink").live('click', function(e) {
    e.preventDefault();
    var link = this;
    $container.fadeOut(600, function() {
    document.location = link.href;
    });
    });
    */





});
  
    

