// our event listener receives the carousel
// object, so we just check to see if it's 
// turned itself off or not...
function afterAnimation(carousel){
    if(carousel.autoStopped){
        carousel.startAuto()
    }
}

jQuery(document).ready(function(){
	TriggerClickLeft = 0; //for educational left moving click
	TriggerClickRight = 0; //for educational right moving click
	//carousel for the home page
	
	var options = {
        auto: 4,
        scroll:1,
		visible:1,
        wrap: 'circular', // with this solution, wrap doesn't matter any more
        // itemLastInCallBack fires when a new 'last' image
        // shows up
        itemLastInCallback:{
            onAfterAnimation: afterAnimation
            }
    }
	try {
		jQuery('#carousel').jcarousel(options);
	} catch(e) {};
	
	
	//educational moving info
	$('.edu_left_pos').click(function() {
	  if (TriggerClickLeft == 0) {
	  	TriggerClickLeft = 1;
	  	$(".edu_left_pos").animate({marginLeft:'-392px'}, 500);  //marginleft - width+paddingsleftright
		$('.edu_left_move').animate({
	  		"width": "360px",
			"height": "820px",
			"opacity":"1"
		}, 500, function(){
	  		// Animation complete.
					$('.scroll-pane').jScrollPane();
				});
		}
		else {
			TriggerClickLeft=0;
			$(".edu_left_pos").animate({marginLeft:'0px'}, 500);
			$('.edu_left_move').animate({
		  		"width": "0px",
				"height": "0px",
				"opacity":"0"
			}, 500, function(){
		  		// Animation complete.
						$('.scroll-pane').jScrollPane();
					});
			}
	});
	
	$('.edu_right_pos').click(function() {
	  if (TriggerClickRight == 0) {
	  	TriggerClickRight = 1;
	  	$('.edu_right_move').animate({
	  		"width": "360px",
			"height": "820px",
			"opacity":"1"
		}, 500, function(){
	  		// Animation complete.
					$('.scroll-pane').jScrollPane();
				});
		}
		else {
			TriggerClickRight=0;
			$('.edu_right_move').animate({
		  		"width": "0px",
				"height": "0px",
				"opacity":"0"
		  	}, 500, function(){
		  		// Animation complete.
						$('.scroll-pane').jScrollPane();
					});
			}
	});
	
	//Educational protocols
	$('.protocol_select').click(function(){
		$('#selected_protocol').html('');
		$('#selected_protocol').append($(this).find(".usage_table_content").html());
		
		var protocol_id = $(this).find('.protocol_id').val();
		if (parseInt(protocol_id)>0){
			var _href = $('#save_protocol_bt').attr("href").substring(0, $('#save_protocol_bt').attr("href").lastIndexOf("/")+1);
			$('#save_protocol_bt').attr("href", _href + protocol_id);
		}
	});
	
});

