﻿$(document).ready(function () {

    // Open external links in a new window
    $('a[rel*="external"]').click(function () {
        window.open($(this).attr('href'));
        return false;
    });


    // Log clicks to external sites with Google Analytics
    $('a').each(function () {
        var $a = $(this);
        var href = $a.attr('href');
        var rel = $a.attr('rel');
        if (((href.match(/^http/) || href.match(/^https/)) && !href.match(document.domain)) || rel.match(/^document/)) {
            $a.click(function () {
                pageTracker._trackPageview('/outgoing/' + href);
            });
        }
    });

});


// Hides rows in the CV table on load
$(document).ready(function () {
    $(".low-importance").hide();
});

// Shows and hides rows in the CV table
function Toggle() {

    var link = document.getElementById("importanceToggle");
    if (link.innerHTML == 'Vis mer') {
        link.innerHTML = 'Vis mindre';
        $(document).ready(function () {
            $(".low-importance").show();
        });
    }
    else {
        link.innerHTML = 'Vis mer';
        $(document).ready(function () {
            $(".low-importance").hide();
        });
    }
}

// Show and hide community elements
var is_visible = false;
$(document).ready(function () {
    $('.hidden-item').hide();
});

function ShowMoreCommunityItems() {
    var link = document.getElementById("moreCommunityLink");

    if (is_visible) {
        link.innerHTML = 'Vis mer';
        $('.hidden-item').hide();
    }
    else {
        link.innerHTML = 'Vis mindre';
        $('.hidden-item').show();
    }

    is_visible = !is_visible;
}

// Show and hide community elements, v2.0
var Count;
$(document).ready(function () {
    Count = 5;
    // ShowItems();

    $("#add").click(function () {
        Count = Count + 5;
        ShowItems();
    });

    $("#remove").click(function () {
        Count = Count - 5;
        ShowItems();
    });

});

function ShowItems() {
    if (Count > $("#community li").size()) {
        Count = $("#community li").size()
    };
    $("#community li:lt(" + Count + ")").show();
    $("#community li:gt(" + (Count - 1) + ")").hide();
}
