// JavaScript Document
$(document).ready(function(){
		var _sections = Number($(".featured_item").length/3);
		var _width = Number($("#footer_mask").width()+3);
		var _current = 0;
		_setactive(_current);
		
		$.get("xml/footer.xml", {}, function(xml) {
			$('item', xml).each(function(i){
				itemname = $(this).find('title').text();
			});
		});
		
		$("#right_arrow").click(function(){
			if(_current < _sections-1){
				_current++
				var newWidth = "-="+ Number($("#footer_mask").width()+3) + "px";
				//var newWidth = "-" + $("#footer_mask").offset().left;
				$("#footer").animate({
					left: newWidth
				}, "slow");
				_setactive(_current);
			}
		});
		
		$("#left_arrow").click(function(){
			if(_current > 0){
				_current--;
				var newWidth = "+="+ Number($("#footer_mask").width()+3) + "px";
				if($("#footer").css("left")!="0px"){
					$("#footer").animate({
						left: newWidth
					}, "slow");
				}
				_setactive(_current);
			}
		});
		
		$("#number_ctr a").click(function(){
			var _selected = Number(this.text-1)
			if(_selected != _current){
				var temp_point = _current;
				_current = _selected;
				var dir = -1;
				var newWidth = Number(_width) * Number(_current) * Number(dir);
				$("#footer").animate({
					left: newWidth
				}, "slow");
				$("#number_ctr a").removeClass("active");
				$(this).addClass("active");
			}
		});
	});
	
	function _setactive(n){
		$("#number_ctr a").removeClass("active");
		var _active = $("#number_ctr a:eq("+ n + ")")
		_active.addClass("active");
	}