﻿/// <reference path="jquery-vsdoc.js" />

function bind(){
 //FOODMENU
    $(".category").hover(function () {
        $(this).children(".categoryPreview").show();
    }, function () {
        $(this).children(".categoryPreview").hide();
    });



    $(".category").click(function () {
        var id = $(this).attr("categoryid");
        getCategoryItems(id);
    });



    $("#navBackLink").bind('click', function ()
    {
        getCategorys(4); // 4 = last venstrestillt
    });

    $(".item").hover(function ()
    {
        $(this).children(".itemPreview").show();
        var height = $(this).children(".itemPreview").height();
        var prepos = $(this).offset();
        var topcalc = (prepos.top - (height / 2) + 10);
        var leftcalc = prepos.left - 240;
        $(this).children(".itemPreview").offset({ top: topcalc, left: leftcalc });
        $(this).children(".itemPreview").children("#frameMiddle").children("#framePoint").offset({ top: prepos.top + 5, left: leftcalc + 225 });
    }, function ()
    {
        $(this).children(".itemPreview").hide();
    });
    //END FOODMENU

    /* Slideshow 2 */
    if ($(".slideshow").children(".backgroundImage").length > 1) {
        //$('.slideshow').cycle('destroy');
        $('.slideshow').unbind();
        $('.slideshow').cycle({
            fx: 'fade',
            slideExpr: 'img',
            next: '#rightWing',
            prev: '#leftWing'
        });
    }

  
}

function OpenMessageBox(message)
{
    $("#overlay").show();
    $("#messageBox .message").html(message);
    $("#messageBox").show();
}

function OpenTextBox(message)
{
    $("#overlay").show();
    $("#messageBox").removeClass();
    $("#messageBox").addClass("messageBoxFull");
    $("#message").removeClass();
    $("#message").addClass("pageMessage");
    $("#messageBox #message").html(message);
    $("#messageBox").show();
}

function CloseMessageBox()
{
    $("#messageBox").hide();
    $("#overlay").hide();
}

function loadjscssfile(filename, filetype)
{
    if (filetype == "js")
    { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css")
    { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined") document.getElementsByTagName("head")[0].appendChild(fileref)
}


// END WEATHERAPP

$(document).ready(function () {
//    var loc = window.location.pathname;
//    if (loc != "" && loc != "/") {
//        getCategorys(4); // 4 = last venstrestillt
//        $("#menyBtn").hide();
//        bind();
//    }

//    $("#menyBtn").click(function () {
//        getCategorys(4); // 4 = last venstrestillt
//        $(this).hide();
//        bind();
//    });

//    CloseMessageBox();

//    $("#messageBox .close").click(function () {
//        CloseMessageBox();
//    });

//    $("#textBox .close").click(function () {
//        CloseMessageBox();
//    });

//    $("#googleMapBox .close").click(function () {
//        CloseGoogleMapBox();
//    });

//    /* Flip */
//    $(".flip").bind("click", function () {
//        $(".panel").slideToggle("fast");
//    });

//    /* Flip 2*/
//    $("#changeLanguage").bind("click", function () {
//        $("#googleText").fadeToggle("fast");
//        $("#google_translate_element").slideToggle("fast");
//        if (INITIATED === false) {
//            loadjscssfile("//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit", "js");
//            INITIATED = true;
//        }
//    });



//    // WEATHERAPP
//    $(".notInCityLink").bind("click", function () {
//        getRestaurants();
//        $("#citySelector").slideToggle();
//    });

//    $(".citySelectorLink").live('click', function () {
//        var zipCode = $(this).attr("zipCode");
//        getWeather(zipCode);
//        setDetailLink(zipCode);
//        $("#citySelector").slideToggle();
//    });
//    //END WEATHERAPP

//    //getRestaurants();

// 



//    $(window).resize(function () {
//        $('#footerWrapper').stickyfloat({ duration: 100 });
//    });

    $(".lnkReadMoreView").live('click', function () {
        if ($('.bodyText').is(":visible")) {
            $(this).html("&raquo; Les mer");
            $('.bodyText').slideUp("fast");
        }
        else {
            $(this).html("&raquo; Lukk");
            $('.bodyText').slideDown();
        }
        setTimeout("updateStickyfloat()", 500);
    });

//    $(".lnkReadMoreWork").click(function () {
//        if ($('.bodyText').is(":visible")) {
//            $(this).html("&raquo; Les mer");
//            $('.bodyText').slideUp("fast");
//        }
//        else {
//            $(this).html("&raquo; Lukk");
//            $('.bodyText').slideDown();
//        }
//        setTimeout("updateStickyfloat()", 500);
//    });

//    $('.bannerCycle2').cycle({
//        fx: 'fade',
//        slideExpr: 'a',
//        timeout: '7000',
//        next: '',
//        prev: ''
//    });

//    $("#printMenuBtn").live("click", function () {
//        window.open('Print.aspx', 'PrintMe', 'height=600px,width=800px,scrollbars=1');
//    });

//    setTimeout("updateStickyfloat()", 500);

});

function updateStickyfloat(){
 $('#footerWrapper').stickyfloat({ duration: 100 });
}

function setDetailLink(zipCode) {
    $(".detailLink").html("<a target=\"_blank\" href=\"http://www.yr.no/sted/Norge/postnummer/" + zipCode + "/\">› Se detaljert varsel</a>");
}
