
$(document).ready(function(){


//clicking on logo leads to homepage
	$(".logo").livequery('click', function(){ document.location = '/';	});

//start custom scroller(s)
	$(".scroller").jScrollPane({
		scrollbarWidth: 8,
		scrollbarMargin: 0,
		dragMinHeight: 100,
                showArrows: true
	});

//course chooser in footer
	$("#plus").livequery('click',function(e){
		if ($("#sel").html() != 'OPLEIDING SELECTOR') {
			$(this).attr('src', '/media/layout/plus.gif');
			$("#sel").html("OPLEIDING SELECTOR");
			$("#sel").css({
				bottom: '-15px',
				background: '#fff',
				border: '1px solid #cacaca'
			});
		} else {
			$(this).attr('src', '/media/layout/min.gif');
			$("#sel").html($("#sel2").html());
			$("#sel").css({
				bottom: ($("#sel").outerHeight() - 41) + 'px',
				background: '#fff url(/media/layout/or_top.jpg) no-repeat top center',
				borderTop: '0px'
			});
		}
		e.preventDefault();
	});

//searchfield in footer
	$("#search").livequery('focus', function(){
		$(this).val('');
	});
	$("#search").livequery('blur', function(){
		if ($(this).val().length < 1)
			$(this).val($(this).attr('title'));
	});
	function zoek() {
		location.hash = '#search';
		var da = new Object();
		da.search = $("#frm_search #search").val();
		
		$.ajax({
			type: 'POST',
			url: '/search.php',
			data: da,
			success: function(data){
				//alert(data);
				$('#content .wrapper').html(data);
			}
		});
	}
	$("#frm_search #searchbutton").livequery('click', function(e) {
		zoek();
		e.preventDefault();
	});
	$("#frm_search").livequery('submit', function(e) {
		zoek();
		e.preventDefault();
	});

        var randomli  = $(".scroller #chooser li").random();
        $(".scroller #chooser li").attr('id', '');
        randomli.attr('id', 'selected');
        $("#top_scroll #items img").attr('src', randomli.children("a").next().attr('src'));
	$("#top_scroll #items #opl_klik").attr('href', randomli.children("a").attr('href'));

	$.metadata.setType('attr','data');
//show course-image on mouseover (home-page)
	$(".scroller #chooser a").livequery('mouseenter',function(e){
		$(".scroller #chooser li").attr('id', '');
		$(this).parent().attr('id', 'selected');
		$("#top_scroll #items img").attr('src', $(this).next().attr('src'));
		$("#top_scroll #items #opl_klik").attr('href', $(this).attr('href'));
		e.preventDefault();
	});

	function setScroller(obj) {
		obj.attr('id', 'selected');
		$("#top_scroll #items img").attr('src', obj.children("img").attr('src'));
		$("#top_scroll #items #opl_klik").attr('href', obj.children("a").attr('href'));
	}
//switch between courses (images and links) through prev- and next-buttons
	$('#prev').livequery('click', function(){
		var now = $(".scroller #chooser #selected"); //currently selected
		$(".scroller #chooser li").attr('id', '');
		if (now.prevAll('li').length != 0) { //if there are one or more li's before the current one
			setScroller(now.prev()); //show the one before the current one
		}else {
			setScroller(now.parent().children(':last')); //show the last one
		}
	});
	$('#next').livequery('click', function(){
		var now = $(".scroller #chooser #selected"); //currently selected
		$(".scroller #chooser li").attr('id', '');
		if (now.nextAll('li').length != 0) { //if there are one or more li's after the current one
			setScroller(now.next()); //show the one after the current one
		} else {
			setScroller(now.parent().children(':first')); //show the first one
		}
	});

//toggle cloud on a coursepage (both flash- and HTML-clouds)
	$("#cloudtoggler a").livequery('click',	function (e){
		if ($(this).html() == 'Toon cloud') {
			$("#tagcloud").animate({'height': '225px'}, 'normal', 'swing', function(){$("#cloudtoggler a").html('Verberg cloud');});
			$("#toggleablecloud").show('normal');
			$("#smallcloud").show('normal');
		} else {
			$("#tagcloud").animate({'height': '27px'}, 'normal', 'swing', function(){$("#cloudtoggler a").html('Toon cloud');});
			$("#toggleablecloud").hide('normal');
			$("#smallcloud").hide('normal');
		}
		e.preventDefault();
	});

//print some stuff
	$(".print").click(function(){
		var printitem = $(this).attr('rel');
		$(printitem).print();
		return(false);
	});

//tooltip
	$(".tt").tooltip({
		tip: '#tooltip',
		offset: [10,2],
		effect: 'slide'
	});

//image-map on 'academy'-page
	$("#bigside #blue").mouseenter(function(){$("#bigside #bigimg").attr('src', $("#bigside #blue_img").attr('src'));});
	$("#bigside #blue").mouseleave(function(){$("#bigside #bigimg").attr('src', $("#bigside #base_img").attr('src'));});

	$("#bigside #green").mouseenter(function(){$("#bigside #bigimg").attr('src', $("#bigside #green_img").attr('src'));});
	$("#bigside #green").mouseleave(function(){$("#bigside #bigimg").attr('src', $("#bigside #base_img").attr('src'));});

	$("#bigside #yellow").mouseenter(function(){$("#bigside #bigimg").attr('src', $("#bigside #yellow_img").attr('src'));});
	$("#bigside #yellow").mouseleave(function(){$("#bigside #bigimg").attr('src', $("#bigside #base_img").attr('src'));});

});
