jQuery.fn.fadeToggle = function(speed, easing, callback) { 
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
}; 

$(document).ready(function(){
	$('#homeB a')
		.colorbox({opacity:0.90});
		
	$('#homeB p')
		.fadeTo(1,0.3)
		.hover(
			function(){ $(this).fadeTo(400,1.0) },
			function(){ $(this).fadeTo(500,0.3) }
		);

	$("a[rel^='cb']")
		.colorbox({opacity:0.90});

	function errorMessage($text){
		$('#msg2').empty().append($text).fadeIn('slow');
	}

	$().bind('cbox_complete',function(){
		if( $('#mailform').length ){  
			$('#about a.contact')
				.click(function(){$('#mailform').fadeToggle();});

			$('img.close')
				.click(function(){$('#mailform').fadeOut();});

			$('#result').empty().append('<p id="msg2"></p>');
			$('#msg2').hide();

			$('#reset').click(function(){$('#msg2').fadeOut();});

			$('#mailform form').ajaxForm(function(data){
				$('#msg2').hide();

				if(data==1){
					$('#mailform form').empty().append('<div id="msg1">Your message is sent! Thank you!</div>')
					$('#msg1').hide().fadeIn('slow');

				}else if(data==2){
					errorMessage('Your email failed. Please try again later.');

				}else if(data==3){
					errorMessage('Please enter a name.');

				}else if(data==4){
					errorMessage('Please enter a valid email.');

				}else if(data==5){
					errorMessage('Please enter message.');
				}
			});
		}
	});
});
