// JavaScript Document
$(document).ready(function () {
    if ($("#slider") != undefined) {
        $("#slider").easySlider();
    }
    if ($(".lightbox") != undefined) {
        $(".lightbox").lightBox();
    }
    /************************************************************************************************************************/
    /* BASEFONTSIZE SELECTION ***********************************************************************************************/
    /************************************************************************************************************************/
    $('.IncreaseFontSize').click(function () {
        var className = $('#BaseFontSize').attr("class");
        switch (className) {
            case 'BaseFontSize1':
                $('#BaseFontSize').removeClass('BaseFontSize1');
                $('#BaseFontSize').addClass('BaseFontSize2');
                break;
            case "BaseFontSize2":
                $('#BaseFontSize').removeClass('BaseFontSize2');
                $('#BaseFontSize').addClass('BaseFontSize3');
                break;
            case "BaseFontSize3":

                break;
            default:
        }
    });
    $('.DecreaseFontSize').click(function () {
        var className = $('#BaseFontSize').attr("class");
        switch (className) {
            case 'BaseFontSize1':

                break;
            case "BaseFontSize2":
                $('#BaseFontSize').removeClass('BaseFontSize2');
                $('#BaseFontSize').addClass('BaseFontSize1');
                break;
            case "BaseFontSize3":
                $('#BaseFontSize').removeClass('BaseFontSize3');
                $('#BaseFontSize').addClass('BaseFontSize2');
                break;
            default:
        }
    });
    /************************************************************************************************************************/

    /************************************************************************************************************************/
    /* SECTION CONTAINER ITEMS, CONTROL 3RD ITEM CSS ATTRIBUTES *************************************************************/
    /************************************************************************************************************************/

    ManageListMargin($(".SectionsList"), 2, 3);
    ManageListMargin($(".FeaturedItems"), 2, 3);
    ManageListMarginClear($(".SectionsList"), 3, 3);

    function ManageListMargin(target, startIndex, targetColumn) {
        var sectionChildren = target.children();
        for (i = startIndex; i < sectionChildren.length; i += targetColumn) {
            sectionChildren[i].className = "FloatRight NoMargin";
        }
    }

    function ManageListMargin(target, startIndex, targetColumn) {
        var sectionChildren = target.children();
        for (i = startIndex; i < sectionChildren.length; i += targetColumn) {
            sectionChildren[i].className = "FloatRight NoMargin";
        }
    }

    function ManageListMarginClear(target, startIndex, targetColumn) {
        var sectionChildren = target.children();
        for (i = startIndex; i < sectionChildren.length; i += targetColumn) {
            sectionChildren[i].className = "ClearFloatAbove";
        }
    }

    /*
    var sectionChildren = $(".SectionsList").children();
    for(i=2; i<sectionChildren.length; i+=3) {
    sectionChildren[i].className = "FloatRight NoMargin";
    }
    */
    /************************************************************************************************************************/

    /************************************************************************************************************************/
    /* SPOT LIGHT ON CONTAINER, ROLL-UP DESCRIPTION *************************************************************************/
    /************************************************************************************************************************/
    $('.SpotLightItem').hover(function () {
        var descriptionHeight = $(".DescriptionTextContainer", this).height();
        $(".DescriptionTextContainer", this).animate({ marginTop: "-" + descriptionHeight + "px" }, { queue: false, duration: 160 });
    }, function () {
        $(".DescriptionTextContainer", this).animate({ marginTop: "0px" }, { queue: false, duration: 160 });
    });
    /************************************************************************************************************************/

    /************************************************************************************************************************/
    /* BACK TO TOP FUNCTIONALITY ********************************************************************************************/
    /************************************************************************************************************************/
    $('.BackToTop').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 250);
    });
    /************************************************************************************************************************/

    /************************************************************************************************************************/
    /* INLINE QUOTE CONTAINER. DISCOVER IF MARGIN-TOP IS REQUIRED ***********************************************************/
    /************************************************************************************************************************/
    $('.InlineQuoteContainer').each(function (index) {
        var quotePosition = $(".InlineQuoteContainer").position();
        var parentObject = $(".InlineQuoteContainer").parent();
        var parentPosition = $(".InlineQuoteContainer").parent().position();

        if (parentObject.is("p")) {
            if (quotePosition.top != parentPosition.top) {
                $(".InlineQuoteContainer").css('margin-top', '10px')
            }
        }
    });
    /************************************************************************************************************************/

    /************************************************************************************************************************/
    /* If the main body has a MainBodyContainer that doesn't have a P tag then add padding
    /************************************************************************************************************************/
    if ($('.MainBodyContainer:first > p').size() == 0) {
        $('.MainBodyContainer:first').css({ 'padding-bottom': '20px' });
    }
});
