/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item)
 {
    return '<img src="' + item + '" alt="screenshot" />';
};




jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({scroll: 1});
	jQuery("#contact_form").validate({
		rules: {
			"mailer[name]": {
				required: true,
				maxlength: 250
			},
			"mailer[phone]": {
				maxlength: 20,
			},
			"mailer[email]": {
				required: true,
				maxlength: 250,
				email: true
			}, 
			"mailer[message]": {
				required: true,
				maxlength: 1000
			}
		}
	});
	
	var options = { 
	        success:  mailerResponse,
			beforeSubmit: validateForm
	    };
	
	$('#contact_form').submit(function() {
			$(this).ajaxSubmit(options);
		    return false;
	});
	
	function validateForm() { 
	  if ($("#contact_form").valid()) {
		$("#contact_box fieldset").animate({
			opacity: 0.4
		}, 400, "swing", $("#contact_form").append("<span id='spinner'><img src='/images/spinner.gif'/></a></span>"));
	  } else {
		return false;
	  }
	}
		
	function mailerResponse(responseText, statusText)  {
		$("#contact_box fieldset").animate({
			opacity: 1
		}, 400, "swing");
		eval(responseText);
	}
	
	jQuery('ul#portfolio img').each(function() {
		$(this).wrap("<div class='portfolio_image'></div>");
	});
	
	jQuery('ul#portfolio div.portfolio_image').each(function() {
		$(this).hover(
		  function() { $(this).find('img').animate({ opacity: 0.4 }, 400, "swing"); $(this).prepend("<span> </span>"); },
		  function() { $(this).find('img').animate({ opacity: 1 }, 400, "swing"); $(this).find('span').remove(); }
		)
	});
	
});
