var state = 1;

$(document).ready(function(){

var worknum = $('.workentry').length;
var workpages = Math.ceil(worknum/3);

$("#contactme").click(function(){
	$.scrollTo("#contact", 800, {easing:"easeOutBounce"} );
	return false;
});


$("#next").click(function(){
	if(state==workpages){
		return false;
	}
	if(state == 1){
		$("#prev").removeClass("prevdisabled").addClass("prevenabled");
	}
	var theleft = -960*state;
	$("#thework").animate({ marginLeft: theleft}, 1000, "easeInBack");
      
	state = state + 1;

	if (state==workpages){$("#next").removeClass("nextenabled").addClass("nextdisabled");}
	
})

$("#prev").click(function(){
	if(state==1){
		return false;
	}
	if(state == workpages){
		$("#next").removeClass("nextdisabled").addClass("nextenabled");
	}
	var theleft = -960*(state-2);
	$("#thework").animate({ marginLeft: theleft}, 1000, "easeInBack" );
      
	state = state - 1;

	if (state==1){$("#prev").removeClass("prevenabled").addClass("prevdisabled");}
	
})

$('#next').hover(function(){if($(this).hasClass('nextenabled')){$(this).addClass('nexthover');}}, function(){$(this).removeClass('nexthover');})
$('#prev').hover(function(){if($(this).hasClass('prevenabled')){$(this).addClass('prevhover');}}, function(){$(this).removeClass('prevhover');})



$('.entry-title a[href!=""]').prettyPhoto();
$('.entry-title a[href=""]').css({"cursor":"default"});
$('.entry-title a[href=""]').parents(".workentry").css({"cursor":"default"});
$('.workentry').click(function(){
	if($(this).find('a').attr('href')==""){return false;}
	else{$(this).find('a').click();}
})

$('#contactform').submit(function(){
	var thearray = $('#contactform input, #contactform textarea').serializeArray();
	$.post('/wp-content/themes/sandbox/form.php',thearray, function(e){
	
	if(e==1){
		$('#contactform').fadeOut('slow');
		$('#contactmessage').html("Your message has been sent!<br> I will get back to you shortly.");
	}
	else if (e==2){
		//send user to new quote form
		
		//since new quote form isnt ready, we will give a message
		$('#contactform').fadeOut('slow');
		$('#contactmessage').html("Your message has been sent! I will get back to you shortly.");
	}
	else if(e==5){
		//display error message
			$('#contactmessage').html("You must enter your name and contact information.");
			//setTimeout("$('#contactmessage').html('')",1000)
	}
	else{
			$('#contactmessage').html("Your message was not sent, please try again!");
			//setTimeout("$('#contactmessage').html('')",000)
		}
	});

	return false;
});

});