$(document).ready(function() {	
	
	//initialize contact form dialog box
	$("#contact-form").dialog({
			autoOpen: false,
			width: 350,
			modal: true,
			buttons: {
				'Send Email': function() {
					 var name = $('input[name=name]');  
					 var email = $('input[name=email]');  
					 var message = $('textarea[name=message]');  
					 
					 //var data = '{"name":"' + name.val() + '","email":"' + email.val() + '","message":"'  + encodeURIComponent(message.val() )+'"}'; 
					 var data = 'name=' + name.val() + '&email=' + email.val() + '&message='  + encodeURIComponent(message.val());
					 
					$.ajax({  
						//this is the php file that processes the data and send mail  
						url: "Lib/contact.php",    
						type: "POST",          
						data: data,       
						cache: false,  
						success: function (html) {} 
					});  
					$(this).dialog('close');
				},
				'Cancel': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				//allFields.val('').removeClass('ui-state-error');
			}
		});
	
	$("#contact").click(function(){
		$('#contact-form').dialog('open');							 
	});

	
	//Use opacity instead of display property so that footer doesn't jump when dlisplay becomes block.
	$(defaultDiv).hide();
	$(defaultDiv).fadeIn(600, function(){
		if($.browser.msie)
			this.style.removeAttribute('filter');
		//$(this).css('filter','alpha(opacity=100)');
	});	
	
	$('.rcol').css("opacity","0");
	$('.rcol').delay(800).animate({opacity: "1"},800, function(){
		if($.browser.msie)
			this.style.removeAttribute('filter'); //needed to render text cleanly in IE								   
	});
	//if(jQuery.browser.msie)
  
	
	var currentDiv = "#" + $(defaultDiv).attr('id');
	var disable = 0; //variable used to disable further clicks while in the process of animating.
	  
	  $('.textLink').click(function(){
		if (!disable == 1) {
			disable = 1;
			newDiv = "#" + $(this).attr("name");
			
			if(currentDiv  != newDiv){
				showContent(currentDiv , newDiv, function(){
					currentDiv = newDiv;
					disable = 0;
				});
			} else {
			      disable = 0;
			}
		}
		return false;
	  });
});

// edited 05-04-11 for efficiency and a bug - A.
function showContent(hideDiv,showDiv,callback){
	
	newHeight = $(showDiv).height();
	minHeight = 429;
	
	$(hideDiv).fadeOut(500, function(){
		$(showDiv).parent().animate({height: newHeight},600);  //gracefully resize parent to fit new content.
		$(showDiv).fadeIn(600, function(){
			if($.browser.msie)
				this.style.removeAttribute('filter'); //needed to render text cleanly in IE						
			//$(this).css('filter','alpha(opacity=100)');		   
			//once animate is completely finished call callback...
			//if (typeof callback == 'function') {	
				callback.call(this);
			//}
		});
	});
}
	  
