$("html").addClass("js");

$(document).ready(function(){
    $("a[rel*=blank]").click(function(){
        window.open($(this).attr('href'), '_blank');
        return false;
    })

    if($("#highlights").length > 0){
        highlights.init();
    }

    /* simple pagination for profiles in sidebar */
    var activeProfileList = 0;
    var profileLists = $(".more_list.other_profiles");
    $(".pagination.other_profiles li.prev a").click(function(){
        $(profileLists[activeProfileList]).removeClass('active');
        activeProfileList = (activeProfileList == 0) ? (profileLists.length - 1) : activeProfileList - 1;
        $(profileLists[activeProfileList]).addClass('active');
        return false;
    });
    $(".pagination.other_profiles li.next a").click(function(){
        $(profileLists[activeProfileList]).removeClass('active');
        activeProfileList = (activeProfileList == (profileLists.length - 1)) ? 0 : activeProfileList + 1;
        $(profileLists[activeProfileList]).addClass('active');
        return false;
    });

    $("a.more").closest('.column').click(function(){
        var link = $(this).find('a').attr('href');
        var rel = $(this).find('a').attr('rel');
        if(rel == "blank"){
            window.open(link);
        }else{
            window.location = link;
        }
    });

    $(".profiles li a").closest('li').click(function(){
        var link = $(this).find('a').attr('href');
        var rel = $(this).find('a').attr('rel');
        if(rel == "blank"){
            window.open(link);
        }else{
            window.location = link;
        }
    });

    $(".werkvelden li a.more").closest('li').click(function(){
        var link = $(this).find('a').attr('href');
        var rel = $(this).find('a').attr('rel');
        if(rel == "blank"){
            window.open(link);
        }else{
            window.location = link;
        }
    });

    $(".diensten li a.more").closest('li').click(function(){
        var link = $(this).find('a').attr('href');
        var rel = $(this).find('a').attr('rel');
        if(rel == "blank"){
            window.open(link);
        }else{
            window.location = link;
        }
    });

    $(".news_list li a").closest('li').click(function(){
        var link = $(this).find('a').attr('href');
        var rel = $(this).find('a').attr('rel');
        if(rel == "blank"){
            window.open(link);
        }else{
            window.location = link;
        }
    });

    $(".other_profiles li a").closest('li').click(function(){
        var link = $(this).find('a').attr('href');
        var rel = $(this).find('a').attr('rel');
        if(rel == "blank"){
            window.open(link);
        }else{
            window.location = link;
        }
    })
    
});

var highlights = {
    intervalId : '',
    intervalTime : 5000,
    currentActive : 0,
    totalItems : 0,
    
    init: function(){
        this.totalItems = $("#highlights ul.w159 > li").length;
        this.intervalId = setInterval("highlights.showNext()", highlights.intervalTime);
        $("#highlights ul li:first.highlight").addClass('active');
        $("#highlights ul li.highlight").hover(
            function(){
                highlights.showNext(this);
            }
        );

        if($("li.highlight.active p.intro a:first").length > 0){
            $("li.highlight.active ul li").live('click', function(){
                window.location = $("p.intro a:first", this).attr('href');
            })
        }
    },
    showNext: function(active){
        $("#highlights ul li.highlight.active").removeClass("active");
        if(active == null){
            highlights.currentActive = (highlights.currentActive == (highlights.totalItems - 1)) ? 0 : (highlights.currentActive + 1);
            $("#highlights ul li.highlight:eq("+highlights.currentActive+")").addClass("active");
        }else{
            clearInterval(highlights.intervalId);
            $(active).addClass("active");
        }
    },
    adjustHeight: function(){
        var totalHeight = $("#highlights ul:first").height();
        if(totalHeight <= $("#highlights li.active ul").height()){
            $("#highlights").height($("#highlights ul li.highlight.active ul:first li").height() + 27);
        }else{
            $("#highlights").height(totalHeight);
        }
    }
}
