$(function() {
	// login form
	$(".menu a.login").click(function(){
		var positionDelta = $(".menu a.login").index($(this)) == 0 ? 27 : -113;
		$("form.login").slideToggle("fast").css("top", $(this).position().top + positionDelta);
	});
	$("form.login .minimize").click(function(){$("form.login").slideUp("fast")});
	
	// rotator
	$(".rotator .selector a:not(.left, .right)").click(function() { 
		limit = 5;
		total = $(this).parent().find("a:not(.left, .right)").size();
		current = $(this).parent().find("a:not(.left, .right)").index($(this));
		mid = parseInt(limit/2);
		var left = current - mid;
		var right = current + mid;
		if (left < 0) {
			right = right - left;
			left = 0;
		}
		if (right > total - 1) {
			left = left + (total - right - 1);
			right = total;
		}
		$(this).parent().find("a:not(.left, .right)").show().filter(":lt("+left+")").hide().end().filter(":gt("+right+")").hide();
		$(this).parent().find("a").removeClass("active").end().end().addClass("active").parent().parent().find("li").hide().eq(current).show();
		});
	$(".rotator .selector a.left").click(function() { 
		current = $(this).parent().find("a:not(.left, .right)").index($(this).parent().find("a.active"));
		if (current > 0) { $(this).parent().find("a:not(.left, .right)").eq(current-1).trigger("click"); }
		});
	$(".rotator .selector a.right").click(function() { $(this).parent().find("a:not(.left, .right)").eq($(this).parent().find("a:not(.left, .right)").index($(this).parent().find("a.active"))+1).trigger("click"); });
	$(".rotator .selector").each(function(){ $(this).find("a:not(.left, .right):first").trigger("click"); })
	
	// shahdowbox
	Shadowbox.init({
		animSequence:'sync',
		overlayColor: '#ccc',
		overlayOpacity: 0.5,
		continuous: true,
		initialHeight: 135,
		initialWidth: 180
	});
});
