$(document).ready(function(){
	setInterval(rotateTestimonials, 8000);
		
	$(".boxes .testimonial").each(function(){
		var newTop = 145 - $(this).height() / 2;
		$(this).css("top", newTop + "px");
	});
		
	var hoverConfig = {    
		over: function(){ $(this).find("> ul").show(); }, 
		timeout: 100,
		sensitivity: 30,
		out: function(){ $(this).find("> ul").hide();  }
	};
	$("#menu li").hoverIntent( hoverConfig );
	
	/*$("#menu li").has("ul").hover(function(){
		$(this).find("> ul").show();
	}, function(){
		$(this).find("> ul").hide();
	});*/
	
	$("#menu li ul li:has(ul)").find("> a").append("<span>&raquo;</span>");
	
	$("#main.secondary h1").append(" &raquo;");
	
	$(".overlay").click(function(){ closeWindow(); }).css("opacity", 0.6);;
	$(".window .close").click(function(){ closeWindow(); });
	
	$("a.email").each(function(){
		var email = $(this).html();
		email = email.replace("-at-", "@");
		$(this).attr("href", "mailto:" + email).html(email);
	});
	
});



	
function rotateTestimonials() {
	var visibleNo = $(".boxes .testimonial:visible").attr("rel");
	if (visibleNo == 3) var nextNo = 1;
		else var nextNo = visibleNo * 1 + 1;
	console.log("Visible: " + visibleNo + "\nNext: " + nextNo);
	$(".testimonial[rel=" + visibleNo + "]").fadeOut("fast", function(){
		$(".testimonial[rel=" + nextNo + "]").fadeIn("fast");
	});
	
}

function openWindow(file) {
	$(".overlay").show();
	$(".loading").show();
	$(".window .inner").load("popups/" + file, function(){
		$(".window .close").show();
		centerWindow();
		$(".loading").hide();
		$(".window").show();
	})
}

function closeWindow() {
	$(".window").hide().find(".inner").html("");
	$(".overlay").hide();
}

function centerWindow() {
	var posX = ($(window).width() / 2) - ($(".window").outerWidth() / 2);
	var posY = ($(window).height() / 2) - ($(".window").outerHeight() / 2);
	$(".window").css("left", posX);
	$(".window").css("top", posY);
}
