jQuery(document).ready(function($) {

	$('.columns').quickColumns(); // adds a 2 column layout into the page. Make sure items have alternating .odd || .even classes on them!
	$('#gallery').simpleGallery(); // simple slideshow plugin
	$('#newsletter').autoForm5(); // form validation, html5 fallbacks and style classes
	
	$('.no-csstransitions #fancy a').hover(function(){
		$(this).animate({'top': "-=20px",'left':'0'}, 200);
	},
	function(){
		$(this).animate({'top': '+=20px','left':'0'}, 200);
	});
	
	// very basic image protection (prevent right click)
	$('#gallery img, #blocker').mousedown(function(event){
	  if (event.which==3) {
	    alert('This image is copyrighted');
	  }
	});
	$('#gallery img, #blocker').bind('dragstart',function(event){
	    alert('This image is copyrighted');
	});
	
	
	// show newsletter form
	$('a.newsletter').click(function(event){
		event.preventDefault();
		if ($.browser.msie) {
			$('#overlay').show();
		}
		else {
			$('#overlay').fadeIn(400);
		}
	});
	
	$('#newsletter').click(function(event){
		event.stopPropagation();
	});
	$('#overlay, #overlay .close').click(function(event){
		if ($.browser.msie) {
			$('#overlay').hide();
		}
		else {
			$('#overlay').fadeOut(400);
		}
	});
	
	
	// ===========================
	// = Contact Form Validation =
	// ===========================
	$('#contact-form').submit(function(e) {
		
		var fields = $('[required=""]', $(this)),
			isValid = true;
			
			fields.each(function() {
				
				var fieldPair = $(this).closest('.row').find('label,:input');
				
				if ( $(this).val() == "" || $(this).val() == $(this).attr('data-error') ) { 
					fieldPair.addClass('af5-error');
					$(this).val($(this).attr('data-error')).bind('focus keydown', function(e) {
						if ( $(this).val() == $(this).attr('data-error') ) { 
							$(this).val("");
						}
					}).bind('blur', function(e) {
						if ( $(this).val() == "" ) { 
							$(this).val($(this).attr('data-error')); 
						} else {
							fieldPair.removeClass('af5-error');
						}
					});
					
					isValid = false;
				} else {
					fieldPair.removeClass('af5-error');
				}
				
			});
		
		if ( !isValid ) { 
			e.preventDefault(); 
		}

	});
		
		
//		event.preventDefault();
	// });
	
	// IE fixes
	if ($.browser.msie) {
		// ad header background triangle
		$('<div id="ie-header-bg" />').prependTo('body > .container');
	}
	
	$('#tweets').jtwt({image_size : 0, count : 5, username: 'google', convert_links : 1, loader_text : 'loading new tweets...'}); 
	
});

