$(function(){
	
	$('div#leftcol ul li:last-child').css('border','none');
	$('ul.terapi-list li:last-child').css('border','none');
	
	$('.rightclick').bind("contextmenu", function(e) {
	    e.preventDefault();
	});
	
	$("ul#page_sort").sortable({ 
		opacity: 0.6, 
		cursor: 'move',
		handle: '.move',
		appendTo: 'ul',
		items: 'li',
		update: function() { 
			var parent = $(this).parent().parent().attr('id');
			var order = $(this).sortable("serialize") + '&table=frontpage&action=update&parent=' + parent;       
			$.post("includes/sortList.php", order, function(theResponse){ 
				$("#contentRight").html(theResponse); 
			});
		}
	});
	
	$("ul#opslag_sort").sortable({ 
		opacity: 0.6, 
		cursor: 'move',
		handle: '.move',
		appendTo: 'ul',
		items: 'li',
		update: function() { 
			var parent = $(this).parent().parent().attr('id');
			var order = $(this).sortable("serialize") + '&table=opslagstavlen&action=update&parent=' + parent;       
			$.post("includes/sortList.php", order, function(theResponse){ 
				$("#contentRight").html(theResponse); 
			});
		}
	});
	
	$("ul#opslagstavlen_sort").sortable({ 
		opacity: 0.6, 
		cursor: 'move',
		handle: '.move',
		appendTo: 'ul',
		items: 'li',
		update: function() { 
			var parent = $(this).parent().parent().attr('id');
			var order = $(this).sortable("serialize") + '&table=opslagstavlen&action=update&parent=' + parent;       
			$.post("includes/sortList.php", order, function(theResponse){ 
				$("#contentRight").html(theResponse); 
			});
		}
	});
	
	$('.accordion h3').bind('click', function(){
		$(this).next().toggle('slow');
		$(this).toggleClass('down');
	});
	$('#leftcol > ul li').css('border','');
	$('#leftcol > ul li:last').css('border','none');
	
	
	var nbLength = $('#citat').children().length;
	var nb = 0;
	
	function slideSwitch() {
		var $active = $('#citat div.active');
		if ( $active.length == 0 ) $active = $('#slideshow div:last');
		if(nb == nbLength){
			nb=1;
		}else{
			nb = nb+1;
		}
		// use this to pull the images in the order they appear in the markup
		var $next =  $active.next().length ? $active.next()
			: $('#citat div:first');
		// uncomment the 3 lines below to pull the images in random order
		// var $sibs  = $active.siblings();
		// var rndNum = Math.floor(Math.random() * $sibs.length );
		// var $next  = $( $sibs[ rndNum ] );
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
		if(nb < nbLength){
			setTimeout(function(){
				slideSwitch();
			}, 5000);
		}else{
			setTimeout(function(){
				slideSwitch()
			}, 24000);
		}
	}
	setTimeout(function(){
		slideSwitch();
	}, 24000);
});
