﻿$(function(){

	// Accordion
	$("#accordion").accordion({ header: "h3" });
	
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
});
	
$(function() {
	$('a.thumb').lightBox();
});

$(document).ready(function(){
	$('.thumbEnlarge').hover (
		function()
		{
			this.src = this.src.replace("magnify","magnify-hover");
		},
		function()
		{
			this.src = this.src.replace("magnify-hover","magnify");
		}
	);
});

$(document).ready(function() {

	$('#txtName').toggleVal();
	$('#txtEmail').toggleVal();
	$('#txtMessage').toggleVal();
	

	//contact form validation and processing	
  	$('input#btnSubmit').click(function(e){
  	
  		// prevents a second postback to the page and keeps the form values from showing in the url
  		e.preventDefault();
  		
   		// validate and process form
   		
   		var error = false;
   		var name = $('input#txtName').val();
		var email = $('input#txtEmail').val();
		var re = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
		var message = $('textarea#txtMessage').val();
		
   		if (name == '' || name == 'Name'){
   			var error = true;
   			$('label#errorName').fadeIn(500);
   		}
   		else{
   			$('label#errorName').fadeOut(100);
   		}
   		
   		if (email == '' || email == 'Email' || !email.match(re)){
   			var error = true;
   			$('label#errorEmail').fadeIn(500);
   		}
   		else{
   			$('label#errorEmail').fadeOut(100);
   		}
   		
   		if (message == '' || message == 'Message'){
   			var error = true;
   			$('label#errorMessage').fadeIn(500);
   		}
   		else{
   			$('label#errorMessage').fadeOut(100);
   		}
   		
   		if(error == false){
   			//hide the submit button to avoid spamming
   			//change the button to Sending...
   			$('#submit').fadeOut(10);
   			$('#sending').fadeIn(500);
   			//hide any previous error or success messages
   			$('#msgSuccess').fadeOut(10);
   			$('#msgFailed').fadeOut(10);
   			
			$.post('processing.aspx', $('#formContact').serialize(),function(result){
   				if(result == 'sent'){
   					// removed failed message if send previously failed
   					$('#msgFailed').fadeOut(10);
   					// if the email is sent show the send button and remove the sending button
   					$('#submit').fadeIn(500);
   					$('#sending').fadeOut(100);
   					// and show the msgSuccess div with fadeIn
   					$('#msgSuccess').fadeIn(500);
   					// and reset the inputs and text area to default values
   					$('#txtName').attr({'value' : 'Name'});
					$('#txtEmail').attr({'value' : 'Email'});
					$('#txtMessage').val('Message');
   				}
   				else{
   					// show the failed div
   					$('#msgFailed').fadeIn(500);
   					// hide sending and show the send button
   		   			$('#sending').fadeOut(100);
   					$('#submit').fadeIn(500);	   			
   				}   				
   			});
		}	   		
  	});
});


