// JavaScript Document

$(document).ready(function() {
  	$('#main').fadeIn('slow');
  
  	$('#add-additional-info').click( function(event){
		event.preventDefault();
		
		$('#additional-info').fadeToggle();
		
		if($('#additional-info').css('opacity') == 0){
			$('#add-additional-info').text('(hide note)');
		}else{
			$('#add-additional-info').text('(personal note)');
		};
	});
	
	/* Tooltip Tipsy */
	$(function() {
		$('.tooltip').tipsy({	
			fade: true,
			gravity: 's',
			offset: 2
		});
	});
	
	$(function() {
		$('.tooltip-sw').tipsy({	
			fade: true, 
			gravity: 'sw',
			offset: 2
		});
	});
	
	$(function() {
		$('.tooltip-se').tipsy({	
			fade: true, 
			gravity: 'se',
			offset: 2
		});
	});
	
	
	/* Form */
	$(function(){
		$('#contact').validate({
			submitHandler: function(form) {
				$(form).ajaxSubmit({
					url: 'bin/process.php',
					success: function() {
						$('#contact').fadeOut(200);
						var wait = setInterval(function() {
							if( !$("#contact").is(":animated") ) {
								clearInterval(wait);
								$('#thanks').fadeIn(500);
							}
						}, 500);
					}
				});
			}
		});         
	});

	/* google analytics */
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-23944601-1']);
	_gaq.push(['_setDomainName', 'none']);
	_gaq.push(['_setAllowLinker', true]);
	_gaq.push(['_trackPageview']);
		
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
});
