﻿
function load_x_file(fileName, fileType) {
    switch (fileType) {
        case "js":
            var j = document.createElement('script');
            j.type = 'text/javascript';
            j.src = fileName;
            j.async = true;
            if (typeof j != "undefined") {
                var script = document.getElementsByTagName('script')[0];
                script.parentNode.insertBefore(j, script);
            }
            break;
        case "css":
            var c = document.createElement("link");
            c.rel = 'stylesheet';
            c.type = 'text/css';
            c.href = fileName;
            if (typeof c != "undefined") {
                var head = document.getElementsByTagName('head')[0];
                head.parentNode.insertBefore(c, head);
            }
            break;
        default:
    }
}
var msie7 = $.browser.msie && $.browser.version == 7;
if (msie7) {
    load_x_file("/css/publicsite/publicsite_ie7.css", "css");
    load_x_file("/js/publicsite/foodcures/fc_ie7.js", "js");
}
var msie6 = $.browser.msie && $.browser.version == 6;
if (msie6) {
    load_x_file("/js/publicsite/foodcures/fc_ie777.js", "js");
}

var checkForID = function(id) {
    var div = document.getElementById(id);
    return (div) ? true : false;
};
var homePageSlider = function() {

    function formatText(index, panel) {
        return index + "";
    }

    var slider = $('.anythingSlider');
    slider.anythingSlider({
        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 5000,                    // How long between slide transitions in AutoPlay mode
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        animationTime: 600,             // How long the slide transition takes
        hashTags: true,                 // Should links change the hashtag in the URL?
        buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        startText: "Go",             // Start text
        stopText: "Stop",               // Stop text
        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
    }); // END anythingSlider
    $("#slide-jump").click(function() {
        slider.anythingSlider(6);
    });

    $(function() {
        function show_content(id, doRotate) {
            // Content
            $('.content_body').slideUp();
            $("#menu_containerFC #body_" + id).slideDown();

            $("#rotato_img div").hide();
            $("#rotato_img_" + id).stop().show().css('position', 'absolute');
            $("#rotato_img_1").css('margin-top', '0px');

            // Menu (removes on class for all links; the mouseover event takes care of it)
            $("#menu_containerFC a").removeClass('on').addClass('off');
            $(".homepage-rotato-v2").removeClass('off');

            if ($("#menu_containerFC a").hasClass('no-bg')) {
                $(".no-bg").removeClass('on').removeClass('off');
            }
            if (doRotate) {
                $("#menu_containerFC a#" + id).removeClass('off').addClass('on');
                $(".homepage-rotato-v2").removeClass('off');
            }
            return false;
        }

        var rotate = setInterval(function() {
            if ($("#menu_containerFC a#1").hasClass('on')) {
                show_content(2, true);
            } else if ($("#menu_containerFC a#2").hasClass('on')) {
                show_content(3, true);
            } else if ($("#menu_containerFC a#3").hasClass('on')) {
                show_content(1, true);
            }
        }, 4000);
        
        // Mouseover event
        function hoverExpandEvent() {
            if ($(this).hasClass('off') && !$(this).hasClass('no-bg')) {
                show_content($(this).attr("id"));
                $(this).removeClass('off').addClass('on');
                $(".homepage-rotato-v2").removeClass('off');
                window.clearInterval(rotate);
            }
        }

        function dummy() {
            // dummy function: 2 args are 
            // required for hoverIntent to work correctly
            return false;
        }

        $("#rotatingContentFC").show();
        $("#menu_containerFC li a").hoverIntent(hoverExpandEvent, dummy);

    });
};         // END homePageSlider

$(document).ready(function() {
    if (checkForID("rotato_img")) {
        homePageSlider();
    }

    // Find a Food Cure AND Top Nav Menu - Button Mouseover and SUBNAV Show
    $.each([1,2,3,4,5], function(index, value) {
        $.each([$(".topnavitem_level_" + value + " a"), $(".topnavitem_level_" + value + "_Page a"), $("#subnav" + value)], function() {
            $(this).bind("mouseover", function() {
                $("#subnav" + value).show();
                $(".topnavitem_level_" + value).addClass('topnavitem_level_' + value + '_ON');
                $(".topnavitem_level_" + value + "_Page").addClass('topnavitem_level_' + value + '_ON');
            });
        });
    });

    // Find a Food Cure AND Top Nav Menu - Button Mouseout and SUBNAV Hide
    $.each([1,2,3,4,5], function(index, value) {
        $.each([$(".topnavitem_level_" + value + " a"), $(".topnavitem_level_" + value + "_ON a"), $(".topnavitem_level_" + value + "_Page a"), $("#subnav" + value)], function() {
            $(this).bind("mouseout", function() {
                $("#subnav" + value).hide();
                $(".topnavitem_level_" + value).removeClass('topnavitem_level_' + value + '_ON');
                $(".topnavitem_level_" + value).removeClass('topnavitem_level_' + value + '_Page');
                $(".topnavitem_level_" + value + "_Page").removeClass('topnavitem_level_' + value + '_ON');
            });
        });
    });
    
    // Find a Food Cure AND Top Nav Menu - Button Mouseover and SUBNAV Show
    $.each([1,2,3,4,5,6,7], function(index, value) {
    $.each([$(".publicTopNavigation" + value + "FC"), $(".publicTopNavigation" + value + "FCON"), $("#TopSubnav" + value)], function() {
            $(this).bind("mouseover", function() {
                $("#TopSubnav" + value).show();
                $(".publicTopNavigation" + value + "FC").addClass('publicTopNavigation' + value + 'FCON');
                $(".publicTopNavigation" + value + "FCON").addClass('publicTopNavigation' + value + 'FCON');
             });
        });
    });

    // Find a Food Cure AND Top Nav Menu - Button Mouseout and SUBNAV Hide
    $.each([1,2,3,4,5,6,7], function(index, value) {
    $.each([$(".publicTopNavigation" + value + "FC"), $(".publicTopNavigation" + value + "FCON"), $("#TopSubnav" + value)], function() {
            $(this).bind("mouseout", function() {
                $("#TopSubnav" + value).hide();
                $(".publicTopNavigation" + value + "FC").removeClass('publicTopNavigation' + value + 'FCON');
             });
        });
    });

});
