jQuery(document).ready(function($) {
	
	//prevent default on links with # as href
	$('body a[href=#]').click(function(event) { event.preventDefault(); });
	
});

//Forms
jQuery(document).ready(function($) {
		
	//auto clear forms and validate
	$('form').each(function() {
		var form = $(this);
		form.find('input[type=text], input[type=password], textarea').each(function() {
			var d = $(this).val();      
			if(d != '') $(this).addClass('v-default');  
			$(this).focus(function() { if($(this).val() == d) { $(this).val(''); $(this).removeClass('v-default'); } });
			$(this).blur(function() { if($(this).val() == "") { $(this).val(d); $(this).addClass('v-default'); } });
		});
		
		form.submit(function(e) {
			var errors = false, pattern= /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
			
			form.find('.v-email, .v-noempty').each(function() {
				
				if($(this).hasClass('v-email')) {
					if($(this).hasClass('v-default') || !pattern.test($(this).val())) {
						errors = true;
						setError($(this));
					}
				}
				
				if($(this).hasClass('v-noempty')) {
					if($(this).hasClass('v-default') || $(this).val() == "") {
						errors = true;
						setError($(this));
					}
				}
				
			});
			
			if(!errors)
				return true;
			else
				return false;
			
		});
		
	});
	
	function setError(o) {
		o.fadeOut().fadeIn();
	}
	
	
});
	
//Image Fade

		jQuery(document).ready(function($) {
			$("img.a").hover(
			function() {
				$(this).stop().animate({"opacity": "0"}, "fast");
			},
			
			function() {
				$(this).stop().animate({"opacity": "1"}, "fast");
			});
		 
		});
		
		/* 
		
		===== @CSS ==============================
		
		div.fade { position: relative; }
		img.a { position: absolute; left: 0; top: 0; z-index: 10; }
		img.b { position: relative; left: 0; top: 0; }
		
		===== @HTML =============================
		
		<div class="fade">
			<img src="####" class="a" />
			<img src="####_hover" class="b" />
		</div>
		
		*/
