$(document).ready(

	function() {
	
		initSearch();
		initMailtoLinks();
		
		initCarousel();
		
		// alle submenu's verbergen behalve die van de huidige pagina
		$(".sub").hide();
		$(".with_sub.active_sub .sub").show();

		// geef elk submenu een uniek id
		$(".sub").each(
			function(i) {
				var id = "sub_" + i;
				$(this).attr({ id:id });
			}
		);
		
		// geef de parent li een rel met het zelfde nummer als het id van het submenu
		$(".with_sub").each(
			function(i) {
				var rel = i;
				$(this).attr({ rel:rel });
			}
		);
		
		// toon submenu als de muis over de parent li gaat, verberg submenu als de muis van de li af gaat
		$(".with_sub").hoverIntent({
				sensitivity: 7,	// number = sensitivity threshold (must be 1 or higher)
				interval: 150,		// number = milliseconds of polling interval
				over: showNav,		// function = onMouseOver callback (required)
				timeout: 150,		// number = milliseconds delay before onMouseOut function call
				out: hideNav		// function = onMouseOut callback (required)
		});
		
		

	}
	
);



function initCarousel()
{
	if ( document.getElementById('mag_carousel') )
	{
	/*
		var so = new SWFObject("/static/swfobject/carousel_dock.swf", "tvmags", "400", "255", "8", "#ffffff");
		so.addVariable( "dataUrl", "/page/xml_carousel");
		so.write("mag_carousel");
		*/
	}
	
	var id = 'mag_carousel';
	
	if ( document.getElementById(id) )
	{
		var flashvars = { dataUrl : "/page/xml_carousel" };
		var params = { wmode: "transparent" };
		var attributes = {};
					
		swfobject.embedSWF("/static/swfobject/carousel_dock.swf", id, "400", "255", "9.0.0", "/static/swfobject/expressInstall.swf", flashvars, params, attributes );
	}

}

function showNav() {
	var clearQueue	= true;
	var gotoEnd		= true;
	var curSub		= $(this).attr("rel");
	$("#sub_" + curSub).stop(clearQueue , gotoEnd).slideDown("slow");
	$(this).addClass("active_sub");
}

function hideNav() {
	var clearQueue	= true;
	var gotoEnd		= true;
	var curSub		= $(this).attr("rel");
	$("#sub_" + curSub).stop(clearQueue , gotoEnd).slideUp("slow");
	$(this).removeClass("active_sub");
}

function initSearch() {

	function search(e)
	{
		var searchField	= $("#zoekveld").val();
		
		if (searchField != "") {
			var searchPage	= $(".zoeken a").attr("href");
			var searchURL	= searchPage + "/" + searchField + "/1/0";
			//$(".zoeken a").attr({ href: seachURL });

			document.location.href = searchURL;
			
			e.preventDefault();
		}
	}
	
	$(".zoeken a").click(
		
		search
	);
	
	$(".zoeken").submit(
		
		search
	);
}

function replace( str, naald, vervanging) {
	return str.split(naald).join(vervanging);
}

function initMailtoLinks() {
	$("a[rel='mail']").each(
		function() {
			var href = $(this).attr('href');
			$(this).attr( 'href', "mailto:" + replace( href, "[at]", "@") );		
		}
	);

}
/*
reflection.js for jQuery v1.02
(c) 2006-2008 Christophe Beyls <http://www.digitalia.be>
MIT-style license.
*/
(function(a){a.fn.extend({reflect:function(b){b=a.extend({height:0.33,opacity:0.5},b);return this.unreflect().each(function(){var c=this;if(/^img$/i.test(c.tagName)){function d(){var j,g=Math.floor(c.height*b.height),k,f,i;if(a.browser.msie){j=a("<img />").attr("src",c.src).css({width:c.width,height:c.height,marginBottom:-c.height+g,filter:"flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+(b.opacity*100)+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+(b.height*100)+")"})[0]}else{j=a("<canvas />")[0];if(!j.getContext){return}f=j.getContext("2d");try{a(j).attr({width:c.width,height:g});f.save();f.translate(0,c.height-1);f.scale(1,-1);f.drawImage(c,0,0,c.width,c.height);f.restore();f.globalCompositeOperation="destination-out";i=f.createLinearGradient(0,0,0,g);i.addColorStop(0,"rgba(255, 255, 255, "+(1-b.opacity)+")");i.addColorStop(1,"rgba(255, 255, 255, 1.0)");f.fillStyle=i;f.rect(0,0,c.width,g);f.fill()}catch(h){return}}a(j).css({display:"block",border:0});k=a(/^a$/i.test(c.parentNode.tagName)?"<span />":"<div />").insertAfter(c).append([c,j])[0];k.className=c.className;a.data(c,"reflected",k.style.cssText=c.style.cssText);a(k).css({width:c.width,height:c.height+g,overflow:"hidden"});c.style.cssText="display: block; border: 0px";c.className="reflected"}if(c.complete){d()}else{a(c).load(d)}}})},unreflect:function(){return this.unbind("load").each(function(){var c=this,b=a.data(this,"reflected"),d;if(b!==undefined){d=c.parentNode;c.className=d.className;c.style.cssText=b;a.removeData(c,"reflected");d.parentNode.replaceChild(c,d)}})}})})(jQuery);

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
jQuery(function($) {
	$("img.reflect").reflect({/* Put custom options here */});
	$(".item .reflect img").addClass("reflected");
	$(".item .reflect canvas").addClass("reflected");
});