$(document).ready(function () {

    $(".linkBoxes > div:last").addClass("lastLinkBox");
    $("span.optionsControl").parents("div").addClass("blockIndex");
    $(".massorySeparator > div").addClass("lastBox");
    $(".selectInner li:last").addClass("selectLink");
    $(".contHolder > div:last").addClass("lastContBox");
    $(".teamRow > div:last-child").each(function () {
        $(this).addClass("lastMemberBox");
    });

    $(".teamRow-publication > div:last-child").each(function () {
        $(this).addClass("lastMemberBox");
    });

    $(".areasRow > div:last-child").each(function () {
        $(this).addClass("lastMemberBox");
    });
    $(".w238 .innetContBox > h3:first-child").each(function () {
        $(this).addClass("titlePosition");
    });
    $(".topBoxesHolder > div:last").addClass("lastMemberBox");
    $(".rowsPosition > div").last("div.w238").addClass("lastBox");
    $(".rowsPosition > div").addClass("equalBlock");
    $(".areasRow:last .singleArea:last .singleAreaCont").addClass("grayBg");
    $("span.optionsControl").click(function () {
        $(this).toggleClass("activeBg");
        if ($(this).next("div").is(':hidden')) {
            $(this).next("div").css('display', 'block');
        } else ($(this).next("div").css('display', 'none'))
    });

    inputReseter($('.searchField'), 'Search Entire Site');
    inputReseter($('.sidebarBox .row span.inp input'), 'Search by Keywords');
    inputReseter($('.firstName'), 'Attorney First Name');
    inputReseter($('.lastName'), 'Attorney Last Name');
    inputReseter($('.keywords'), 'Search by Keywords');
    inputReseter($('.nameField input'), 'Search by Name');

    tabs();

    $('.imageHolder').each(function () {
        var contentHeight = $(this).height();
        $(this).find('.image-inactive').css({
            'top': contentHeight * (-1),
            'display': 'block'
        });
    });

    $('.shareIcon').click(function () {
        $(this).next().fadeToggle();
    });
    $('.shareBoxClose').click(function () {
        $('.shareBox').fadeToggle();
    });

    var pub = $(".att-publications");

    // Get the total height of the publications
    var pubHeight = 0;
    pub.each(function () {
        pubHeight += $(this).outerHeight();
    });

    var presentation = $(".att-presentations");

    // Get the total height of the presentations
    var presentationHeight = 0;
    presentation.each(function () {
        presentationHeight += $(this).outerHeight();
    });

    // By default show only 3 publications
    if (pub.length > 3) {
        pub.hide().slice(0, 3).show();
        pub.slice(0, 3).each(function () {
            pubHeight -= $(this).outerHeight();
        });
    }
    else {
        $("#aPublications").hide();
    }

    if (presentation.length > 3) {
        presentation.hide().slice(0, 3).show();
        presentation.slice(0, 3).each(function () {
            presentationHeight -= $(this).outerHeight();
        });
    }
    else {
        $("#aPresentations").hide();
    }

    var eqBlock = $('.equalBlock');

    // Toggle publications
    $(".allPublications").click(function () {

        if ($(this).text().indexOf("Publications") > 0) {
            if ($(this).text().indexOf("See All") >= 0) {
                pub.show();
                $(this).text("View 3 Publications");
                eqBlock.height(eqBlock.height() + pubHeight);
            }
            else {
                $(this).text("See All Publications")
                pub.hide().slice(0, 3).show();
                eqBlock.height(eqBlock.height() - pubHeight);
            }
        }
        else if ($(this).text().indexOf("Presentations") > 0) {
            if ($(this).text().indexOf("See All") >= 0) {
                presentation.show();
                $(this).text("View 3 Presentations");
                eqBlock.height(eqBlock.height() + presentationHeight);
            }
            else {
                $(this).text("See All Presentations")
                presentation.hide().slice(0, 3).show();
                eqBlock.height(eqBlock.height() - presentationHeight);
            }
        }

        $(this).focus();

        return false;
    });

    // Set the height of the columns
    equalHeight(eqBlock);
    equalHeight($(".singleAreaCont"));
    equalHeight($(".contHolder .mainBlock"));

    //    $('.contHolder a').click(function () {
    //        if ($(this).attr('href').indexOf('#') == 0) {
    //            equalHeight($(".equalBlock"));
    //        }
    //    });


    //equalHeight($(".searchSidebar"));
});


$(window).load(function () {
    $(".officeDetailRight").height($('.w480.leftPosition').height());

    $('.imageHolder').each(function () {
        var contentHeight = $(this).height();
        $(this).find('.image-inactive').css({
            'top': contentHeight * (-1),
            'display': 'block'
        });
    });
});

function clearText(textField) {
    if (textField.defaultValue == textField.value)
        textField.value = ""
}

function ContentAnimation() {
    $('.imageHolder').each(function () {
        var contentHeight = $(this).height();

        $(this).find('.image-inactive').animate({
            'top': 0
        }, 1000);

        $(this).find('.image-active').animate({
            'top': contentHeight
        }, 1000);
    });
}

function equalHeight(somedata) {
    var testHeight = 0;

    somedata.each(function () {
        var boxHeight = $(this).height();

        //alert(somedata.attr('class') + ' - ' + boxHeight);

        if (boxHeight > testHeight) {
            testHeight = boxHeight;
        }
    });

    somedata.css('height', testHeight);
};

function tabs() {
    $('.accordionWrap .accordionCont').hide();
    $('.accordionWrap .accordionCont.visible').show();
    $('.accordionWrap h3.activeAccordion').click(function () {
        if ($(this).attr('class').indexOf('first') == -1) {
            if ($(this).hasClass('current')) {
                $(this).removeClass('current');
                $(this).next().hide();
            } else {
                $(this).addClass('current');
                $(this).next().show();
            }

            $(".officeDetailRight").height($('.w480.leftPosition').height());
        }
    });
}

//----------------------------------------------- Reset input
function inputReseter(jqObj, iniVal) {
    $(jqObj).focus(function () {
        value = $(this).val();
        if (value == iniVal) {
            $(this).val('');
        } else {
            // user has ented input, do nothing
        }
    });
    $(jqObj).blur(function () {
        if ($(this).val() === '') {
            $(this).val(iniVal);
        } else {
            // user has ented input, do nothing
        }
    });
}



function ResetFormPubSearch() {
    $(".select").each(function () {
        var arr = $(this).attr("id").split('$');
        if (arr[1] != null) {
            var val = $("select[id$='" + arr[1] + "'] option:first-child").val();
            $("select[id$='" + arr[1] + "'] option:first-child").attr("selected", "selected");

            $(this).text($("select[id$='" + arr[1] + "'] option:first-child").text());
        }
    });
    return false;
}


