
var businessCardWidth = 250;
var animationSpeed = 350;
var scrollers = {};

$(document).ready(function() {
	
	$("#contacts_city_select")
		.change(function() {
			$("#contacts .contacts_location")
				.hide()
				.filter(".city_" + this.value.toString())
					.show()
		})
		.change()
	
	var scrollerIndex = 0;
	$(".scrollerObject").each(function() {
		var scroller = $(this).find(".scroller");
		var scrollerId = "scroller-" + (++scrollerIndex);
		$(scroller).attr("id", scrollerId);
		scrollers[scrollerId] = {
			count: $(scroller).find(".scrollItem").length,
			position: 1,
			leftArrow: $(this).find(".arrow.left"),
			rightArrow: $(this).find(".arrow.right")
		};
		showOrHideArrows(scrollerId);
	});
	
	$(".scrollerObject .arrow.left").click(function() {
		var scroller = $(this).closest(".scrollerObject").find(".scroller");
		var scrollerId = scroller.attr("id");
		if (scrollers[scrollerId].position <= 1)
			return false;
		scrollers[scrollerId].position--;
		showOrHideArrows(scrollerId);
		scroller.animate({ marginLeft: '+=' + businessCardWidth }, animationSpeed, "easeInOutExpo");
	});
	
	$(".scrollerObject .arrow.right").click(function() {
		var scroller = $(this).closest(".scrollerObject").find(".scroller");
		var scrollerId = scroller.attr("id");
		if (scrollers[scrollerId].position >= scrollers[scrollerId].count)
			return false;
		scrollers[scrollerId].position++;
		showOrHideArrows(scrollerId);
		scroller.animate({ marginLeft: '-=' + businessCardWidth }, animationSpeed, "easeInOutExpo");
	});
	
});

function showOrHideArrows(scrollerId) {
	if (scrollers[scrollerId].position <= 1)
		scrollers[scrollerId].leftArrow.addClass("disabled");
	else
		scrollers[scrollerId].leftArrow.removeClass("disabled");
	
	if (scrollers[scrollerId].position >= scrollers[scrollerId].count)
		scrollers[scrollerId].rightArrow.addClass("disabled");
	else
		scrollers[scrollerId].rightArrow.removeClass("disabled");
}

