var SM = {
	
	
	init: function() {
		SM.categories.init();
		SM.navigation.init();
	},
	
	
	categories: {
		
		_currentPost: '',
		_current: 'all-sections',
		
		init: function() {
			cat = this;
			
			cat._current = cat.getActive();
			cat.setActive(cat._current);
			cat.highlight(cat._current);
			
			if(cat._currentPost !== '') {
				cat.setActivePost(cat._currentPost);
			}
			
			$('#categories li').bind('mousedown', function() {
				var id = $(this).attr('id');
				cat.setActive(id);
				cat.highlight(id);
				$('#posts li.' + id).show('highlight', {color: '#9edce3'}, 1500);
			});
			
		},
		
		setActivePost: function(id) {
			$('#posts li#post-' + id).addClass('active');
		},
		
		setActive: function(id) {
			$('#categories li').removeClass('active');
			$('#categories li#' + id).addClass('active');
		},
		
		getActive: function() {
			var hash = window.location.hash;
			
			if(hash != '') {
				return hash;
			}
			
			return this._current;
		},
		
		highlight: function(id) {
			$('#posts li').removeClass('highlight');
			$('#posts li.' + id).addClass('highlight');
		}
		
	},
	
	
	navigation: {
		
		_size: 590,
		_current: 1,
		_total: 1,
		
		init: function() {
			this._total = this.getTotal();
			
			nav = this;
			$('#navigation .next-slide a').bind('click', function() {
				nav.next();
			});
			$('#navigation .prev-slide a').bind('click', function() {
				nav.prev();
			});
			$('#navigation .counter a').bind('click', function() {
				var id = $(this).attr('id').slice(6);
				nav.slideTo(id);
			});
			
		},
		
		getTotal: function() {
			return $('#image img').size();
		},
		
		setActive: function(id) {
			$('#navigation .counter a').removeClass('active');
			$('#navigation .counter #image-' + id).addClass('active');
		},
		
		next: function() {
			if(this._current >= this._total) {
				this._current = 1;
			} else {
				this._current++;
			}
			this.slideTo(this._current);
		},
		
		prev: function() {
			if(this._current <= 1) {
				this._current = this._total;
			} else {
				this._current--;
			}
			this.slideTo(this._current);
		},
		
		slideTo: function(id) {
			this.setActive(id);
			$animateTo = -(this._size * id) + this._size;
			$('#image ul').animate({
				left: $animateTo + 'px'
			}, 1000);
		}
		
	}
	
}
