"use strict";
/*global $, jQuery, document*/ //define here all the globals you might have or want

$(document).ready(function () {
    FixRibbonAndWorkspaceDimensions();
    $(document).bind('mousemove', FixModalWindowPositioning);
});
/*
This function fixes the ribbon positioning when we are not using the shareopint default "iframe-like" structure for the html in the master page.
*/
function FixRibbonAndWorkspaceDimensions() {
    ULSxSy: ;
    g_frl = true;
    var elmRibbon = document.getElementById("s4-ribbonrow");
    var elmWorkspace = document.getElementById("s4-workspace");
    var elmTitleArea = GetCachedElement("s4-titlerow");
    var elmBodyTable = document.getElementById("s4-bodyContainer");
    if (!elmRibbon || !elmWorkspace || !elmBodyTable) {
        return;
    }
    if (!g_setWidthInited) {
        var setWidth = true;
        if (elmWorkspace.className.indexOf("s4-nosetwidth") > -1)
            setWidth = false;
        g_setWidth = setWidth;
        g_setWidthInited = true;
    }
    else {
        var setWidth = g_setWidth;
    }
    var baseRibbonHeight = RibbonIsMinimized() ? 44 : 135;
    var ribbonHeight = baseRibbonHeight + g_wpadderHeight;
    if (GetCurrentEltStyle(elmRibbon, "visibility") == "hidden") {
        ribbonHeight = 0;
    }

    // Override default resizing behavior
    // -- adds padding to the top of the "s4-workspace" <div> if the ribbon exists and has content
    // -- allows the ribbon to be positioned using CSS instead of JavaScript (more accessible)
    // -- checks to see if the page is inside a "no-ribbon" dialog
    if (elmRibbon.children.length > 0 && document.getElementsByTagName("html")[0].className.indexOf('ms-dialog-nr') == -1) {
        elmWorkspace.style.paddingTop = ribbonHeight + 'px';
    }
}
function FixModalWindowPositioning() {
    //Position modal windows below the ribbon, if they're at risk to open under ribbon.
    if ($("#s4-ribbonrow").length != 0 && $(".ms-dlgContent").length != 0) {
        var ribbonOffset = $("#s4-ribbonrow").offset(),
        newPos = ribbonOffset.top + 160,
        curPos = $(".ms-dlgContent").offset();
        if (curPos.top <= 160) {
            $(".ms-dlgContent").animate({
                top: newPos
            }, 100)
        }
    }
}

function ShareInFacebook() {
    title = document.title;
    url = location.href;
    encodedUrl = encodeURIComponent(url);
    encodedTitle = encodeURIComponent(title);
    fbSharerUrl = "http://www.facebook.com/sharer.php?u=" + encodedUrl + "&t=" + encodedTitle;
    newWindow = open(fbSharerUrl, "FBShareWindow");
}
window.onscroll = FixRibbonAndWorkspaceDimensions

