

//Hides all the content except the greeting and sets the height of all columns to col-3

function hideContent() {
	
	
	if($('home')){
					
		$$('#greeting', '#nav', '#col-2', '#col-3', '#col-1-footer', '#col-2-footer', '#col-3-footer').invoke('hide');
					
	}
	
	// works in Firefox and IE.
	getColHeight() 
	
	// Safari needs to wait until the page loads to get the correct height for some reason
	Event.observe(window, 'load', function() {
  		getColHeight()
	});
	
	loadHome()
	
	// if($('headline')){
	// 				
	// 	$('headline').setStyle({
	// 		position: 'absolute',
	// 		left: '0px',
	// 		top: '138px'
	// 	});
	// 	
	// 	$('headline').update('<h1><a href="#">direct. effective. communication.</a></h1>');
	// 			
	// 	Event.observe('headline', 'click', removeHeadline);
	// 			
	// }
	
}



//begin headline function

function loadHome() {
		

					
			
					
					new Effect.Parallel([ 
					new Effect.Appear('greeting', { sync: true }),
					new Effect.Appear('nav', { sync: true }), 
					new Effect.Appear('col-1-footer', { sync: true })

						], { duration: .5, afterFinish: function() {
												  
							new Effect.Parallel([ 
							 
							new Effect.Appear('col-2', { sync: true }),
							
							new Effect.Appear('col-2-footer', { sync: true })

								], { duration: .5, afterFinish: function() {			  
											  
									new Effect.Parallel([ 
									new Effect.Appear('col-3', { sync: true }), 
									new Effect.Appear('col-3-footer', { sync: true })

										], { duration: .5 }
									);
								}}
							);
						}}	  					  				  
					);
	


					
					return false;

}

// end


function removeHeadline() {
		
			if ($(this).hasClassName('loaded')) {
				
				return false;
				
				} 
				
				else {
					
					new Effect.Fade('headline', { duration: 1, afterFinish: function() { 
					
					new Effect.Parallel([ 
					new Effect.Appear('greeting', { sync: true }),
					new Effect.Appear('nav', { sync: true }), 
					new Effect.Appear('col-1-footer', { sync: true })

						], { duration: .5, afterFinish: function() {
												  
							new Effect.Parallel([ 
							 
							new Effect.Appear('col-2', { sync: true }),
							
							new Effect.Appear('col-2-footer', { sync: true })

								], { duration: .5, afterFinish: function() {			  
											  
									new Effect.Parallel([ 
									new Effect.Appear('col-3', { sync: true }), 
									new Effect.Appear('col-3-footer', { sync: true })

										], { duration: .5 }
									);
								}}
							);
						}}	  					  				  
					);
					}});

					$(this).toggleClassName('loaded');
					
					return false;
			}
		}

// end




function getColHeight() {
	
	$$('.col').invoke('setStyle', { height: '' });
	
	var colHeight = $('col-3').getHeight();
	
	$$('.col').invoke('setStyle', { height: colHeight+'px' }) 

}


//Determine the browser time and display greeting accordingly. Then blink for attention.

function greeting() {
	message = "nothing";
	today = new Date();
	currentHour = today.getHours();
	
	if (currentHour < 12) { 
		message = "good morning"; 
	}
	if (currentHour >= 12 && currentHour < 17) {
		message = "good afternoon";
	} 
	if (currentHour >= 17) {
		message = "good evening";
	} 
	
	$('greeting').update(message);
}



//Retrieves content based on url passed to it from the rules below

function getContent(col2, col3) {
	
	element.onclick = function(){
		
		if ($(this).hasClassName('current')) {
			
			return false;
			
			} 
			
			else {
				
				if($('slideshow')){
					
					$('slideshow').remove();
					
					}
				
				new Effect.Opacity('footer', { duration: .5, to: 0 });
				new Effect.Opacity('content', { duration: .5, to: 0, afterFinish: function() {
																												  																		  																						 
					new Ajax.Updater('content', col3, { 
										  
						method:'get',
						evalScripts: true,
						
						onComplete:function(){ 
						
							getColHeight();
							new Effect.Opacity('content', { duration: .5, to: 1 });
							
							if($('contact')){
					
								loadAction();
					
							}
							
						}
						
					});	
					
					
				}});
	
				
				new Effect.Opacity('container', { duration: .5, to: 0, afterFinish: function() {
																									 
					new Ajax.Updater('container', col2, { 
										  
						method:'get',
						
						onComplete:function(){ 
						
							getColHeight();
							new Effect.Opacity('container', { duration: .5, to: 1 });
							new Effect.Opacity('footer', { duration: .5, to: 1 });
							
							checkForLinks();
						}
						
					});
					
					
					
				}});
				
				
				removeClassCurrent();
				$(this).toggleClassName('current');
				return false;
				
		};
	}
}


// this removes the class 'current' from all other links when a link is clicked so we don't end up with 2 current links

function removeClassCurrent() {
	$$('#nav a.current').invoke('removeClassName','current');
}



//Retrieves content based on url passed to it from the rules below
// this version just removes the slideshow rather than trying to fade it which clearly doesn't work

function getProjects(col3) {
				
	$('slideshow').remove();																	  
																						 
	new Ajax.Updater('content', col3, { 
							  
		method:'get',
		evalScripts: true
	});
	
	return false;
	
}



	

	
	
	
	
	
	
	
// The following uses behaviour.js
	
// Get page based on link clicked and pass it to getContent(url)

var myrules = {

	'li#nav-home a' : function(element){ 
	var col2 = '/includes/content/home-col-2.php';
	var col3 = '/includes/content/home-col-3.php';
	getContent(col2, col3)
	},

	'li#nav-process a' : function(element){ 
	var col2 = '/includes/content/process-col-2.php';
	var col3 = '/includes/content/process-col-3.php';
	getContent(col2, col3)
	},
	
	'li#nav-services a' : function(element){ 
	var col2 = '/includes/content/services-col-2.php';
	var col3 = '/includes/content/services-col-3.php';
	getContent(col2, col3)
	},
	
	'li#nav-selected-projects a' : function(element){ 
	var col2 = '/includes/content/projects-col-2.php';
	var col3 = '/includes/content/projects-col-3.php';
	getContent(col2, col3)
	},
	
	'li#nav-about a' : function(element){ 
	var col2 = '/includes/content/about-col-2.php';
	var col3 = '/includes/content/about-col-3.php';
	getContent(col2, col3)
	},
	
	'li#nav-client a' : function(element){ 
	var col2 = '/includes/content/client-col-2.php';
	var col3 = '/includes/content/client-col-3.php';
	getContent(col2, col3)
	},
	
	'li#nav-contact a' : function(element){ 
	var col2 = '/includes/content/contact-col-2.php';
	var col3 = '/includes/content/contact-col-3.php';
	getContent(col2, col3)
	}
	
}


// Try using if ($('whatever'))



//*****************************************************************
//-----------------------------------------------------------------





function checkForLinks() {
	
	
	if($('emailus')){
					
	
		$('emailus').observe('click', function(event) {
			
			if (this.hasClassName('current')) {
			
				Event.stop(event);
			
			} 
			
			else {
				
				var col2 = '/includes/content/contact-col-2.php';
				var col3 = '/includes/content/contact-col-3.php';
				getContentAlt(col2, col3);
				
				removeClassCurrent();
				this.toggleClassName('current');
				Event.stop(event);
				
			}
		  
							
		});
		  //end $('emailus').observe
		
		
		/* $('emailus').onclick = function() {return false;}; */
		
	};
	//end if emailus
	
	
	
	
	if($('nav-integrate')){
					
	
		$('nav-integrate').observe('click', function(event) {
			
			if (this.hasClassName('current')) {
			
				Event.stop(event);
			
			} 
			
			else {
				
				var col2 = '/includes/content/integrate-col-2.php';
				var col3 = '/includes/content/integrate-col-3.php';
				getContentAlt(col2, col3);
				
				removeClassCurrent();
				this.toggleClassName('current');
				Event.stop(event);
				
			}
		  
							
		});
		  //end $('emailus').observe
		
		
		/* $('emailus').onclick = function() {return false;}; */
		
	}
	//end if emailus

}







function getContentAlt(col2, col3) {
	
				
				if($('slideshow')){
					
					$('slideshow').remove();
					
					}
				
				new Effect.Opacity('footer', { duration: .5, to: 0 });
				new Effect.Opacity('content', { duration: .5, to: 0, afterFinish: function() {
																												  																		  																						 
					new Ajax.Updater('content', col3, { 
										  
						method:'get',
						evalScripts: true,
						
						onComplete:function(){ 
						
							getColHeight();
							new Effect.Opacity('content', { duration: .5, to: 1 });
							
							if($('contact')){
					
								loadAction();
					
							}
							
						}
						
					});	
					
					
				}});
	
				
				new Effect.Opacity('container', { duration: .5, to: 0, afterFinish: function() {
																									 
					new Ajax.Updater('container', col2, { 
										  
						method:'get',
						
						onComplete:function(){ 
						
							getColHeight();
							new Effect.Opacity('container', { duration: .5, to: 1 });
							new Effect.Opacity('footer', { duration: .5, to: 1 });
							
							checkForLinks();
						}
						
					});
					
					
					
				}});
				
				
				//removeClassCurrent();
				//$(this).toggleClassName('current');
				//return false;
				


}



	
	document.observe("dom:loaded", checkForLinks);
	
	Behaviour.register(myrules);
	
	// load a few functions quickly.
	FastInit.addOnLoad(hideContent, greeting);
	
	
	
