$(document).ready(function(){
// Get latest 6 tweets
$("#latestNews").hide();$(".loadingTweets").fadeIn("slow");
$.jTwitter('cdssandwiches', 2, function(data){
	setTimeout(function(){$(".loadingTweets").hide();$("#latestNews").fadeIn("slow");}, 1000);
	$.each(data, function(i, post){
		var tweetDate = post.created_at.split(" ")
		$("#latestNews").append("<li><span class=\"newsDate\">"+tweetDate[0]+" "+tweetDate[1]+" "+tweetDate[2]+" </span>"+ post.text+"</li>");
	});
	$("#latestNews li:odd").addClass("alt");
});
// Center content Featured food boxes opacity effects
$(".mainPromotionText").css({ "opacity":"0.8"});
$(".mainPromotion").css({ "opacity":"0.5"});
// Highlight the first box
$(".mainPromotion", this).eq(0).stop(true).fadeTo("slow", 1);
$(".mainPromotionText", this).eq(0).stop(true).animate({marginBottom: "-30px"}, {speed: 300, easing: "easeOutBack"});
// Homepage center boxes clickable - don't forget to set the url attribute
$("div.clickable").click(function(){
	window.location = $(this).attr("url");
});
// Homepage center boxes hover effect
$(".mainPromotion").hover(function () {
	$(this).stop(true).fadeTo("slow", 1);
	// Reset the first box
	$(".mainPromotionText").eq(0).stop(true).animate({marginBottom: "-85px"}, {speed: 300, easing: "easeOutBack"});
	$(".mainPromotionText", this).stop(true).animate({marginBottom: "-30px"}, {speed: 300, easing: "easeOutBack"});
}, function () {
	$(this).stop(true).fadeTo("slow", 0.5);	
	$(".mainPromotionText", this).stop(true).animate({marginBottom: "-85px"}, {speed: 300, easing: "easeOutBack"});
});
// Contact Form
var email = $("input[name=email]");
var comment = $("textarea[name=comment]");
var emailDefault = "Please enter your email address or phone number";
var commentDefault = "Please enter your comment or message";
email.val(emailDefault);
comment.val(commentDefault);
email.focus(function () {if(email.val() == emailDefault){email.val("");}});
comment.focus(function () {if(comment.val() == commentDefault){comment.val("");}});
email.blur(function () {if(email.val() == ""){email.val(emailDefault);}});
comment.blur(function () {if(comment.val() == ""){comment.val(commentDefault);}});
//if submit button is clicked
$("#submit").click(function () {		
	//Get the data from all the fields
	//Simple validation to make sure user entered something
	//If error found, focus to the text field
	if (email.val()=="" || email.val()==emailDefault) {
		email.focus();
		return false;
	} else email.removeClass("hightlight");
	if (comment.val()=="" || comment.val()==commentDefault) {
		comment.focus();
		return false;
	} else comment.removeClass("hightlight");
	//organize the data properly
	var data = "email=" + email.val() + "&comment="  + encodeURIComponent(comment.val());
	//fadeout the form
	$("#theform").fadeOut("slow");
	//show the loading sign$(".loading").show();
	//start the ajax
	$.ajax({
		//this is the php file that processes the data and send mail
		url: "include/process.php",	
		//GET method is used
		type: "GET",
		//pass the data			
		data: data,		
		//Do not cache the page
		cache: false,
		//success
		success: function (html) {				
			//if process.php returned 1/true (send mail success)
			if (html==1) {					
				//hide the form
				$(".formWrapper").hide();					
				$(".loading").fadeIn("slow");
				//show the success message
				setTimeout(function(){$(".loading").hide();$(".done").stop(true).fadeIn("slow");}, 2000);
				//if process.php returned 0/false (send mail failed)
			} else alert("Sorry, there's been an unexpected error. Please try again later.");				
		}		
	});
	//cancel the submit button default behaviours so we don't get taken off the page
	return false;
});// End Contact Form
// Testimonials start
var currentTestimonial = 0;
var html = "";
$.ajax({
	//this is the php file that processes the data and send mail
	url: "pages/testimonials.html",	
	//GET method is used
	type: "GET",		
	//Do not cache the page
	cache: false,
	//success
	success: function (html) {				
		if (html) {					
			nexttesimonial(html);
		} //fail
		else alert("Sorry, there's been an unexpected error. Please try again later.");				
	}
});// Testimonials end
function nexttesimonial(html) {
	var testimonial = $("blockquote",html).eq(currentTestimonial) ;
	$("#testimonial").empty().html(testimonial);
	$("#nextTestimonial").click(function () {
		if(currentTestimonial < ($("blockquote",html).length - 1))currentTestimonial++;
		else currentTestimonial = 0;
		$("#testimonial").empty().html($("blockquote",html).stop(true).fadeIn("slow").eq(currentTestimonial));
	});
};

});

