/* NON-BLOCKING LOAD OF JQUERY FROM GOOGLE CDN */
//google.load("jquery", '1.3.2');

var contact_is_sliding = false;			/* is the contact tab currently moving? */


/* RUN PAGE INITIALIZATION. WAIT FOR DOM TO COMPLETE LOADING */
// google.setOnLoadCallback(function() {
	
	$(function() {             

		$.address.change(function(e) {
			handleAddressChange(e);
		});
	    
	
	   setupBio(); 
  	
	   setupPress(); 
	
	   closeButton();

	   //setupContactGlobal();   
	
	}); 

//}); /* close google callback */          


//configuration for hoverIntent.js plugin
var config = {
	sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
    interval: 50, // number = milliseconds for onMouseOver polling interval    
    over: fadeInPointer, // function = onMouseOver callback (REQUIRED)    
    timeout: 100, // number = milliseconds delay before onMouseOut    
    out: fadeOutPointer // function = onMouseOut callback (REQUIRED)
}

/* BIOS SETUP */
function setupBio(){
	$('#headshots div').hoverIntent(config);  //from  hoverIntent.js
	
	
	$('#headshots div').click(function(){ 
		
		$.address.value($(this).find("a").attr('rel').substr(0));
		
	   	hideContact();

	}); 
 
}  


// PRESS SETUP 
function setupPress(){
	$('.read').click(function(){
		
		$.address.value($(this).find("a").attr('rel').substr(0));
		
	   	hideContact();
		  
		  //$.address.title("Core Industries | "+e.path.substr(1)); // grab title from img alt tag
		
 
		
	});
}
 
//handles both bios and press 
function handleAddressChange(e){
	
	if($.address.value().indexOf('bio') > 0){      //if the url path string bio is in the path
		revealBio(e.path.substr(1,2)); 
		 //find the first 2 letter of the path
	}
	else if($.address.value().indexOf('press') > 0){ 
	   	
		openPress(e.path.substr(1,3));      
		
		$('#bios .b1 .ind_bio').addClass('revealed');  //reveal the first bio since there is no bio selected  
		$('#headshots .b1 img.hs_hover').addClass('revealed');
	}  
	
	else{
		$('#bios .b1 .ind_bio').addClass('revealed');  //reveal the first bio since there is no bio selected  
		$('#headshots .b1 img.hs_hover').addClass('revealed'); 
	} 
	
	if($.address.value().indexOf('contact') > 0){ //after everything loads check for contact 
	   	revealContact();
	}
	 
	
}



// BIO EVENTS 
function revealBio(p){ 
	
	hideBio(); 
    closePress();   //close any open press if bio is selected

	$('#bios .'+p+' .ind_bio').addClass('revealed');

	$('#headshots .'+p+' img.hs_hover').addClass('revealed');   
	$('#headshots .'+p+' img.notch').addClass('hidden');
 

} 

function hideBio(){ 
	  $('#bios .revealed').removeClass('revealed');
	  $('#headshots .revealed').removeClass('revealed');
	  $('#headshots .hidden').removeClass('hidden');  
	
}    

//these are called in the config for hoverIntent
function fadeInPointer(){
	 $('#headshots .'+$(this).attr("class")+' img.notch').animate( {opacity: 0}, 200); 
  	 $('#headshots .'+$(this).attr("class")+' img.hs_hover').animate( {opacity: 1}, 200);
}

function fadeOutPointer(){
	 $('#headshots .'+$(this).attr("class")+' img.notch').animate( {opacity: 1}, 200); 
     $('#headshots .'+$(this).attr("class")+' img.hs_hover').animate( {opacity: 0}, 200);
}    


 


// PRESS EVENTS 
function openPress(press){
            		
	  closePress();
	  
	  $('#press #'+press+' .article').slideDown('fast');
	  $.scrollTo( '#'+press, 700);
	  
	  $('#press #'+press+' .article').animate( {opacity: 1}, 200);
	  
	  $('#press #'+press+' .article').addClass('selected');
	  
	  $('#press .read').animate( {opacity: 1}, 50);     
	  $('#press #'+press+' .read').animate( {opacity: 0}, 200);
	  
	  
	  $('#press #'+press+' .close').animate( {opacity: 1}, 200);
	  
	  
	  $('#press .hidden').removeClass('hidden');
	  
	  return false;      
}
               
   
function closeButton(){ 
	
  	$('.article .close').click(function(){
	
	      closePress();
		  $('#press #'+$(this).parent().parent().attr('id')+' .read').animate( {opacity: 1}, 200);
		  $.scrollTo( '#press #'+$(this).parent().parent().attr('id'), 500) ;
		
		  $.address.value('/');
		
		  return false;
	
	});  
 
} 

function closePress(){  
	
		$('#press .selected').addClass('hidden');
		$('#press .selected').removeClass('selected');
		$('.hidden').slideUp('fast');
} 

  


