﻿var BMM = {

    init: function () {
    },

    setupEditorAnchors: function () {

        $("a.xrm-attribute-ref").text("Edit");

        $(".xrm-attribute").hover(function () { $(this).find("a.xrm-attribute-ref").show(); }, function () { $(this).find("a.xrm-attribute-ref").hide(); });

        $("a.xrm-attribute-ref").click(function (e) {

            e.preventDefault;
            var arrValues = $(this).attr("href").split('/');

            if ($(this).parent().hasClass("xrm-editable-html"))
                var oWindow = window.radopen("/shared/editors/fulleditor.aspx?id=" + arrValues[3].replace("adx_webpages(guid'", '').replace("')", '') + "&type=" + arrValues[4], "rwFullEditor");
            else if ($(this).parent().hasClass("xrm-editable-text"))
                var oWindow = window.radopen("/shared/editors/simpleeditor.aspx?id=" + arrValues[3].replace("adx_webpages(guid'", '').replace("')", '') + "&type=" + arrValues[4], "rwSimpleEditor");
            else if ($(this).parent().hasClass("uploaddocumentwrapper"))
                var oWindow = window.radopen("/shared/editors/documentupload.aspx?parentid=" + arrValues[1] + "&isevent=" + arrValues[2], "rwDocumentUpload");

            return false;

        });

    },

    setupModuleEditors: function () {

        $("div.module").hover(function () { $(this).find("a.editlink").show(); }, function () { $(this).find("a.editlink").hide(); });

        $("a.editlink").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/fulleditor.aspx?id=" + $(this).attr("rel") + "&type=adx_copy", "rwFullEditor");
            return false;
        });

    },

    setupTitleEditors: function () {

        $("h1").hover(function () { $(this).find("a.edittitlelink").show(); }, function () { $(this).find("a.edittitlelink").hide(); });

        $("a.edittitlelink").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/simpleeditor.aspx?id=" + $(this).attr("rel") + "&type=adx_title", "rwSimpleEditor");
            return false;
        });

    },

    setupDocumentEditors: function () {

        $(".publication-downloads li").hover(function () { $(this).css("style", "position:relative;"); $(this).find(".editoptions").show(); }, function () { $(this).find(".editoptions").hide(); })

        $(".download li").hover(function () { $(this).find(".editoptions").show(); }, function () { $(this).find(".editoptions").hide(); })

        $(".uploaddocumentwrapper").hover(function () { $(this).find("a.uploaddocument").show(); }, function () { $(this).find("a.uploaddocument").hide(); });

        $("a.uploaddocument").click(function (e) {
            e.preventDefault;
            var arrValues = $(this).attr("href").split('/');
            //alert(arrValues[1] + " " + arrValues[2]);
            var oWindow = window.radopen("/shared/editors/documentupload.aspx?parentid=" + arrValues[1] + "&isevent=" + arrValues[2], "rwDocumentUpload");
            return false;
        });

        $("a.documentedit").click(function (e) {
            e.preventDefault;

            if ($(this).hasClass("event"))
                var oWindow = window.radopen("/shared/editors/documentupload.aspx?documentid=" + $(this).attr("href") + "&isevent=true", "rwDocumentUpload");
            else
                var oWindow = window.radopen("/shared/editors/documentupload.aspx?documentid=" + $(this).attr("href"), "rwDocumentUpload");

            return false;
        });
    },

    setupGalleryEditors: function () {

        $(".staff-index li").hover(function () { $(this).find(".editoptions").show(); }, function () { $(this).find(".editoptions").hide(); })

        $(".uploaddocumentwrapper").hover(function () { $(this).find("a.addgallery").show(); }, function () { $(this).find("a.addgallery").hide(); });

        $("a.addgallery").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editgallery.aspx", "rwGalleryEditor");
            return false;
        });

        $("a.galleryedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editgallery.aspx?eventgalleryid=" + $(this).attr("href"), "rwGalleryEditor");
            return false;
        });
    },

    setupGalleryItemEditors: function () {

        $(".t2d-list li").hover(function () { $(this).find(".galleryitemeditoptions").show(); }, function () { $(this).find(".galleryitemeditoptions").hide(); })

        $(".uploaddocumentwrapper").hover(function () { $(this).find("a.addgalleryitem").show(); }, function () { $(this).find("a.addgalleryitem").hide(); });

        $("a.addgalleryitem").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/galleryitemupload.aspx?galleryid=" + $(this).attr("rel"), "rwGalleryItemEditor");
            return false;
        });

        $("a.galleryitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/galleryitemupload.aspx?galleryitemid=" + $(this).attr("href"), "rwGalleryItemEditor");
            return false;
        });
    },

    setupResourceEditors: function () {

        $(".staff-index li").hover(function () { $(this).find(".editresourceoptions").show(); }, function () { $(this).find(".editresourceoptions").hide(); })

        $(".editresourcewrapper").hover(function () { $(this).find("a.addresearchresource").show(); }, function () { $(this).find("a.addresearchresource").hide(); });

        $("a.addresearchresource").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editresearchresource.aspx", "rwResourceEditor");
            return false;
        });

        $("a.resourceitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editresearchresource.aspx?resourceid=" + $(this).attr("href"), "rwResourceEditor");
            return false;
        });
    },

    setupStaffEditors: function () {

        $(".staff-index li").hover(function () { $(this).find(".editstaffoptions").show(); }, function () { $(this).find(".editstaffoptions").hide(); })

        $(".editstaffwrapper").hover(function () { $(this).find("a.addstaff").show(); }, function () { $(this).find("a.addstaff").hide(); });

        $("a.addstaff").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editcontact.aspx?type=staff", "rwContactEditor");
            return false;
        });

        $("a.staffitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editcontact.aspx?contactid=" + $(this).attr("href") + "&type=staff", "rwContactEditor");
            return false;
        });
    },

    setupBoardEditors: function () {

        $(".staff-index li").hover(function () { $(this).find(".editboardoptions").show(); }, function () { $(this).find(".editboardoptions").hide(); })

        $(".editboardwrapper").hover(function () { $(this).find("a.addboard").show(); }, function () { $(this).find("a.addboard").hide(); });

        $("a.addboard").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editcontact.aspx?type=board", "rwContactEditor");
            return false;
        });

        $("a.boarditemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editcontact.aspx?contactid=" + $(this).attr("href") + "&type=board", "rwContactEditor");
            return false;
        });
    },

    setupNewsEditors: function () {

        $(".tc2-list li").hover(function () { $(this).find(".editnewsoptions").show(); }, function () { $(this).find(".editnewsoptions").hide(); })

        $(".editnewswrapper").hover(function () { $(this).find("a.addnews").show(); }, function () { $(this).find("a.addnews").hide(); });

        $("a.addnews").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editnewsitem.aspx", "rwNewsEditor");
            return false;
        });

        $("a.newsitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editnewsitem.aspx?newsitemid=" + $(this).attr("href"), "rwNewsEditor");
            return false;
        });
    },

    setupFundingEditors: function () {

        $(".sub-feature .sub-feature-unit").hover(function () { $(this).find(".editfundingoptions").show(); }, function () { $(this).find(".editfundingoptions").hide(); })

        $(".editfundingwrapper").hover(function () { $(this).find("a.addfunding").show(); }, function () { $(this).find("a.addfunding").hide(); });

        $("a.addfunding").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/EditFundingOpportunity.aspx", "rwFundingEditor");
            return false;
        });

        $("a.fundingitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/EditFundingOpportunity.aspx?fundingopid=" + $(this).attr("href"), "rwFundingEditor");
            return false;
        });
    },

    setupLiasonEditors: function () {

        $(".editliasonwrapper .office").hover(function () { $(this).find(".editliasonoptions").show(); }, function () { $(this).find(".editliasonoptions").hide(); })

        $(".editliasonwrapper").hover(function () { $(this).find("a.addliason").show(); }, function () { $(this).find("a.addliason").hide(); });

        $("a.addliason").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editinstitution.aspx?liason=true", "rwLiasonEditor");
            return false;
        });

        $("a.liasonitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editinstitution.aspx?institutionid=" + $(this).attr("href") + "&liason=true", "rwLiasonEditor");
            return false;
        });
    },

    setupResearchFieldEditors: function () {

        $(".editresearchfieldwrapper .sub-feature-unit").hover(function () { $(this).find(".editresearchfieldoptions").show(); }, function () { $(this).find(".editresearchfieldoptions").hide(); })

        $(".editresearchfieldwrapper").hover(function () { $(this).find("a.addresearchfield").show(); }, function () { $(this).find("a.addresearchfield").hide(); });

        $("a.addresearchfield").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editresearchfields.aspx", "rwResearchFieldEditor");
            return false;
        });

        $("a.researchfielditemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editresearchfields.aspx?researchfieldid=" + $(this).attr("href"), "rwResearchFieldEditor");
            return false;
        });
    },

    setupShareSlide: function () {

        $(".share-module .expand").click(function () {
            if ($(".share-module #ShareWrapper").hasClass("closed")) {
                $(".share-module #ShareWrapper").removeClass("closed");
                $(".share-module #ShareWrapper").addClass("open");
                $(this).html("&nbsp;-]");
            } else if ($(".share-module #ShareWrapper").hasClass("open")) {
                $(".share-module #ShareWrapper").removeClass("open");
                $(".share-module #ShareWrapper").addClass("closed");
                $(this).html("&nbsp;+]");
            }
        });
    },

    setupInnovationEditors: function () {
        $(".editinnovationwrapper .sub-feature .sub-feature-unit").hover(function () { $(this).find(".editinnovationoptions").show(); }, function () { $(this).find(".editinnovationoptions").hide(); })

        $(".editinnovationwrapper").hover(function () { $(this).find("a.addinnovation").show(); }, function () { $(this).find("a.addinnovation").hide(); });

        $("a.addinnovation").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editinstitution.aspx?innovation=true", "rwInnovationEditor");
            return false;
        });

        $("a.innovationitemedit").click(function (e) {
            e.preventDefault;
            var oWindow = window.radopen("/shared/editors/editinstitution.aspx?institutionid=" + $(this).attr("href") + "&innovation=true", "rwInnovationEditor");
            return false;
        });
    },

    setupLogoutButton: function () {
        $("#page-inner").hover(function () { $(this).find("a.logoutbutton").show(); }, function () { $(this).find("a.logoutbutton").hide(); });
        $("#page-inner").find("a.logoutbutton").hide();
    }
};
