$(document).ready(function() {
	Rotator.init();
});

window.Rotator = {
	moveDistance : 230,
		
	init : function() {
		$('#rotator_left_button').bind('click', Rotator.left);
		$('#rotator_right_button').bind('click', Rotator.right);
		
		var width = ($('#rotator_holder .icon').length * 115);
		$('#rotator_holder').width(width);
	},
	
	contentWidth : function() {
		return parseInt($('#rotator_holder').width());
	},
	
	left : function() {
		var moved = Rotator.offset();
		var width = Rotator.contentWidth();
				
		if (moved < 0) {
			Rotator.moveContent((moved+Rotator.moveDistance));
		}
	},
	
	moveContent : function(p_left) {
		
		if ((p_left % Rotator.moveDistance) == 0) {
			$('#rotator_holder').animate({
				"left" : (p_left)+"px"
			},1000);
		}
		
	},
	
	offset : function() {
		return parseInt($('#rotator_holder').css('left').substring(0, $('#rotator_holder').css('left').length-2));
	},
	
	right : function() {
		var moved = Rotator.offset();
		var width = Rotator.contentWidth();
		
		if (moved > ($('#rotator_holder').width()*-1)+Rotator.moveDistance) {
			Rotator.moveContent((moved-Rotator.moveDistance));
		}
	}
}