$(document).ready(function(){

	$("#contact_form").validateMyForm({ form:'#contact_form', showAsterisk:false, notificationText:'required', emailNotificationText:'invalid email', scrollUp: false });
	
	$('.home_proj a').hover(function(){
		$(this).find('span').animate({
		    width: '+=10px'
		}, 200, "easeOutCirc");		
	},
	function(){
		$(this).find('span').animate({
		    width: '-=10px'
		}, 200, "easeOutCirc");	
	});
	
	$('#contact_form label').click(function(){
		$(this).hide();
		$(this).next('input').focus();
		$(this).next('textarea').focus();
	});
	
	$('#contact_form input').focus(function(){
		if($(this).val() == '')
		{
			$(this).prev('label').fadeTo('slow',0.3);
		}
	});
	
	$('#contact_form input').keyup(function(){
		if($(this).val() != '')
		{
			$(this).prev('label').fadeOut('fast');
		} else {
			$(this).prev('label').fadeIn('fast');
		}
	});
	
	$('#contact_form input').blur(function(){
		if($(this).val() == '') {
			$(this).prev('label').fadeTo('slow',1);
		}
	});
	
	$('#contact_form textarea').focus(function(){
		if($(this).val() == '')
		{
			$(this).prev('label').fadeTo('slow',0.3);
		}
	});
	
	$('#contact_form textarea').keyup(function(){
		if($(this).val() != '')
		{
			$(this).prev('label').fadeOut('fast');
		} else {
			$(this).prev('label').fadeIn('fast');
		}
	});
	
	$('#contact_form textarea').blur(function(){
		if($(this).val() == '') {
			$(this).prev('label').fadeTo('slow',1);
		}
	});
	
	$('a[href^="#"]').bind('click.smoothscroll',function (e) {
	    e.preventDefault();
	 
	    var target = this.hash,
	        $target = $(target);
	 
	    $('html, body').stop().animate({
	        'scrollTop': $target.offset().top
	    }, 500, 'swing', function () {
	        window.location.hash = target;
	    });
	});
	
	//Function to perform on touchstart (hiding footer bar)	
	function fadeFooterOut() {
		$('#to_top').fadeOut(300);
	}
	
	//Function to perform on touchend (hiding footer bar)	
	function fadeFooterIn() {
		if(window.pageYOffset != 0) {
			//$('#to_top').css('top',(window.pageYOffset + window.innerHeight - 48) + 'px');
			$('#to_top').fadeIn(300);
		}
	}
	
	if(window.pageYOffset == 0) {
		fadeFooterOut();
	}
	
	//On scroll, hide footer bar, then fade it back in
	//Used for hiding and fading in when clock touched
	//And fading in after touchmove
	window.onscroll = function() {
		//fadeFooterOut();
		//fadeFooterIn();
		if(window.pageYOffset < 100) {
			fadeFooterOut();
		} else {
			fadeFooterIn();
		}
	};
});

$(function() { $(".lavalamp").lavaLamp({ fx: "easeOutBack", speed: 500 })});
	
//To reset the placement of the arrow on the inside pages after page load
setTimeout("triggerHover()",100);
function triggerHover() {
	$('li.current').mouseenter().mouseleave();
}
