$(document).ready(function(){
	if ($("a.fancybox").length > 0) {
		$("a.fancybox").fancybox({
			'titleShow'     : false
		});
	}
	if ($(".slideshow").length > 0) {
		$('.slideshow').cycle({fx:'fade',speed:3000,timeout:3000});
	}
	
	$("a[rel='external']").click(function(){
    	window.open($(this).attr('href'));
    	return false;
    });
    
    /* search function */
    $('#PageTerm')
    	.focus(function(){ if ($(this).val() == 'Zoeken...') { $(this).val(''); } })
    	.blur(function(){ if ($(this).val() == '') { $(this).val('Zoeken...'); } })
    	.click(function(){ if ($(this).val().length > 0) { $(this).focus();$(this).select(); } });
    
    /* menu slide */
    $('#menu ul.subnav li[class!="selected"] ul').hide();
    $('#menu ul.subnav li a').click(function(){
    	if ($(this).parent().children('ul').length > 0) {
    		if ($(this).parent().children('ul').is(':hidden')) {
    			$('#menu ul.subnav li ul').slideUp();
	    		$(this).parent().children('ul').slideDown();
    		}
    		else{
    			$('#menu ul.subnav li ul').slideUp();
    		}
    		return false;
    	}
    });
    
    /* header fadein */
    $('.headerfadein')
    	.css({'opacity':'0', 'display':'block'})
		.animate({opacity: "1"}, { "duration": 1550, "easing": "easeInSine" });
});

function createSortable(id, itemsClass, handler, action, direction){
	$(id).sortable({
        items: itemsClass,
        delay: 10,
        distance: 0,
        axis: direction,
        opacity: 0.5,
        placeholder: 'ui-placeholder',
        handle: handler,
		update: function(e, ui){
            $.ajax({
                type: "POST",
                url: webroot+action,
                data: "itemId=&newOrder="+$(id).sortable('toArray'),
                error: function(msg){
                    $("#JQresult").html(msg);
                },
                success: function(msg){
                    $("#JQresult").html(msg);
                }
            });
		}
    });
}
