window.addEvent('domready', function() {

$$('.ajax').each(function(el) {   
  
        //add an event..   
        el.addEvent('click', function(e) {   
            e = new Event(e).stop();   
						var tosend = this.rel;
						
						var myFx = new Fx.Tween($('which_courses')).addEvent('onComplete', function(){
      						var myFx2 = new Fx.Tween($('which_courses'));
      						myFx2.start('height', [0, 90]);
									myFun();
						}
						);
						myFx.start('height', [$('which_courses').height, 0]);
						
						
						
						
						function myFun(){
						var myRequest = new Request.HTML({
								url: 'savecourse.php',
								 
								
          								onSuccess: function(){   
                          
                          var myString = myRequest.response.text;
                             
                             
                          //I'm expecting three results back, one for each div.   
                          //I also know where they are in the array (0,1 and 2 respectively)   
                             
                          $('which_courses').innerHTML = myString;  
                          
													
													           $$('.remove').each(function(ele) {   
  
                                              //add an event..   
                                              ele.addEvent('click', function(em) {  
                                                  em = new Event(em).stop();   
                                      					  tosend2 = this.rel;
																									
																									var myRequest2 = new Request.HTML({
																											url: 'removecourse.php',
																													 	onSuccess: function(){
																																	var myString2 = myRequest2.response.text;
																																	$(tosend2).innerHTML = "";
																														}								
																									
																									}).send("course="+tosend2);
																										
                                      				});
                                      });
													
                          
                          }  

								
								}).send("course="+tosend);
						
						}
						
				});
});
	
	
});