
// JavaScript Document
// When the document loads do everything inside here ...


     $(document).ready(function(){
     
     
function processBlast() {
    	$("#blast_form").slideUp("slow");	
			$("#seenome_pics").slideUp("slow");		
			var title = "blast"; //retrieve title of link so we can compare with php file
			var blast_seq_in = $("#blast_seq").attr("value"); //retrieve title of link so we can compare with php file
			var blast_seq = blast_seq_in.replace(/ /g,'');
			
			$.ajax({
				method: "get",url: "lib/php/process.php",data: "title="+title+"&blast_seq="+blast_seq,
				beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
				complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
				success: function(html){ //so, if data is retrieved, store it in html
					//$("#blast_results").show("slow"); //animation
					//animation
					$("#results").prepend(html); //show the html inside .content div
					Nifty(".blast_results","big top transparent");	
					$("#blast_form").slideDown("slow");	
					$(".blast_results_close").filter("#close_"+blast_seq).toggle( 
						function(){									  
							$(".blast_results").filter("#blast_results_"+blast_seq).hide("slow"); //animation	
							$(this).css( "background", "url(lib/images/add_16.png) no-repeat top right" );
						},
						function(){
							$(".blast_results").filter("#blast_results_"+blast_seq).show("slow"); //animation	
							$(this).css("background","url(lib/images/cancel_16.png) no-repeat top right");	
						}
					) // end toggle
				}
	 		}); //close $.ajax(
}   // end function process blast

function getOrthologsFromParalogs() {	
	var title = "orthologs_from_paralog"; //retrieve title of link so we can compare with php file
	var blast_seq = $("#blast_seq").attr("value"); //retrieve title of link so we can compare with php file
	$.ajax({
		method: "get",url: "lib/php/process.php",data: "title="+title+"&blast_seq="+blast_seq,
		beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
		complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
		success: function(html){ //so, if data is retrieved, store it in html
					//$("#blast_results").show("slow"); //animation
					$(".blast_results_close").show("slow"); //animation
					$("#results").prepend(html); //show the html inside .content div
					Nifty(".blast_results","big top transparent");	
					$("#blast_form").slideDown("slow");	
					$(".blast_results_close").filter("#close_"+blast_seq).toggle( 
						function(){									  
							$(".blast_results").filter("#blast_results_"+blast_seq).hide("slow"); //animation	
							$(this).css( "background", "url(lib/images/add_16.png) no-repeat top right" );
						},
						function(){
							$(".blast_results").filter("#blast_results_"+blast_seq).show("slow"); //animation	
							$(this).css("background","url(lib/images/cancel_16.png) no-repeat top right");	
						}
					) // end toggle
				}
	 		}); //close $.ajax(
}   // end function process blast

function getContig() {	
	var title = "download"; //retrieve title of link so we can compare with php file
	var genome_id = $("#blast_seq").attr("value"); //retrieve title of link so we can compare with php file
	$.ajax({
		method: "get",url: "lib/php/process.php",data: "title="+title+"&blast_seq="+blast_seq,
		beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
		complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
		success: function(html){ //so, if data is retrieved, store it in html
					//$("#blast_results").show("slow"); //animation
					$(".blast_results_close").show("slow"); //animation
					$("#results").prepend(html); //show the html inside .content div
					Nifty(".blast_results","big top transparent");	
					$("#blast_form").slideDown("slow");	
					$(".blast_results_close").filter("#close_"+blast_seq).toggle( 
						function(){									  
							$(".blast_results").filter("#blast_results_"+blast_seq).hide("slow"); //animation	
							$(this).css( "background", "url(lib/images/add_16.png) no-repeat top right" );
						},
						function(){
							$(".blast_results").filter("#blast_results_"+blast_seq).show("slow"); //animation	
							$(this).css("background","url(lib/images/cancel_16.png) no-repeat top right");	
						}
					) // end toggle
				}
	 		}); //close $.ajax(
}   // end function process blast

function processSearch(){
			$("#search_form").slideUp("slow");
			$("#seenome_pics").slideUp("slow");						
			var title = "search"; //retrieve title of link so we can compare with php file
			var keyword = $("#keyword").attr("value"); //retrieve title of link so we can compare with php file
			$.ajax({
				method: "get",url: "lib/php/process.php",data: "title="+title+"&keyword="+keyword,
				beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
				complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
				success: function(html){ //so, if data is retrieved, store it in html
					//$("#search_results").show("slow"); //animation
					$(".search_results_close").show("slow"); //animation
					$("#results").prepend(html); //show the html inside #results div
					Nifty("div.search_results","big top transparent");	
					$("#search_form").slideDown("slow");	
					$(".search_results_close").filter("#close_"+keyword).toggle( 
						function(){									  
							$(".search_results").filter("#search_results_"+keyword).hide("slow"); //animation	
							$(this).css( "background", "url(lib/images/add_16.png) no-repeat top right" );
						},
						function(){
							$(".search_results").filter("#search_results_"+keyword).show("slow"); //animation		
							$(this).css("background","url(lib/images/cancel_16.png) no-repeat top right");
						}
					) // end toggle
					$(".show_dna_"+keyword).toggle(
						function() {
							var feat_name = $(this).attr("value");
							$("#dna_label_"+feat_name).show("slow");
							$("#dna_results_"+feat_name).show("slow");
							
						},
						function() {
							var feat_name = $(this).attr("value");
							$("#dna_label_"+feat_name).hide("slow");
							$("#dna_results_"+feat_name).hide("slow");
						}
					) // end toggle
					$(".show_protein_"+keyword).toggle(
						function() {
							var feat_name = $(this).attr("value");
							$("#protein_results_"+feat_name).show("slow");
							$("#protein_label_"+feat_name).show("slow");
							console.log("protixzzy izzzy? " + feat_name);
						},
						function() {
							var feat_name = $(this).attr("value");
							$("#protein_results_"+feat_name).hide("slow");
							$("#protein_label_"+feat_name).hide("slow");
						}
					) // end toggle
					$(".display_paralogs").click(
						function () {   
						var par_fam_id = $(this).attr("value"); //retrieve title of link so we can compare with php file
						$("#paralogs_" + par_fam_id).show("slow");
						//Nifty("#download_list_"+genome_id,"big transparent");	
						var position = $(this).position();
 						var offset = $(this).offset();
						//console.log("left: " + position.left + ", top: " + position.top + "   o left: " + offset.left + ", o  top: " + offset.top);
						$("#paralogs_"+ par_fam_id).css(
							{
								'position' : 'absolute',
								'top' : offset.top, 
								'left' : offset.left
							}
				
						);
					$.ajax({
						method: "get",url: "lib/php/process.php",data: "title=orfs_from_paralog&par_fam_id="+par_fam_id,
						beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
						complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
						success: function(html){ //so, if data is retrieved, store it in html
							$("#paralogs_inner_" + par_fam_id).html(html); //show the html inside .content div
					
						}
	 				}); //close $.ajax(
					

				
		}
	); // end click  
				} // end success function
	 		}); //close $.ajax(
} // end processSearch function
     
function showInstructions(){ 
	$("#seenome_instructions_wrapper").show("slow");
		Nifty("div#seenome_instructions","medium transparent");
		Nifty("div.seenome_instructions","medium transparent");
} 
		Nifty("div.nav","medium transparent");
				
        $('#search_submit').click(function() { //start function when search_submit is clicked
		 		processSearch();
       	}); //close click(
       	$('.search_input').keypress(function(e){
				var code = (e.keyCode ? e.keyCode : e.which);
 				if(code == 13) { //Enter keycode
   				processSearch();
	 		}     
     
     });
    $('#blast_submit').click(function() { //start function when search_submit is clicked
			processBlast();			 	
		 	
     }); //close click(
     $('.blast_input').keypress(function(e){
			var code = (e.keyCode ? e.keyCode : e.which);
 			if(code == 13) { //Enter keycode
   			processBlast();
	 		}     
     
     });

       	
		
	
	
	$("#search_prompt").click(
      function () {
	  	$("#download_links").hide("slow");

		$("#seenome_links").hide("slow");
		$("#seenome_instructions_wrapper").hide("slow");
		$("#b31_contig_downloads").hide("slow");
      }, 
      function () {
		  // do nothing
      }
    ); // end click
	
	
		
	
	
	$("#blast_prompt").click(
      function () {
	  	$("#download_links").hide("slow");
	  	$("#b31_contig_downloads").hide("slow");
	  
		$("#seenome_instructions_wrapper").hide("slow");
		$("#seenome_links").hide("slow");
		
      }, 
      function () {
		  // do nothing
      }
     ); // end click
    
	$("#seenome_nav").toggle(
      function () {
	  	$("#download_links").hide("slow");
	  	$("#b31_contig_downloads").hide("slow");
	  	$("#citation").hide("slow");
	  	$("#seenome_instructions_wrapper").hide("slow");
		$("#seenome_links").slideDown("slow");
		$("#seenome_pics").show("slow");
		$("#seenome_links").show("slow");
      }, 
      function () {
		  	$("#seenome_links").slideUp("slow");
			$("#seenome_pics").hide("slow");
			$("#seenome_links").hide("slow");
      }
    ); // end toggle
    $("#paralog_nav").toggle(
      function () {
	  	$("#download_links").hide("slow");
	  	$("#b31_contig_downloads").hide("slow");
	  	$("#citation").hide("slow");
	  	$("#seenome_instructions_wrapper").hide("slow");
		$("#seenome_links").hide("slow");
		$("#seenome_pics").hide("slow");
		$("#seenome_links").hide("slow");
		$("#paralog_table").show("fast");		
		
      }, 
      function () {
		  	$("#paralog_table").hide("fast");
      }
    ); // end toggle
    
	$("#instructions_nav").toggle(
		function () {      
      	showInstructions();
      }, 
      function () {
		  $("#seenome_instructions_wrapper").hide("slow");
      }
    ); //end click
    $("#citation_nav").toggle(
		function () {   
			$("#seenome_links").hide("slow");
			$("#seenome_instructions_wrapper").hide("slow");   
      	$("#citation").show("slow");
      }, 
      function () {
		  $("#citation").hide("slow");
      }
    ); //end click
   $("#tutorials_nav").toggle(
		function () {   
			$("#seenome_links").hide("slow");
			$("#seenome_instructions_wrapper").hide("slow");   
      	$("#citation").hide("slow");
			$("#tutorials").show("slow");
      }, 
      function () {
		  $("#tutorials").hide("slow");
      }
    ); //end toggle
    $("#tutorials_site_download").toggle(
		function () {   
			$("#tutorials_site_download_details").show("slow");
      }, 
      function () {
		  $("#tutorials_site_download_details").hide("slow");
      }
    ); //end toggle
    $("#tutorials_site_blast").toggle(
		function () {   
			$("#tutorials_site_blast_details").show("slow");
      }, 
      function () {
		  $("#tutorials_site_blast_details").hide("slow");
      }
    ); //end toggle
    $("#tutorials_site_search").toggle(
		function () {   
			$("#tutorials_site_search_details").show("slow");
      }, 
      function () {
		  $("#tutorials_site_search_details").hide("slow");
      }
    ); //end toggle
	$("#tutorials_seenome_general").toggle(
		function () {   
			$("#tutorials_seenome_general_details").show("slow");
      }, 
      function () {
		  $("#tutorials_seenome_general_details").hide("slow");
      }
    ); //end toggle
    $("#tutorials_seenome_alignments").toggle(
		function () {   
			$("#tutorials_seenome_alignments_details").show("slow");
      }, 
      function () {
		  $("#tutorials_seenome_alignments_details").hide("slow");
      }
    ); //end toggle
    $("#tutorials_seenome_screenshots").toggle(
		function () {   
			$("#tutorials_seenome_screenshots_details").show("slow");
      }, 
      function () {
		  $("#tutorials_seenome_screenshots_details").hide("slow");
      }
    ); //end toggle
   
    
	$("#show_instructions").toggle(
		function () {      
      	showInstructions();
      }, 
      function () {
		  $("#seenome_instructions_wrapper").hide("slow");
      }
    ); // end click
    $("#tree_picture").hover(
    	function () {      
      	$("#tree_picture_instructions").show("slow");
      }, 
      function () {
		   $("#tree_picture_instructions").hide("slow");
      }
    );
     $("#tree_picture").toggle(
     		function () {
     			$(this).fadeOut('fast', function() {
        			$("#tree_picture_img").attr("src", "lib/images/isolate_tree_phylogram.png");
      		});
      		$(this).fadeIn('fast', function() {
        			$("#tree_picture_img").animate({ 
    					width: "1040px",
    					height: "600px",
  					}, 500 );
  					$("#tree_picture_instructions").html("Click on the phylogram to view a cladogram");	
      		});    					
     		},
     		function () {
     			$(this).fadeOut('fast', function() {
        			$("#tree_picture_img").attr("src", "lib/images/cladogram_3.png");
      		});
      		$(this).fadeIn('fast', function() {
        			$("#tree_picture_img").animate({ 
    					width: "300px",
    					height: "585px",
  					}, 500 );
  					$("#tree_picture_instructions").html("Click on the cladogram to view a phylogram");	
	
      		});
     		}
     	); // end picture click
     $(".download_genome").click(
			function () {   
				var genome_id = $(this).attr("value"); //retrieve title of link so we can compare with php file
				$("#download_list_"+genome_id).show("slow");
				Nifty("#download_list_"+genome_id,"big transparent");	
				var position = $(this).position();
 				var offset = $(this).offset();
				//console.log("left: " + position.left + ", top: " + position.top + "   o left: " + offset.left + ", o  top: " + offset.top);
				$("#download_list_"+genome_id).css(
					{
						'position' : 'absolute',
						'top' : offset.top, 
						'left' : offset.left
					}
				
				);
				
		},
			function () {
		  // do nothing
      }
	); // end click  
	$(".display_orthologs").click(
			function () {   
				var par_fam_id = $(this).attr("value"); //retrieve title of link so we can compare with php file
				var genome_id = $(this).attr("genome_id"); //retrieve title of link so we can compare with php file
				var mol_id = $(this).attr("mol_id"); //retrieve title of link so we can compare with php file
				var feat_name = $(this).attr("feat_name"); //retrieve title of link so we can compare with php file
				$("#orthologs_" + par_fam_id).show("slow");
				//Nifty("#download_list_"+genome_id,"big transparent");	
				var position = $(this).position();
 				var offset = $(this).offset();
				console.log("genome id: " + genome_id + ", feat: " + feat_name + "   o left: " + offset.left + ", o  top: " + offset.top);
				$("#orthologs_"+ par_fam_id).css(
					{
						'position' : 'absolute',
						'top' : offset.top, 
						'left' : offset.left
					}
				
				);
				$.ajax({
					method: "get",url: "lib/php/process.php",data: "title=orthologs_from_paralog&par_fam_id="+par_fam_id+"&genome_id="+genome_id+"&mol_id="+mol_id+"&feat_name="+feat_name,
					beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
					complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
						$("#orthologs_" + par_fam_id).prepend(html); //show the html inside .content div
					
					}
	 			}); //close $.ajax(
					

				
		}
	); // end click  
		$(".display_paralogs").click(
			function () {   
				var par_fam_id = $(this).attr("value"); //retrieve title of link so we can compare with php file
				$("#paralogs_" + par_fam_id).show("slow");
				//Nifty("#download_list_"+genome_id,"big transparent");	
				var position = $(this).position();
 				var offset = $(this).offset();
				//console.log("left: " + position.left + ", top: " + position.top + "   o left: " + offset.left + ", o  top: " + offset.top);
				$("#paralogs_"+ par_fam_id).css(
					{
						'position' : 'absolute',
						'top' : offset.top, 
						'left' : offset.left
					}
				
				);
				$.ajax({
					method: "get",url: "lib/php/process.php",data: "title=orfs_from_paralog&par_fam_id="+par_fam_id,
					beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
					complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
						$("#paralogs_inner_" + par_fam_id).html(html); //show the html inside .content div
					
					}
	 			}); //close $.ajax(
					

				
		}
	); // end click  
	   $(".download_close").toggle( 
			
			function(){		
				var parent =  $(this).parent(); //retrieve title of link so we can compare with php file
				console.log(parent); 							  
				$(parent).hide("slow"); //animation	
	
			},
			function(){
				var parent =  $(this).parent(); //retrieve title of link so we can compare with php file
				console.log(parent); 					
				$(parent).show("slow"); //animation	

			}
		); // end toggle
		 $(".paralog_close").toggle( 
			
			function(){		
				var parent =  $(this).parent(); //retrieve title of link so we can compare with php file 							  
				$(parent).hide("slow"); //animation	
				console.log("close clickt");
			},
			function(){
				var parent =  $(this).parent(); //retrieve title of link so we can compare with php file					
				$(parent).show("slow"); //animation	
				console.log("close clickt");
			}
		); // end toggle

	

	
	$("#b31_download").hover(
      function () { 
	  	$("#seenome_pics").hide("slow");
		$("#b31_contig_downloads").show("slow");
		
      }, 
      function () {
		  // do nothing
      }
    ); // end hover
	
   
}); //close $(
