var box_zindex = 100;

$(document).ready(function(){ 

	$('.captionbox').css("opacity",.9);


	$('.captionbox').click(function(){
		  //Change z-index, so that each clicked box becomes first in stack
		  box_zindex++;
		  $(this).css('z-index', box_zindex);
	});									


	$('.captionbox').draggable({
		opacity:".5",
		distance:"5",
		cancel: ".nodrag" /* Don't act on elements with p tag*/
	});
	
	
	$('.captionbox_close a').click(function(){ 
		//alert((this).text);
		if ($(this).text()=='x') {
			$(this).text('+');
		} else {
			$(this).text('x');
		}
		$(this).closest(".captionbox").children(".captionbox_content").toggle('blind',{},new String("fast"));

	});	


	$('.toggleAll').click(function(){ 
		if ($(this).text()=='x') {
			// hide all
			$(this).text('+');
			$('.captionbox_close a').text('+');

			// ajax call to save current visibility state in session variable
			$('nothing').load('/hello/toggleAll_save.php?hide'); // using 'nothing' because we don't need the returned text

			$(".captionbox_content").hide('blind',{},new String("fast"));
		} else {
			// show all
			$(this).text('x');
			$('.captionbox_close a').text('x');
			// ajax call to save current visibility state in session variable
			$('nothing').load('/hello/toggleAll_save.php?show'); // using 'nothing' because we don't need the returned text
			$(".captionbox_content").show('blind',{},new String("fast"));
		}
		//$('.captionbox').toggle('explode',{pieces:9},new String("normal"));
		//$(".captionbox_content").toggle('blind',{},new String("fast"));
	});	

});
