Navigation = function(obj)
{
	this.obj			= obj;
	this.navPrev		= this.obj.find('.nav.prev');
	this.navNext		= this.obj.find('.nav.next');
	this.options		= this.obj.find('.options');
	this.searchIcon		= this.obj.find('.search-icon');
	this.currentItem	= this.obj.find('.current');
	this.scrollSpeed	= 250;
	this.page			= 0;
	this.pages			= [];
	this.category		= '';
	this.rulerWidth		= 1;
	this.itemPadding	= {desktop: 70, tablet: 48};
	this.itemPadding	= {desktop: 55, tablet: 24};

	this.init = function()
	{
		var _this = this;

		this.refresh();
		this.options.find('.item').mouseup(function() {
			var category = $(this).attr('id').substr(7);	// navcat-...
			if (page == 'index') {
				document.location.hash = category;
				_this.filterTeaser();
			} else {
				document.location = root + '#' + category;
			}
		})

		$(document).click(function() {
			if (device == 'mobile' && _this.options.is(':visible')) {
				_this.options.hide();
			}
		})
		this.currentItem.click(function() {
			if (_this.options.is(':visible')) {
				_this.options.hide();
			} else {
				_this.options.show();
			}
			return false;
		})
		this.searchIcon.click(function() {
			if ($('.search.mobile').is(':visible')) {
				$('.search.mobile').hide();
			} else {
				$('.search.mobile').show();
			}
		})
		$(window).hashchange(function() {
			_this.filterTeaser();
		})
		this.filterTeaser();
	}

	this.refresh = function()
	{
		var _this = this;
		// Check visibility of Prev/Next-Buttons
		// Get scroll page positions
		if (device == 'mobile') {
			_this.options.hide();
			_this.navPrev.hide();
			_this.navNext.hide();
			_this.obj.removeClass('scroll');
		} else {
			_this.options.show();
			var itemWidth = 0;
			var pageWidth = 0;
			var page = 1;
			this.pages = [0];
			this.obj.find('.item').each(function() {
				itemWidth += $(this).width() + _this.itemPadding[device]*2 + _this.rulerWidth;
				pageWidth += $(this).width() + _this.itemPadding[device]*2 + _this.rulerWidth;
				if (pageWidth > _this.obj.width()) {
					pageWidth = $(this).outerWidth() + _this.rulerWidth;
					page ++;
				}
				_this.pages[page] = itemWidth;
			})
			this.pages.pop();
	
			if (itemWidth > this.obj.width()) {
				// Show Prev/Next-Button
				this.obj.addClass('scroll');
				this.obj.find('.nav').fadeIn();
				this.navPrev.click(function() {
					_this.scrollPrev();
				})
				this.navNext.click(function() {
					_this.scrollNext();
				})
			} else {
				this.obj.removeClass('scroll');
				this.obj.find('.nav').hide();
			}
	
			this.page = 0;
			this.options.stop().css({left: 0});
		}
	}

	this.scrollPrev = function()
	{
		if (this.page <= 0) {
			return;
		}
		this.page --;
		this.options.stop().animate({left: -this.pages[this.page]}, this.scrollSpeed);
	}

	this.scrollNext = function()
	{
		if (this.page >= this.pages.length-1) {
			return;
		}
		this.page ++;
		this.options.stop().animate({left: -this.pages[this.page]}, this.scrollSpeed);
	}

	this.filterTeaser = function()
	{
		var category = (page == 'index') ? 'all' : '';
		if (document.location.hash.length > 1) {
			var category = document.location.hash.substr(1);
		}
		this.obj.find('.item').removeClass('active');
		if (category != '') {
			this.obj.find('#navcat-'+category).addClass('active');
			var currentText = this.obj.find('.item.active').text();
			this.currentItem.html(currentText);
		}

		if (device == 'mobile') {
			this.options.hide();
		}

		$('.content .teaser').hide();
		if (category == 'all') {
			$('.content .teaser.all').fadeIn(250);
		} else {
			$('.content .teaser.category-'+category).fadeIn(250);
		}
	}

	this.init();
}

