﻿$(window).ready(function(){
    var menuHeight = $('#navigation ul').outerHeight();
    var brandHeight = $('#content .branding').outerHeight();
    menuHeight+=brandHeight;
    if(menuHeight > $('#content').outerHeight()){
        $('#content').height(menuHeight);
    }

});
$(document).ready(function() {
    //Find all text inputs and set title as text
    
    $("input[type='text'][value='']").each(AddTitleText).blur(AddTitleText);
    $("input.empty-text").focus(function(){if($(this).val()==$(this).attr('title'))$(this).val("").removeClass("empty-text");});
    
    // Find all anchors with the class popup and add the onclick function to open the link in a new window.
    $('a.popup').click(function() {
        window.open($(this).attr('href'));
        return false;
    });
    
    // Traverse through all links with the class popup and modify the title attribute.
    $("a.popup[title='']").attr('title', '(Öppnas i nytt fönster)');

    //Load css for thickbox
    if ($('.thickbox').length >0) {
        $("head").append("<link>");
        css = $("head").children(":last");
        css.attr({
          rel:  "stylesheet",
          type: "text/css",
          href: "/styles/thickbox.css"
    });
    }
        //Load css for rounded corners
        $("head").append("<link>");
        css = $("head").children(":last");
        css.attr({
          rel:  "stylesheet",
          type: "text/css",
          href: "/styles/corners.css"
    });
    $('#translatelink').click(function(){
        if($('#translatediv').length==0)
            OpenTranslate(this)
        return false;
        });
    
    $("body").click(function(e){
        if(e.target.id != "translatediv"&&e.target.parentNode.id!="translatediv"){
          $('#translatediv').remove();
        }
    });

});

function AddTitleText() {
    if($(this).val()==''||$(this).val()==$(this).attr('title'))
        $(this).val($(this).attr('title')).addClass("empty-text");
}

function OpenTranslate(translateAnchor){
    var element='<div id="translatediv"><p>Use Google to translate the web site. We take no responsibility for the accuracy of the translation.</p><label for="translateSelect">Choose language:</label><select id="translateSelect">';
    var options='';
    for(var lang in google.language.Languages) {
        if(lang !== "UNKNOWN" && google.language.isTranslatable(google.language.Languages[lang])){
            options=options+'<option value="'+google.language.Languages[lang]+'">'+lang+'</option>';
        }
    }
    $(translateAnchor).after(element+options+'</select></div>');
    $('#translatediv select').change(function(){
        document.location.href=$(translateAnchor).attr('href').replace("hl=en","hl="+$('#translatediv select').val());
    });
}

