//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// function() - the brains
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$(document).ready(function() {
	
	//initialize
	wwibInit();
	
	//event handler for toggling expanded views of articles
	$('p.toggle a, p.togglePanelist a').click(function(){
		
		var thisLink=$(this);
		var slidePanel=thisLink.parent().prev();
		
		while(slidePanel.attr('class')!="moreInfo"){
			slidePanel=slidePanel.prev();
			}//end while
		
		if ($(this).parent().attr('class')=="togglePanelist"){
			
			if(thisLink.html()!="Collapse Panelists"){
		
				slidePanel.slideDown("slow", function(){
					thisLink.html("Collapse Panelists");
					});
				}//end of if
				
			else{
				slidePanel.slideUp("slow", function(){
					thisLink.html("Panelists");
					});
				}
			}//end if
		
		else{
			
			if(thisLink.html()!="Close"){
		
				slidePanel.slideDown("slow", function(){
					thisLink.html("Close");
					});
				}//end of if
				
			else{
				slidePanel.slideUp("slow", function(){
					thisLink.html("Learn More");
					});
				}//end else
			
			}//end else
		
		return false;
		});
		
	//event handler to display popUp Content
	$("a[rel*=popUpDisplay]").click(function(){
		
		//gets content from external file to display in window
		var mylink=$(this).attr('href');
		var toLoad="";
		
		//searches through the 'href' tag to see what information to grab
		for(i=0; i<mylink.length; i++){
			
			if(mylink.charAt(i)!="#"){toLoad=toLoad+mylink.charAt(i);}//end if
				
			else{toLoad=toLoad+" #";}//end else
				
			}//end for loop
			
		var myHeader='<h1>'+$(this).html()+'</h1><div id="popUpContent"><div style="text-align:center;padding:25px;"><img src="lib/src/facebox/loading.gif"></div></div>';
		
		jQuery.facebox(myHeader,'panels');
		
		$('#popUpContent').load(toLoad,'',function(){	
			
			var faceBoxImage=String($('#popUpContent a[rel*=facebox]').html());
		
			if(faceBoxImage!="null"){
				$('#popUpContent').html($('#popUpContent a[rel*=facebox]').html()+$('#popUpContent').html());
				$('#popUpContent a[rel*=facebox]').css("display","none");
				}//end if	
			
			});
		
		return false;
		});
	
	});
	
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// wwibInit() - initializes the site and functions
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var wwibInit = function(){
	
	$("a[rel*=facebox]").facebox();
	$(document).pngFix();
	$('.toggle').css("display","inline");
	$('.togglePanelist').css("display","inline");
	$('.moreInfo').css("display","none");
	}//end wwibInit function

