/// <reference path="jquery-1.3.2-vsdoc2.js" />
/// <reference path="swfobject-vsdoc.js" />
/// <reference path="sifr-vsdoc.js" />

$(document).ready(function() {


    // Level 2 & 3 dropdown
    $(".menu_top_level1_li").hover(

    function() {
        var id = $(this).attr("menuid");
        $(this).children("a").children("img").attr("src", "text_images/menu_top_level1_active_m_" + id + ".png");
        $(this).children(".menu_top_level2").addClass("menu_top_level2_active");

        var fold = 480;
        var element = $(this).children(".menu_top_level2").offset().left - 225;


        if (element > fold) {
            var parentWidth = $(this).width();
            var rightOffset = 225 - parentWidth;
            $(this).children(".menu_top_level2").css("margin-left", "-" + rightOffset + "px");
            var rightOffsetInfobox = 0;
            $(this).children(".menu-infobox").css("margin-left", "-" + (572 + rightOffset) + "px");
        }

    }
    ,
    function() {
        var id = $(this).attr("menuid");
        $(this).children("a").children("img").attr("src", "text_images/menu_top_level1_m_" + id + ".png");
        $(this).children(".menu_top_level2").removeClass("menu_top_level2_active");


    }

    );


    // Show infobox when hovering over level 2 or 3
    $(".menu_top_level3_li").hover(

    function() {
        var infobox = null




        infobox = $(this).parent().parent().parent().parent().children(".menu-infobox");


        var titleimg = $(this).attr("titleimg");
        var titleAlt = $(this).attr("titlealt");
        var menuImage = $(this).attr("img");
        var description = $(this).attr("descr");


        //        infobox.children(".infobox-title").children(".infobox-title-img").attr("src", titleimg);
        //        infobox.children(".infobox-title").children(".infobox-title-img").attr("alt", titleAlt);
        infobox.children(".infobox-title").children().text(titleAlt);
        infobox.children(".infobox-image").attr("src", menuImage);
        infobox.children(".infobox-description").text(description);

        if (menuImage != '') {
            infobox.css("display", "block");
        }
        else {
            infobox.css("display", "none");
        }
    }
    ,
    function() {

        $(this).parent().parent().children(".menu-infobox").css("display", "none");

    }

    );



    // Show infobox when hovering over level 2
    $(".menu_top_level2_li").hover(

    function() {
        var infobox = null




        infobox = $(this).parent().parent().children(".menu-infobox")




        //        var fold = 480;
        //        var element = $(this).parent().parent().offset().left + 320; // box - menu - infoboxwidth


        //        if (element > fold) {
        //            var parentWidth = $(this).parent().parent().width();
        //            var rightOffset = 0 - parentWidth + 320;
        //            $(infobox).css("left", "-" + Math.abs(rightOffset - 225 + 122) + "px");
        //        }


        var titleimg = $(this).attr("titleimg");
        var titleAlt = $(this).attr("titlealt");
        var menuImage = $(this).attr("img");
        var description = $(this).attr("descr");


        //        infobox.children(".infobox-title").children(".infobox-title-img").attr("src", titleimg);
        //        infobox.children(".infobox-title").children(".infobox-title-img").attr("alt", titleAlt);
        infobox.children(".infobox-title").children().text(titleAlt);
        infobox.children(".infobox-image").attr("src", menuImage);
        infobox.children(".infobox-description").text(description);

        if (menuImage != '') {
            infobox.css("display", "block");
        }
        else {
            infobox.css("display", "none");
        }
    }
    ,
    function() {

        $(this).parent().parent().children(".menu-infobox").css("display", "none");

    }

    );

    // Clickevent on menu top level 2
    $(".menu_top_level2_li").click(
    function() {
        if ($(this).children().hasClass("menu_top_level3_active")) {
            $(this).children(".menu_top_level3_active").removeClass("menu_top_level3_active");
        }
        else {
            $(this).children(".menu_top_level3").addClass("menu_top_level3_active");
        }
        if ($(this).attr("href") == "#")
            return false;
        return true;
    }
    );

    // Clickevent on menu left level 2
    $(".menu_level2_li").click(
    function() {
        if ($(this).children().hasClass("menu_level3_active")) {
            $(this).children(".menu_level3_active").removeClass("menu_level3_active");
        }
        else {
            $(this).children(".menu_level3").addClass("menu_level3_active");
        }
        if ($(this).attr("href") == "#")
            return false;
        return true;
    }
    );


    // Scrolling on infodocuments
    $("#my-list").hoverscroll({

        vertical: false,
        width: 960,
        height: 87,
        arrows: true,
        arrowsOpacity: 0.7,
        debug: false

    });


    // Full screen on Hovedbilde (prettyphoto)
    $("a[rel^='prettyPhoto']").prettyPhoto();




    /* 
    FADE OUT AND IN PAGE
		
		This script fades out and in new page when click on all links. It requires a div that lays over all content: 
    <div id="loader" style="position:fixed;top:0px;left:0px;width:100%;height:100%;background:#13191d;z-index:5000;display:none;">&#160;</div>		
    */
    /*
    $('#loader').css({ display: "block" });
    setTimeout('$("#loader").fadeOut("400")', 500);

		// loop through a tags on page 
    $('a').each(function(idx, item) {
    // if it is not a mailto tag
    if (item.href.indexOf("mailto") == -1) {
    var url = "javascript:delayedRedirect('" + item.href + "');"
    item.href = url;
    }
    });
    */


});
