﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

$("#menu_main li:first").addClass("firstLi");
$("#breadCrumb li:last a").addClass("lastLi");
$("#menu_tool li:last a").addClass("lastLi");
$("#menu_language li:last a").addClass("lastLi");

$('#faq dl dd').hide();
$('#faq dl dt').css('cursor', 'pointer').click(function() {
    $(this).addClass('active').siblings().removeClass('active');
    var $nextdd = $(this).next();
    var $visibleSiblings = $nextdd.siblings('dd:visible');
    if ($visibleSiblings.length) {
        $visibleSiblings.slideUp('fast', function() {
            $nextdd.slideToggle('fast');
        });
    } else {
        $nextdd.slideToggle('fast');
    }
});

(function($) {
    $(document).ready(function() {
        $('.styleswitch').click(function() {
            switchStylestyle(this.getAttribute("rel"));
            return false;
        });
        var c = readCookie('style');
        if (c) switchStylestyle(c);
    });

    function switchStylestyle(styleName) {
        $('link[rel*=style][title]').each(function(i) {
            this.disabled = true;
            if (this.getAttribute('title') == styleName) {
                this.disabled = false;
                $('.styleswitch').hide();
                if (styleName === "main") {
                    $('.styleswitch[rel=contrast]').show();
                }
                if (styleName === "contrast") {
                    $('.styleswitch[rel=main]').show();
                }
            }
        });
        createCookie('style', styleName, 365);
    }
})(jQuery);

// Accordion
$('.dynamic_content > li').removeClass('open').find('.teaser').hide();
$('.dynamic_content > li:first').addClass('open').find('.teaser').show();
$('.dynamic_content > li > h2').click(function() {
    $(this).parent().toggleClass('open').siblings().removeClass('open');
    var $teaser = $(this).next();
    var $visibleSiblings = $('.dynamic_content > li > .teaser:visible').not($teaser);
    if ($visibleSiblings.length) {
        $visibleSiblings.slideUp('fast', function() {
            $teaser.slideToggle('fast');
        });
    } else {
        $teaser.slideToggle('fast');
    }

    return false;
});


// Print
$('ul#tools').prepend('<li class="print"><a href="#print">Utskrift</a></li>');
$('ul#tools li.print a').click(function() {
    window.print(); 
    return false;
});

// Subjects
$('#subject li').removeClass('open');
$('#subject > li ul').hide();
$('#subject > li > a').click(function() {
    $(this).next().toggle();
    $(this).parent().toggleClass('open');
    return false;
});

// Events
$('.aktivitet .detaljer').hide();
$('.aktivitet > h2').click(function() {
    var parent = $(this).parent();
    $('.detaljer', parent).slideDown('fast');
    return false;
});

$('.aktivitet .exit').click(function() {
    $(this).parent().slideUp('fast');
    return false;
});


//Local tools
$('.tipsfriend').hide();
$('.tips').click(function() {
    $('.tipsfriend').slideToggle('medium');
});

// Font resizing
$('#header #small').click(function() {
    $('body').removeClass('small medium large').addClass('small');
    createCookie('fontsize', 'small', 365);
    return false;
});
$('#header #medium').click(function() {
    $('body').removeClass('small medium large').addClass('medium');
    createCookie('fontsize', 'medium', 365);
    return false;
});
$('#header #large').click(function() {
    $('body').removeClass('small medium large').addClass('large');
    createCookie('fontsize', 'large', 365);
    return false;
});

var fontsize = readCookie('fontsize');
if (fontsize == 'small' || fontsize == 'medium' || fontsize == 'large') {
    $('body').removeClass('small medium large').addClass(fontsize);
}

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name, "", -1);
}

// Bookmark
// add a "rel" attrib if Opera 7+
if (window.opera) {
    if ($("#tools .bookmark a").attr("rel") != "") { // don't overwrite the rel attrib if already set
        $("#tools .bookmark a").attr("rel", "sidebar");
    }
}

$("#tools .bookmark a").click(function(event) {
    event.preventDefault(); // prevent the anchor tag from sending the user off to the link
    var url = this.href;
    var title = this.title;

    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(url, title);
    } else if (window.opera) { // Opera 7+
        return false; // do nothing - the rel="sidebar" should do the trick
    } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
        alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
    }
});


/*EmployeeList */

//hide all desicriptions when page loads
$(".description").hide();

//EXPRESSIONS
//toggle the description
$("a.liste").click(function () {
    $("a.liste").not(this).removeClass("collapse");

    if ($(this).parent().hasClass("description")) {
        return true;
    }
    else {
        $(".description").not($(this).parent().find(".description")).hide();
        $(this).parent().find(".description").toggle();
        $(this).toggleClass("collapse");
        return false;
    }
});
