function createCookie(name,value,days) {
	var expires = "";
    if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	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;
}

$(document).ready(function(){

	// flash inladen
	// als een div aangemaakt wordt met als class "flash",
	// en als inhoud het absolute pad naar de flash en de variable
	// wordt deze automatisch ingeladen
	$('.flash').each(function(){
		slideshowvars = $(this).find('.flashlink').html();
		slideshowheight = $(this).css('height');
		slideshowwidth = $(this).css('width');
		$(this).html("");
		$(this).flash({
	    	src: slideshowvars,
	    	width: slideshowwidth,
	    	height: slideshowheight,
            wmode: 'transparent'
		});
	});

	// verzend links in formulieren maken
	$('.verzendlink').click(function(){
		$(this).parents('form').submit();
	});

	// links in "_blank" i.p.v. via HTML i.v.m. valid XHTML
	$('.blankwindow').attr('target','_blank');

    $('.contactcolorbox').click(function(){

		var targetid = $(this).attr('rel');
		if (typeof targetid == 'undefined' || targetid == '') return ;

		$(this).colorbox({
			open: true,
			inline: true,
			transition:'none',
			href: "#" + targetid
		});
	});

    // <a href="javascript:;" class="contactcolorbox" rel="contactform">test</a>
    
    // laatste 10 pagina's opslaan
    var x = readCookie('pageviewcookie')
    var lastTen = new Array();
    if (x) {
        lastTen = x.split("|");
    }
    lastTen.push(document.location);
    while(10 < lastTen.length) {
        lastTen.shift();
    }
    var y = lastTen.join("|");
    createCookie('pageviewcookie',y,7);

    $('.LastTenField').each( function() {
        $(this).attr('value',y);
    });
});

function reloadToClearColorbox()
{
    window.location.href = window.location.href;
}

function contactcolorbox()
{
    $.fn.colorbox({
        open: true,
        inline: true,
        transition:'none',
        href: "#contactform",
        onClosed:function(){
            reloadToClearColorbox();
        }
    });
}

function belmijcolorbox()
{
    $.fn.colorbox({
        open: true,
        inline: true,
        transition:'none',
        href: "#contactform2",
        onClosed:function(){
            reloadToClearColorbox();
        }
    });
}
