jQuery(document).ready(function($) {
	
	//prevent default on links with # as href
	$('body a[href=#]').click(function(event) { event.preventDefault(); });
	
	//fbox
	$('#home-slider .fbox').fancybox({
		overlayColor:'#333',
		onClosed:function() {
			$('#home-slider ul:first').cycle('resume');
		}
	});
	
	//cycle
	$('#home-slider').each(function() {
		
		var wrap = $(this);
		var nav = wrap.find('.slide-nav');
		
		wrap.find('ul:first').cycle({
			fx:'fade',
			speed:1000,
			timeout:5000,
			pager:nav,
			pagerAnchorBuilder:function(i, e) {
				return '<a href="#"></a>';
			}
		});
		
	});
	
	//fbox stop
	$('#home-slider a.fbox').click(function(e) {
		$('#home-slider ul:first').cycle('pause');
		return false;
	});
	
});

//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();
	}
	
	
});
