$().ready(function() {

  /* 
    The 3 events below add, remove and submit species which belong to a certain location.
    A user can pull selected species out of a list of *all species*
  */

  $('#add_to_selected_species').click(function() {  
   return !$('#available_species option:selected').remove().appendTo('#selected_species');  
  });  

  $('#remove_from_selected_species').click(function() {  
   return !$('#selected_species option:selected').remove().appendTo('#available_species');  
  });

  $('form').submit(function() {  
   $('#selected_species option').each(function(i) {  
    $(this).attr("selected", "selected");  
   });  
  }); 
 
  /* Sets an Accordion for the survey submission */
  if ( $("#accordion").length > 0 ) { $("#accordion").accordion(); }

  imagePreview() ;

  if ($('.post')) { // engage forum posts are separate tables so need their own class

    $('.post tr:nth-child(odd)').addClass('altRow');

  }

  if ($('.forumlist')) { // Forum list tables

    $('.forumList tr').mouseover( function() { $(this).addClass('engageHighlightRow'); } );

    $('.forumList th').css( { 'background-color' : 'white', 'color' : 'black' } );
    $('.forumList th a').css('color','black');

    $('.forumList tr').mouseout( function() { $(this).removeClass('engageHighlightRow'); } );

    $('.forumList tr:nth-child(even)').addClass('altRow');

  }


}); 


this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 150;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){

		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});		
};