﻿// HIGHLIGHT: JAVASCRIPT TEXT HIGLIGHTING JQUERY PLUGIN
// Url: http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
// Source: http://johannburkard.de/resources/Johann/jquery.highlight-3.yui.js
jQuery.fn.highlight = function (b) { function a(e, j) { var l = 0; if (e.nodeType == 3) { var k = e.data.toUpperCase().indexOf(j); if (k >= 0) { var h = document.createElement("span"); h.className = "highlight"; var f = e.splitText(k); var c = f.splitText(j.length); var d = f.cloneNode(true); h.appendChild(d); f.parentNode.replaceChild(h, f); l = 1 } } else { if (e.nodeType == 1 && e.childNodes && !/(script|style)/i.test(e.tagName)) { for (var g = 0; g < e.childNodes.length; ++g) { g += a(e.childNodes[g], j) } } } return l } return this.each(function () { a(this, b.toUpperCase()) }) }; jQuery.fn.removeHighlight = function () { return this.find("span.highlight").each(function () { this.parentNode.firstChild.nodeName; with (this.parentNode) { replaceChild(this.firstChild, this); normalize() } }).end() };
// End highlight

//--------------------------------------------------------------------------------------------------------------

function OldMenuSetStateHidden() {
    $('#document-menu-wrapper').css('width', '0px');
    $('#document-menu-content').css('display', 'none');
    $('#document-menu-icon').css('right', '-2px');
    $('#document-menu-icon > img').attr('src', '/resources/images/docmenuopen.png');
    $('#document-menu-icon > img').attr('title', 'Vis dokumentmenyen');
    $('#document-menu-icon > img').hover(function () { $(this).attr('src', '/resources/images/docmenuopenHL.png'); }, function () { $(this).attr('src', '/resources/images/docmenuopen.png'); });
    $('#document-menu').css('width', '0px');
    $('#document').css('margin-left', '0px');
    $('#document').css('border-left', '0px');
    $.cookie("oldmenucollapse", "false", { path: '/', expires: 365, domain: cookieDomain });
}

//--------------------------------------------------------------------------------------------------------------

function OldMenuSetStateVisible() {
    $('#document-menu-wrapper').css('width', '200px');
    $('#document-menu-content').css('display', 'block');
    $('#document-menu-icon').css('right', '-5px');
    $('#document-menu-icon > img').attr('src', '/resources/images/docmenuclose.png');
    $('#document-menu-icon > img').hover(function () { $(this).attr('src', '/resources/images/docmenucloseHL.png'); }, function () { $(this).attr('src', '/resources/images/docmenuclose.png'); });
    $('#document-menu-icon > img').attr('title', 'Gjem dokumentmenyen');
    $('#document-menu').css('width', '190px');
    $('#document').css('margin-left', '200px');
    $('#document').css('border-left', '1px solid #DEDEDE');
    $.cookie("oldmenucollapse", "true", { path: '/', expires: 365, domain: cookieDomain });
}

//--------------------------------------------------------------------------------------------------------------

function OldMenuToggle() {
    if ($.cookie("oldmenucollapse") == "true") OldMenuSetStateHidden();
    else OldMenuSetStateVisible();
}

//--------------------------------------------------------------------------------------------------------------

function OldMenuUpdatePosition() {
    var pY = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
    // IE6 spesifik scrolling
    if ($.browser.msie && $.browser.version.substr(0.3) == "6.0")
        pY = (pY < $("#fw-page").offset().top) ? 31 : pY - ($("#fw-page").offset().top - 31);
    else
        pY = (pY < $("#fw-page").offset().top) ? ($("#fw-page").offset().top + 31) - pY : 31;
    $("#document-menu").css("top", pY);
}

//--------------------------------------------------------------------------------------------------------------

function PrintCombinedMenu() {
    var menuHtml = "";

    // Get h2 and h3 headers
    $("h2").each(function () {
        var id = $(this).attr("id");
        var header = $.trim($(this).text());

        if (id != null && id.length > 0) {
            menuHtml += "<li><a href=\"#" + id + "\" title=\"" + header + "\">" + snip(header, 25);

            var subMenu = "";
            $(this).next().find("h3").each(function () {
                var subId = $(this).attr("id")
                var subHeader = $.trim($(this).text());

                subMenu += "<li><a href=\"#" + subId + "\" title=\"" + subHeader + "\">" + snip(subHeader, 25) + "</a>";
            });

            if (subMenu.length > 0) {
                subMenu = "<span class=\"more\"></span></a><ul class=\"level-3\">" + subMenu + "</ul>";
                menuHtml += subMenu;
            }
            else menuHtml += "</a>";

            menuHtml += "</li>";
        }
    });

    // "Print menu"
    if (menuHtml.length > 0) {
        $("#content-menu-toggle").parent().append("<ul id=\"content-menu\" class=\"level-2\">" + menuHtml + "<li id=\"document-top\"><a href=\"#\"><i>Til toppen av dokumentet</i></a></li></ul>");
        $("#document-menu-content").html("<ul>" + menuHtml + "<li id=\"document-top\"><a href=\"#\"><i>Til toppen av dokumentet</i></a></li></ul>");
        $("#document-menu-icon").css("display", "inline");
    }

    // Add events and configs
    var config = {
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100,  // number = milliseconds for onMouseOver polling interval    
        over: ShowContentMenu3, // function = onMouseOver callback (REQUIRED)    
        timeout: 500,   // number = milliseconds delay before onMouseOut    
        out: HideContentMenu3   // function = onMouseOut callback (REQUIRED)          
    };
    $("#content-menu li").hoverIntent(config);

    $("#content-menu li a").click(function () {
        var url = $(this).attr("href");
        window.location = url;
        if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) document.body.scrollTop -= 35;
        else document.documentElement.scrollTop -= 35;

        return false;
    });

    $("#document-menu li a").click(function () {
        $(this).parent().parent().find("ul").hide();
        $(this).parent().find("ul").show();

        var url = $(this).attr("href");
        window.location = url;

        if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) document.body.scrollTop -= 35;
        else document.documentElement.scrollTop -= 35;

        return false;
    });
}

//--------------------------------------------------------------------------------------------------------------

function checkSubmit(e, d, f)
{
    if (d) document.forms[0].submit();
}

function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

//--------------------------------------------------------------------------------------------------------------

$(document).ready(function () {
    
    /*** NEL MESSAGE *********************************************************/
    $('.nel-message a.close').click(function () {
        $(this).parent().hide();

        // Append this message_id to "NELMessagesRead"
        var cookieIds = $.cookie('NELMessagesRead');
        if (!cookieIds) {
            cookieIds = '';
        } else {
            cookieIds += ',';
        }

        var messageId = $('.nel-message a.close').parent().attr('id');
        messageId = messageId.split('-');
        messageId = messageId[messageId.length - 1];

        cookieIds += messageId;

        //$.cookie('NELMessagesRead', cookieIds, { expires: 365, domain: 'legehandboka.no', path: '/' });
        $.cookie('NELMessagesRead', cookieIds, { expires: 365 }); //, domain: 'localhost', path: '/' });


        return false;
    });

    /*** SIGN IN DIALOG ******************************************************/
    var handleLogIn = function (accountDialog) {
        accountDialog.find("form").submit(function (e) {
            e.preventDefault(); //no postback 

            $.post(
                        $(this).attr("action"),
                        $(this).serialize(),
                        function (json) {
                            if (!json.IsValid) {
                                //invalid sign in, return partial 
                                accountDialog.html(json.Html);
                                handleLogIn(accountDialog);
                            }
                            else {
                                accountDialog.html(json.Html);
                                handleMessage(accountDialog);
                            }
                        },
                        "json"
                    );
        });
    }

    var handleAccountDialog = function (accountDialog, targetUrl, autoClose) {
        //handle links that should open inside dialog
        $(".dialog_link").click(function () {
            $.ajax({
                url: $(this).attr('href'),
                success: function (data) {
                    var accountDialog = $("#account-dialog");
                    accountDialog.html(data);
                    handleAccountDialog(accountDialog, targetUrl, true);
                }
            });
            return false;
        });

        //handle submit
        accountDialog.find("form").submit(function (e) {
            e.preventDefault(); //no postback 

            $.post(
                $(this).attr("action"),
                $(this).serialize(),
                function (json) {
                    if (!json.IsValid) {
                        //invalid form data, return partial 
                        accountDialog.html(json.Html);
                        handleAccountDialog(accountDialog, targetUrl, autoClose);
                        accountDialog.find("#dialog-links").fadeOut();
                        accountDialog.find("#dialog-links").fadeIn();
                    }
                    else {
                        //show success partial
                        accountDialog.html(json.Html);
                        handleClose(accountDialog, targetUrl, autoClose);
                    }
                },
                "json"
            );
        });
    }

    var handleClose = function (accountDialog, targetUrl, autoClose) {
        var timeout = null;
        //Autoclose dialog after timeout
        if (autoClose) {
            if (targetUrl && targetUrl.length > 0) {
                timeout = setTimeout("location.assign('" + targetUrl + "')", 10000);
            }
            else {
                timeout = setTimeout("location.reload()", 10000);
            }
        }

        //handle links that should open inside dialog
        $(".dialog_link").click(function () {
            //Cancel timeout
            clearTimeout(timeout);
            //Process link to new login dialog
            $.ajax({
                url: $(this).attr('href'),
                success: function (data) {
                    var accountDialog = $("#account-dialog");
                    accountDialog.html(data);
                    accountDialog.dialog("option", "title", 'Logg inn');
                    //accountDialog.dialog("option", "height", 250);
                    handleAccountDialog(accountDialog, targetUrl, true);
                }
            });
            return false;
        });

        //Close dialog if user clicks the close button
        accountDialog.find("form").submit(function (e) {
            e.preventDefault(); //no postback 
            timeout = null; //remove timeout
            if (targetUrl && targetUrl.length > 0) {
                location.assign(targetUrl);
            }
            else {
                location.reload();
            }
        });
    }

    $("#log_in_link").click(function () {
        $.ajax({
            url: $(this).attr('href'),
            success: function (data) {
                var accountDialog = $("#account-dialog");
                accountDialog.html(data);
                accountDialog.dialog({
                    //width: 400,
                    //height: 250,
                    modal: true,
                    title: "Logg inn",
                    close: function (event, ui) {
                        location.reload();
                    }
                });
                handleAccountDialog(accountDialog, "", true);
            }
        });
        return false;
    });

    $("#log_out_link").click(function () {
        $.ajax({
            url: $(this).attr('href'),
            success: function (data) {
                var accountDialog = $("#account-dialog");
                accountDialog.html(data);
                accountDialog.dialog({
                    //width: 400,
                    //height: 150,
                    modal: true,
                    title: "Logg ut",
                    close: function (event, ui) {
                        location.assign("/");
                    }
                });
                handleClose(accountDialog, "/", true);
            }
        });
        return false;
    });

    /*** EQUAL HEIGHTS ON MENU AND PAGE **************************************/
    // c2: Ting virker ok (lokalt i Chroem og IE) når jeg kommenterte ut denne koden, vi prøver uten! 

    //    //equalHeight($("div.equal-height"));
    //    var mainHeight = $("#fw-main").height();
    //    var pageHeight = $("#fw-page").height() + 30;
    //    //var documentHeight = $("#document").height();
    //    var targetHeight = mainHeight;

    //    if (pageHeight > targetHeight)
    //        targetHeight = pageHeight;

    //    //if (documentHeight > targetHeight)
    //    //  targetHeight = documentHeight;

    //    if (targetHeight < 1010)
    //        targetHeight = 1010;

    //    $("#fw-main").height((targetHeight + 30));
    //    $("#fw-page").height(targetHeight);

    //    var documentHeight = $(document).height();
    //    //var documentHeight = $("#document").height();
    //    $("#fw-main").height(documentHeight + 30);
    //    $("#fw-page").height(documentHeight + 30);
    //    //$("#fw-document").height(documentHeight);

    //    var documentHeight = $(document).height();

    //    $('html').append('<div style="position:fixed;top:100px; right:10px;">$(document):' + documentHeight +
    //    '<br>$("#fw-main"): ' + $("#fw-page").height() +
    //    '<br>$("#fw-page"): ' + $("#fw-page").height() +
    //    '<br>$("#document"): ' + $("#document").height() + '</div>');

    //    $("#fw-page").height(documentHeight);
    //    $("#document-menu-wrapper").height(documentHeight);

    /*** ACCORDION CHAPTER MENU **********************************************/
    var activeTitle = $("div#fw-menu ul li.current").parent().prev().find("a").text();
    var activeId = 0;

    var menuArray = $("#fw-menu div#accordion h3");

    var count = 0;
    jQuery.each(menuArray, function () {
        if (this.firstChild.innerHTML == activeTitle)
            activeId = count;
        count++;
    });

    $("#accordion").accordion({
        autoHeight: false,
        animated: false,
        active: activeId
    });

    /*** APPLICATION DROPDOWN LIST *************************************************************************************/
    /* Adapted from http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx */

    createDropDown();

    $(".dropdown dt a").click(function () {
        $(".dropdown dd ul").toggle();
    });

    $(".dropdown dt a").mousedown(function () {
        $(this).toggleClass("mousedown");
    });

    $(".dropdown dt a").mouseup(function () {
        $(this).toggleClass("mousedown");
    });

    $(".dropdown dd ul li a").click(function () {
        $(".dropdown dt a").html($(this).html());
        $(".dropdown dd ul").hide();
        var source = $("#application");
        source.val($(this).find("span.value").html());
        source.parent().submit();
    });

    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function (e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown"))
            $(".dropdown dd ul").hide();
    });

    function createDropDown() {
        var source = $("#application");
        var selected = source.find("option:selected");  // get selected <option>
        var options = $("option", source);  // get all <option> elements

        // create <dl> and <dt> with selected value inside it
        if ($.browser.msie && $.browser.version.substr(0.3) == "7.0") {
            $('#fw-menu').append('<dl id="application-dropdown" class="dropdown"></dl>');
        }
        else {
            source.after('<dl id="application-dropdown" class="dropdown"></dl>');
        }
        $("#application-dropdown").append('<dt><a href="#"><span class="text">' + selected.text() + '</span><span class="value">' + selected.val() + '</span></a></dt>');
        $("#application-dropdown").append('<dd><ul></ul></dd>');

        // iterate through all the <option> elements and create UL
        options.each(function () {
            $("#application-dropdown dd ul").append('<li' + ($(this).hasClass('locked') ? ' class="locked"' : ($(this).hasClass('open') ? ' class="open"' : '')) + '>' +
                '<a href="#"><span class="text">' + $(this).text() + '</span><span class="value">' + $(this).val() + '</span></a></li>');
        });

        source.hide();
    }

    /*** CHAPTER MENU & BREADCRUMB *******************************************/
    var vpHeight = ViewPortHeight();
    var pY = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;

    // Update menu position when REFRESHING
    $(window).ready(function () {
        var browserVersion = "!IE6";
        pY = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
        var menuY = pY;

        // Resize MENU
        vpHeight = ViewPortHeight();
        var newMenuHeight = vpHeight;
        // Juster for header ved resizing
        if (pY < $("#fw-page").offset().top)
            newMenuHeight = vpHeight - ($("#fw-page").offset().top - pY);
        $("#fw-menu").height(newMenuHeight);

        // IE6 spesifik scrolling
        if ($.browser.msie && $.browser.version.substr(0.3) == "6.0") {
            browserVersion = "hyyl det er IE6!";
            // Adjust pY according to document, do not start scrolling until page has passed this anchor
            menuY = (pY < $("#fw-page").offset().top) ?
                0 :                                // ABSOLUTE
                pY - $("#fw-page").offset().top;  // ABSOLUTE
        }
        // Scrolling for browsere som takler position = fixed
        else {
            menuY = (pY < $("#fw-page").offset().top) ?
                $("#fw-page").offset().top - pY :   // FIXED
                0;                                  // FIXED

        }

        if ($.browser.msie && $.browser.version.substr(0.3) == "7.0") {
            browserVersion = "hyyl det er IE7!";
            $("#application-dropdown").css("top", menuY);
            $("#accordion").css("top", menuY + 30);
        }

        // Move menu to adjusted pY
        $("#fw-menu").css("top", menuY);
        $("#application-dropdown dd ul").css("top", menuY + 25);
        $("#fw-breadcrumb").css("top", menuY);

        // DEBUG
        //$("#debug").html(
        //    "<b>event: Refresh ("+browserVersion+")</b>" +
        //    "<br>pY: " + pY + 
        //    "<br>menuY: " + menuY +
        //    "<br>fw-page: " + $("#fw-page").offset().top + 
        //    "<br>viewport-height: " + vpHeight +
        //    "<br>clientHeight: " + document.documentElement.clientHeight + 
        //    "<br>scrollTop: " + document.documentElement.scrollTop +
        //    "<br>fw-menu.height: " + $("#fw-menu").height()
        //    );
    });

    // Update menu position when SCROLLING
    $(window).scroll(function () {
        var browserVersion = "!IE6";
        pY = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
        var menuY = pY;

        // Resize MENU
        vpHeight = ViewPortHeight();
        var newMenuHeight = vpHeight;
        // Juster for header ved resizing
        if (pY < $("#fw-page").offset().top)
            newMenuHeight = vpHeight - ($("#fw-page").offset().top - pY);
        $("#fw-menu").height(newMenuHeight);

        // IE6 spesifik scrolling
        if ($.browser.msie && $.browser.version.substr(0.3) == "6.0") {
            browserVersion = "hyyl det er IE6!";
            // Adjust pY according to document, do not start scrolling until page has passed this anchor
            menuY = (pY < $("#fw-page").offset().top) ?
                0 :                                // ABSOLUTE
                pY - $("#fw-page").offset().top;  // ABSOLUTE
        }
        // Scrolling for browsere som takler position = fixed
        else {
            menuY = (pY < $("#fw-page").offset().top) ?
                $("#fw-page").offset().top - pY :   // FIXED
                0;                                  // FIXED
        }

        if ($.browser.msie && $.browser.version.substr(0.3) == "7.0") {
            browserVersion = "hyyl det er IE7!";
            $("#application-dropdown").css("top", menuY);
            $("#accordion").css("top", menuY + 30);
        }

        // Move menu to adjusted pY
        $("#fw-menu").css("top", menuY);
        $("#application-dropdown dd ul").css("top", menuY + 25);
        $("#fw-breadcrumb").css("top", menuY);

        // DEBUG
        //$("#debug").html(
        //    "<b>event: Scroll ("+browserVersion+")</b>" +
        //    "<br>pY: " + pY + 
        //    "<br>menuY: " + menuY +
        //    "<br>fw-page: " + $("#fw-page").offset().top + 
        //    "<br>viewport-height: " + vpHeight +
        //    "<br>clientHeight: " + document.documentElement.clientHeight + 
        //    "<br>scrollTop: " + document.documentElement.scrollTop +
        //    "<br>fw-menu.height: " + $("#fw-menu").height()
        //    );
    });

    // Update menu height when RESIZING
    $(window).resize(function () {
        // Resize MENU
        vpHeight = ViewPortHeight();
        var newMenuHeight = vpHeight;
        // Juster for header ved resizing
        if (pY < $("#fw-page").offset().top)
            newMenuHeight = vpHeight - ($("#fw-page").offset().top - pY);

        $("#fw-menu").height(newMenuHeight);

        //$("#debug").html(
        //    "<b>event: Resize</b>" +
        //    "<br>pY: " + pY + 
        //    "<br>menuY: N/A" +
        //    "<br>fw-page: " + $("#fw-page").offset().top + 
        //    "<br>viewport-height: " + vpHeight +
        //    "<br>clientHeight: " + document.documentElement.clientHeight + 
        //    "<br>scrollTop: " + document.documentElement.scrollTop +
        //    "<br>fw-menu.height: " + $("#fw-menu").height()
        //    );
    });

    /*** SEARCH AUTOCOMPLETE *************************************************/
    $("#query").autocomplete('/ajax/getkeywords/', { selectFirst: false, width: 223 });
    $("#query").result(checkSubmit)

    /*** SEARCH **************************************************************/
    //equalHeight($("div.search-result-group"));
    var count = 0;
    $("div.search-result-group").each(function () {
        if (++count % 2 == 0) {
            $(this).after('<div class="clear"></div>');
        }
    });

    /*** TIP DOCUMENT *********************************************************/
    //    if (!($.browser.msie && $.browser.version.substr(0.3) == "6.0")) {

    //        var tipHeight = $("#tip-document").height();
    //        $("#tip-document").height(100);
    //        $("#tip-document").append('<div class="bottom"></div>');
    //        $("#tip-document .bottom").show();
    //        $("#tip-document").hover(function() {
    //            $(this).find(".bottom").hide();
    //            $(this).animate({ height: tipHeight }, 1000);
    //        },
    //        function() {
    //            $(this).animate({ height: 100 }, 1000, function() { $(this).find(".bottom").show(); });
    //        });
    //    }

    /*** REFERENCE-HOVER *****************************************************/
    $('#tip-document a.reference').click(function () {
        return false;
    });

    $('#tip-document a.reference').mouseenter(function () {
        $("div.reference-hover").hide();

        if ($(this).parent().find("div.reference-hover").length == 0) {
            var referenceName = $(this).attr("href");
            var referance = $("#tip-document div#references a[name='" + referenceName.replace("#", "") + "']");
            var hoverText = referance.html();

            if (referance.next().html() != null)
                hoverText += '&nbsp;<a href="' + referance.next().attr("href") + '" target="_blank">' + referance.next().html() + '</a>';

            $(this).parent().append('<div class="reference-hover">' + hoverText + '</div>');

            $(this).parent().find("div.reference-hover").mouseleave(function () {
                $(this).hide();
            });
        }

        $(this).parent().find("div.reference-hover").show();
    });

    /*** MENU TOGGLE *********************************************************/
    var config = {
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100,  // number = milliseconds for onMouseOver polling interval    
        over: ShowMenu, // function = onMouseOver callback (REQUIRED)    
        timeout: 500,   // number = milliseconds delay before onMouseOut    
        out: HideMenu   // function = onMouseOut callback (REQUIRED)          
    };
    $("#fw-breadcrumb > ul[class!='icons'] > li > a").hoverIntent(config);
    $("#fw-breadcrumb > ul > li[class='dropdown'] > a").hoverIntent(config);

    $("ul.level-1 li.active > a").click(function () {
        return false;
    });

    $("li.dropdown > a").click(function () {
        return false;
    });

    $("*").click(
        function (event) {
            if (this.id == "fw-breadcrumb") event.stopPropagation();
            if (this.tagName.toLowerCase() == "html") {
                $("#fw-breadcrumb li ul").hide();
                $("div.reference-hover").hide();
            }
        }
    );

    /*** TREE MENU MOVETO ****************************************************/
    if ($("#fw-menu ul li.current").offset()) {
        var selected = $("#fw-menu ul li.current").offset().top + $("#fw-menu ul li.current").height();
        var container = $("#fw-menu").offset().top + $("#fw-menu").height();

        if (selected > container) $('#fw-menu').scrollTop(selected - container + 5);
    }
    //Denne er kommentert ut fordi den ødelegger for posisjonering i dokument ved bruk av back-funksjon
    //Må implmenteres slik at den kune trigges hvis man allerede står i toppen av dokumentet
    //$("#query").focus();

    showTipPopup();
});

function hideTipPopup(url)
{
    //$('#crumb-helper').hide();
    $.cookie('tip_popup_disable', true, {expires: 365, path: '/' } );    
    window.location = url;
}

function showTipPopup()
{
    var popup = $("#tip-popup");
    if (popup.attr("class") == "is-logged-in")
    {
        $.cookie('tip_popup', true, { expires: 365 });
        if ($.cookie('tip_popup'))
        {
            $.cookie('tip_popup', null);
            if (!$.cookie('tip_popup_disable'))
            {            
                $('#tip-popup').dialog({ 
                    title: 'Ny funksjon i NEL',
                    modal: true, 
                    width: 400, 
                    buttons: { 
                        "Ok": function() { 
                            $.cookie('tip_popup_disable', true, {expires: 365, path: '/' } );
                            $(this).dialog("close");
                        }
                    }
                });
            }
        }
    }
}

function ShowMenu() 
{
    $("#fw-breadcrumb li ul").hide();
    $(this).parent().find("ul.level-2").show();
    $(this).parent().find("ul.column-2").height($(this).parent().find("ul.level-2:first").height());
    $(this).parent().find("ul.level-2 input:first").focus();
}

function HideMenu() {}

function ViewPortHeight() {
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined')
    {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
    {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
    }

    // older versions of IE

    else
    {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    
    return viewportheight;
}

function viewport() {
	return {
		x: $(window).scrollLeft(),
		y: $(window).scrollTop(),
		w: $(window).width(),
		h: $(window).height()
	};
}

