

;

function moveSidebar()
{
    var viewportHeight;
    var contentHeight     = $('#content').height();
    var scrollbarHeight   = $('#sidebar').height();
    var previousScrollTop = $('#sidebar').attr('name');
    var currentScrollTop  = $(this).scrollTop();
    var sidebarOffset     = 0;
    
    //get viewport height
    //normal browsers
    if (typeof window.innerHeight != 'undefined') {
        viewportHeight = window.innerHeight
    //IE7+
    } else if (typeof document.documentElement != 'undefined' &&
               typeof document.documentElement.clientHeight != 'undefined' &&
               document.documentElement.clientHeight != 0) {
        viewportHeight = document.documentElement.clientHeight
    //IE6-
    } else {
        viewportHeight = document.getElementsByTagName('body')[0].clientHeight
    }
    
    //save current scroll top
    $('#sidebar').attr('name', currentScrollTop);
    
    //only scroll if previous and current scrolltop don't match
    if (previousScrollTop != currentScrollTop) {
        //is the sidebar bigger then the viewport
        if (scrollbarHeight < viewportHeight) {
            //no
            sidebarOffset = sidebarY.top + $(this).scrollTop();
        } else {
            //yes, scrolling down or up?
            if (previousScrollTop < currentScrollTop) {
                //down
                sidebarOffset = (viewportHeight - (scrollbarHeight - $(this).scrollTop()));
                if (sidebarOffset < 0) {
                    sidebarOffset = 0;
                }
            } else {
                //up
                sidebarOffset = sidebarY.top + $(this).scrollTop();
            }
        }
    
        //compare heights
        if (sidebarOffset >= contentHeight)  {
            //no scroll
            return false;
        } else {
            //scroll
            $('#sidebar').animate({top:sidebarOffset}, {duration:500, queue:false});
        }
    }
}

function carouselCallback(id, titleElement, index)
{
    var title = $(id + ' .viewport .overview li:eq('+index+') img').attr('alt');
    var color = $(id + ' .viewport .overview li:eq('+index+') img').attr('rel');
    $(id + ' .controls ' + titleElement).text(title);
    $(id + ' .logo img').attr('src', '/static/img/logo-' + color + '.png');
}

function expandContent(content)
{
    $(content).each(function(){
        var cExpand = $(this).find('.expand');
        var cHandle = $(this).find('.footer .more-info');
        
        cExpand.hide();
        
        cHandle.click(function(e){
            cExpand.slideToggle('slow');
            e.preventDefault();
        });
        
        cHandle.toggle(
            function() {
                cHandle.text('minder informatie -');
            },
            function() {
                cHandle.text('meer informatie +');
            }
        );
    });
}

function initExternalLinks()
{    
    var h = window.location.host.toLowerCase();
    $("a[href^='http']:not([href^='http://" + h + "']):not([href^='http://www." + h + "']), a[href$='.pdf'], a[rel='external']").attr("target","_blank");
}

$(document).ready(function() {

    //init menu
    $('#sidebar .navigation .main').initMenu();

    //replace menu font
    Cufon.replace('.navigation a', {hover: true});
    
    //scoll menu
    sidebarY = $('#sidebar').offset();
    $(window).scroll(moveSidebar);
    moveSidebar();

    //expand content
    //expandContent('#content .article div.body');
    
    initExternalLinks();
});

;

function setCookie(name, value, expires)
{
    document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}


function getCookie(name)
{
    if (document.cookie.length > 0) {
        
        var start = document.cookie.indexOf(name + "=");
        
        if (start != -1) {
        
            start = start + name.length + 1;
            var end = document.cookie.indexOf(";", start);
            
            if (end == -1) {
                end = document.cookie.length;
            }
            
            return unescape(document.cookie.substring(start, end));
        }
    }
    
    return "";
}

 

function twitterCachedCallback(c)
{
    // this will create the HTML. Function found inside blogger.js
    twitterCallback2(c);
    
    var content = document.getElementById("twitter_update_list").innerHTML;
    
    // expire cookie after 30 minutes
    var exp = new Date();
    exp.setTime(exp.getTime() + (1000 * 60 * 30));
    
    setCookie('twitter_content', content, exp);
}

 

$(document).ready(function() {
    // set content immediately if cached
    var cachedContent = getCookie('twitter_content');
    
    if (cachedContent) {
        document.getElementById("twitter_update_list").innerHTML = cachedContent;
    }
});
