$(document).ready(function(){
	
	setTimeout('portfolio_scroller(1)',5000);
	
	$("a.s-next").click(function(){
		$(".scroller").scrollTo( '+=565px', { duration:200, axis:'x',easing:'swing'});
		return false;
	})
	
	$("a.s-prev").click(function(){
		$(".scroller").scrollTo( '-=565px', { duration:200, axis:'x',easing:'swing' });
		return false;
	})
	
	$("a.testimonial").click(function(){
		$.fancybox(
		$(this).attr('rel'),
		{
        	'autoDimensions'	: false,
        	'width'				: 400,
			'height'        	: 'auto',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		}
	);
	return false;

	})	
	
	$(".fancybox").fancybox();
	
$("#getintouch").click(function(){
	$("#getintouch").val('Please Wait...');
	$("#getintouch").attr('disabled','true');
	
	$.ajax({
		type: 'POST', //We're telling jQuery we're doing a POST.
		url: '/',
		data: $("#frm_getintouch").serialize(), // This encapsulates all the form data and passes it as FORM_DATA.
		success: function(data){
			if (data.search(/error/) >= 0) // Check to see if the word 'error' occurs in the returned data.
			{
			var $data = $(data);

			var err = "There were errors found in your entry:\n";

			$data.find('li').each(function() { // Check each instance of the <li> in the returned data and iterate through.
				err+= "\t" + $(this).text() + "\n";
			});
			alert(err); // Alert the Error which will detail all the values of the <li> (i.e the errors!)
			
			$("#getintouch").val('Send');
			$("#getintouch").attr('disabled','');
			
			}
			else
			{
			location.replace( $("#RET").val() ); // There was no error, so we're going to redirect the user to the next step now (set in the RETURN_URL form field)
			}
		}
	})
	return false; // Make sure we return false.
})

$("#post_comment").click(function(){
	$("#comment").slideToggle("slow");
	return false;
})
	
})

function portfolio_scroller(num){
	if (num==6){
		$("#portfolio-scroller").scrollTo( '-=1590px', { duration:500, axis:'x',easing:'swing'});
		num=1;
		}
		else
		{
		$("#portfolio-scroller").scrollTo( '+=265px', { duration:500, axis:'x',easing:'swing'});
		num=num+1;
		}
	setTimeout('portfolio_scroller('+num+')',5000);
}
