	$(document).ready(function(){
	
		
		var file1="lbaesip_titles2.jsp";
		//var file2="lba_parameter_source_sensor2.jsp";
		//var file3="lba_parameter_source_site2.jsp";
		//var file4="lba_topic_term_parameter2.jsp";
		//var file5="lba_site_sensor_parameter2.jsp";
		
	
		$('#inner_top_files').one("click",function(){	
		  $('#innermost_files').load(file1);
		});
		
		var loadText  = function(){
		  $('#innermost_parameter2').load(file2,function(){
		  	$('#loadProperty2').trigger('click');
		  });
		};
		
	
		 var loadText3  = function(){
		  $('#innermost_parameter1').load( file3,function(){
		  $('#loadProperty3').trigger('click');
		  });
		};
		
		
		var loadText4  = function(){
		  $('#innermost_topic').load( file4,function(){
		  	$('#loadProperty4').trigger('click');
		  });
		};
		
	
		var loadText5  = function(){
		  $('#innermost_site').load( file5, function(){
		  	 $('#loadProperty5').trigger('click');
		  });
		   
		};
		
		
	$('ul').Treeview({ control: "#treecontrol", speed: 1, collapsed: true });
		var Q1 = "parameter1";
		var Q2 = "source";
		var Q3 = "site";

		var Q11 = "site";
		var Q12 = "sensor";
		var Q13 = "parameter";
		
		var Q21 = "topic";
		var Q22 = "term";
		var Q23 = "parameter";
		
		var Q1s = "li[@id^=parameter1]";
		var Q11s = "li[@id^=site]";
		var Q21s = "li[@id^=topic]";
		
		 
		 var Q31s = "li[@id^=parameter2]";
		 
		var Q31 = "parameter2";
		var Q32 = "source";
		var Q33 = "sensor";
	
	
	var loadQ1=function(){
		$(Q1s).each(function(index){
 	
     	$(this).attr("id",Q1+"_"+index);
     	$(this).one("click",function(event1){
     		 var curId1 = "#"+ this.id;
     	 	var _curId1 = this.id;
      	
		       $.getJSON("send/get_solr_json",
		  	 	{ objectId: this.title ,
		  	      field: this.id },
		  	 		  	   
		  	     function(data){ 
		  	     var title_list1=["Probable MetaData Error"];
		  	     var id_list1=["Probable MetaData Error"];
		  	     
	  	   		$.each(data,function(entryIndex,entry){
	  	  		title_list1[entryIndex] = entry['title'];
	  	  		id_list1[entryIndex] = entry['objectId'];
	  	   		});
	  	   
			    var template1 = [{     
			      tagName : 'ul',   
			      childNodes : []   
			    }];
			    for (i1 in title_list1) { 
			                
			      template1[0].childNodes.push({   
			        tagName : 'li',              
			        innerHTML : title_list1[i1],
			        
			         title : id_list1[i1],
			        
			        id : Q2+i1+"_"+_curId1
			      });
			    }
		    $(curId1).appendDom(template1);
			 
			  $('ul:has(>li[@id$='+_curId1+'])').Treeview({ speed: 1, collapsed: false});
				$('li[@id$='+_curId1+']').each(function(index2){
				
				
			     	$(this).one("click",function(event2){
			     	
			     	if (event2.target == this){
			     	
			     	
			     	 var curId2 = "#"+ this.id;
			     	 var _curId2 = this.id;
			     	
					       $.getJSON("send/get_solr_json",
					  	 { objectId: this.title ,
					  	   field: this.id },
					  	 		  	   
					  	     function(data){ 
					  	     var title_list2=["Probable MetaData Error"];
					  	     var id_list2=["Probable MetaData Error"];
					  	      var q_list2 = ["Probable MetaData Error"];
					  	      
				  	   		$.each(data,function(entryIndex,entry){
				  	  		title_list2[entryIndex] = entry['title'];
				  	  		id_list2[entryIndex] = entry['objectId'];
				  	  		q_list2[entryIndex] = entry['query'];
				  	   		});
				  	    
					    var template2 = [{     
					      tagName : 'ul',   
					      childNodes : []   
					    }];
					  
					    for (i2 in title_list2) { 
					               
					      template2[0].childNodes.push({   
					        tagName : 'li',              
					        innerHTML : q_list2[i2],
					        
					         title : id_list2[i2],
					       
					       id : Q3+i2+"_"+_curId2
					      });
					    }
					    if(curId2 != curId1){
					    	$(curId2).appendDom(template2);
					    	
					    	$('ul:has(>li[@id$='+_curId2+'])').Treeview({ speed: 1, collapsed: false});
					    }
					  
			     	 
					 	 });
					 	 
					 	 }
					 	  event2.stopPropagation();
					  });
					});
			    
		 	 });
		 	 
		 	 event1.stopPropagation();  
		 	 
		  });
		  
		    
		});
	
	
	
	};

var loadQ11 = function(){
$(Q11s).each(function(index){
     	$(this).attr("id",Q11+"_"+index);
     	
     	$(this).one("click",function(event11){
     		 var curId11 = "#"+ this.id;
     	 	var _curId11 = this.id;
     		
		       $.getJSON("send/get_solr_json",
		  	 	{objectId: this.title ,
		  	      field: this.id },
		  	 		  	   
		  	     function(data){ 
		  	     var title_list11=["Probable MetaData Error"];
		  	     var id_list11=["Probable MetaData Error"];
		  	     
	  	   		$.each(data,function(entryIndex,entry){
	  	  		title_list11[entryIndex] = entry['title'];
	  	  		id_list11[entryIndex] = entry['objectId'];
	  	   		});
	  	   
			    var template11 = [{     
			      tagName : 'ul',   
			      childNodes : []   
			    }];
			    for (i11 in title_list11) { 
			                
			      template11[0].childNodes.push({   
			        tagName : 'li',              
			        innerHTML : title_list11[i11],
			        
			         title : id_list11[i11],
			        
			        id : Q12+i11+"_"+_curId11
			      });
			    }
		    $(curId11).appendDom(template11);
		   
		   $('ul:has(>li[@id$='+_curId11+'])').Treeview({ speed: 1, collapsed: false});  
				$('li[@id$='+_curId11+']').each(function(index12){
				
			     	$(this).one("click",function(event12){
			     	
			     	if (event12.target == this){
			     	
			     	
			     	 var curId12 = "#"+ this.id;
			     	 var _curId12 = this.id;
			     	
					       $.getJSON("send/get_solr_json",
					  	 {objectId: this.title ,
					  	   field: this.id },
					  	 		  	   
					  	     function(data){ 
					  	     var title_list12=["Probable MetaData Error"];
					  	     var id_list12=["Probable MetaData Error"];
					  	      var q_list12 = ["Probable MetaData Error"];
				  	   		$.each(data,function(entryIndex,entry){
				  	  		title_list12[entryIndex] = entry['title'];
				  	  		id_list12[entryIndex] = entry['objectId'];
				  	  		 q_list12[entryIndex] = entry['query'];
				  	   		});
				  	    
					    var template12 = [{     
					      tagName : 'ul',   
					      childNodes : []   
					    }];
					  
					    for (i12 in title_list12) { 
					               
					      template12[0].childNodes.push({   
					        tagName : 'li',              
					        innerHTML : q_list12[i12],
					        
					         title : id_list12[i12],
					       
					       id : Q13+i12+"_"+_curId12
					      });
					    }
					    if(curId12 != curId11){
					    	$(curId12).appendDom(template12);
					    	
					    	$('ul:has(>li[@id$='+_curId12+'])').Treeview({ speed: 1, collapsed: false});
					    }
					    event12.stopPropagation();
			     	 
					 	 });
					 	 event12.stopPropagation();
					 	 }
					  });
					});
		    
		 	 });
		 	 
		 	 event11.stopPropagation();  
		  });
		  
		    
		});


};

var loadQ21 = function(){
 		
 	$(Q21s).each(function(index){
     	$(this).attr("id",Q21+"_"+index);
     	$(this).one("click",function(event21){
     		 var curId21 = "#"+ this.id;
     	 	var _curId21 = this.id;
 		       $.getJSON("send/get_solr_json",
		  	 	{objectId: this.title ,
		  	      field: this.id},
		  	 		  	   
		  	     function(data){ 
		  	     var title_list21=["Probable MetaData Error"];
		  	     var id_list21=["Probable MetaData Error"];
		  	     
	  	   		$.each(data,function(entryIndex,entry){
	  	  		title_list21[entryIndex] = entry['title'];
	  	  		id_list21[entryIndex] = entry['objectId'];
	  	   		});
	  	   
			    var template = [{     
			      tagName : 'ul',   
			      childNodes : []   
			    }];
			    for (i21 in title_list21) { 
			                
			      template[0].childNodes.push({   
			        tagName : 'li',              
			        innerHTML : title_list21[i21],
			        
			         title : id_list21[i21],
			        
			        id : Q22+i21+"_"+_curId21
			      });
			    }
		    $(curId21).appendDom(template);
		    $('ul:has(>li[@id$='+_curId21+'])').Treeview({ speed: 1, collapsed: false}); 
  
		    
		   
				$('li[@id$='+_curId21+']').each(function(index22){
				
				
				
			     	$(this).one("click",function(event22){
			     	
			     	if (event22.target == this){
			     	
			     	
			     	 var curId22 = "#"+ this.id;
			     	 var _curId22 = this.id;
			     	
					       $.getJSON("send/get_solr_json",
					  	 { objectId: this.title ,
					  	   field: this.id },
					  	 		  	   
					  	     function(data){ 
					  	     var title_list22=["Probable MetaData Error"];
					  	     var id_list22=["Probable MetaData Error"];
					  	     var q_list22 = ["Probable MetaData Error"];
					  	     
				  	   		$.each(data,function(entryIndex,entry){
				  	  		title_list22[entryIndex] = entry['title'];
				  	  		id_list22[entryIndex] = entry['objectId'];
				  	  		q_list22[entryIndex] = entry['query'];
				  	   		});
				  	    
					    var template2 = [{     
					      tagName : 'ul',   
					      childNodes : []   
					    }];
					  
					    for (i22 in title_list22) { 
					               
					      template2[0].childNodes.push({   
					        tagName : 'li',              
					        innerHTML : q_list22[i22],
					        
					         title : id_list22[i22],
					       
					       id : Q23+i22+"_"+_curId22
					      });
					    }
					    if(curId22 != curId21){
					    	$(curId22).appendDom(template2);
					    	$('ul:has(>li[@id$='+_curId22+'])').Treeview({ speed: 1, collapsed: false});
					    }
					    event22.stopPropagation();
					    
			     	 
					 	 });
					 	 event22.stopPropagation();
					 	 }
					  });
					});
		    
		 	 });
		 	 
		 	 event21.stopPropagation();  
		  });
		  
		    
		});



};

		 
var loadQ31 = function(){
		 
 		$(Q31s).each(function(index){
 	
     	$(this).attr("id",Q31+"_"+index);
     	
     	$(this).one("click",function(event31){
     		 var curId31 = "#"+ this.id;
     	 	var _curId31 = this.id;
 
     	 	
     	
		       $.getJSON("send/get_solr_json",
		  	 	{objectId: this.title ,
		  	      field: this.id },
		  	 		  	   
		  	     function(data){ 
		  	     var title_list31=["Probable MetaData Error"];
		  	     var id_list31=["Probable MetaData Error"];
		  	     
	  	   		$.each(data,function(entryIndex,entry){
	  	  		title_list31[entryIndex] = entry['title'];
	  	  		id_list31[entryIndex] = entry['objectId'];
	  	   		});
	  	   
			    var template = [{     
			      tagName : 'ul',   
			      childNodes : []   
			    }];
			    for (i31 in title_list31) { 
			                
			      template[0].childNodes.push({   
			        tagName : 'li',              
			        innerHTML : title_list31[i31],
			        
			         title : id_list31[i31],
			        
			        id : Q32+i31+"_"+_curId31
			      });
			    }
		    $(curId31).appendDom(template);
		   $('ul:has(>li[@id$='+_curId31+'])').Treeview({ speed: 1, collapsed: false}); 
		   
				$('li[@id$='+_curId31+']').each(function(index32){
				
			     	$(this).one("click",function(event32){
			     	
			     	if (event32.target == this){
			     	
			     	
			     	 var curId32 = "#"+ this.id;
			     	 var _curId32 = this.id;
			     	
					       $.getJSON("send/get_solr_json",
					  	 { objectId: this.title ,
					  	   field: this.id },
					  	 		  	   
					  	     function(data){ 
					  	     var title_list32=["Probable MetaData Error"];
					  	     var id_list32=["Probable MetaData Error"];
					  	     var q_list32 = ["Probable MetaData Error"];
					  	     
				  	   		$.each(data,function(entryIndex,entry){
				  	  		title_list32[entryIndex] = entry['title'];
				  	  		id_list32[entryIndex] = entry['objectId'];
				  	  		q_list32[entryIndex] = entry['query'];
				  	   		});
				  	    
					    var template2 = [{     
					      tagName : 'ul',   
					      childNodes : []   
					    }];
					  
					    for (i32 in title_list32) { 
					               
					      template2[0].childNodes.push({   
					        tagName : 'li',              
					        innerHTML : q_list32[i32],
					        
					         title : id_list32[i32],
					       
					       id : Q33+i32+"_"+_curId32
					      });
					    }
					    if(curId32 != curId31){
					    	$(curId32).appendDom(template2);
					    	$('ul:has(>li[@id$='+_curId32+'])').Treeview({ speed: 1, collapsed: false});
					    }
					    event32.stopPropagation();
			     	 
					 	 });
					 	 event32.stopPropagation();
					 	 }
					  });
					});
		    
		 	 });
		 	 
		 	 event31.stopPropagation();  
		  });
		  
		    
		});
	};
	
	$('#inner_top_parameter1').one('click',loadText3);
	$('#inner_top_site').one('click',loadText5);
	$('#inner_top_topic').one('click',loadText4);
	$('#inner_top_parameter2').one('click',loadText);
	
	
	$('#loadProperty5').one('click',loadQ11);
	
	$('#loadProperty4').one('click',loadQ21);
	$('#loadProperty3').one('click',loadQ1);
	$('#loadProperty2').one('click',loadQ31);
	
	
	 $('#treeLoading').hide();
 
     $('#treeLoading').ajaxStart(function() {
       $(this).show();
     }).ajaxStop(function() {
     
       $(this).hide();
       
     });
	
	});
