$(document).ready(function() {
	$("h4.expand").click(expand);
	$("#menu div.submenu + a").mouseover(show).mouseout(hide);
	$("#testimonials > img").click(slide);
	$("#testimonials > a").mouseover(start).mouseout(stop);
	scroll(0);
});

function expand(e) {
	var e = $(e.target).next();
	if(e.is(".expand")) {
		e.removeClass("expand");
	} else {
		e.addClass("expand");
	}
}

function show(e) {
	var e = $(e.target).prev();
	e.addClass("active");
}

function hide(e) {
	var e = $(e.target).prev();
	e.removeClass("active");
}

function slide(e) {
	var e = $(e.target).parent();
	if(e.is(".open")) {
		e.removeClass("open");
		e.animate({right: -320}, 500, "swing");
	} else {
		e.addClass("open");
		e.animate({right: 0}, 500, "swing");
	}
}

var interval;

function start(e) {
	clearInterval(interval);
	interval = setInterval(function() { scroll($(e.target).is(".down") ? 1 : -1) }, 20);
}

function stop() {
	clearInterval(interval);
}

function scroll(dir) {
	var e = $("#scroller");
	var top = e.scrollTop();
	top += dir * 10;
	e.scrollTop(top);
	$("#testimonials a.up").css("display", top > 0 ? "block" : "none");
	$("#testimonials a.down").css("display", top < e[0].scrollHeight - e.height() ? "block" : "none");
}

function comment() {
	$("#comment").css("display", $("#comment").css("display") == "block" ? "none" : "block");
}
