$(document).ready(function(){
	var $buffer = $('<div id="buffer"/>'),
		$back = $('#back').hide(),
		naviIDs = {artikel_5:'facebook',artikel_4:'bier',artikel_2:'speisen',artikel_7:'whiskey'};
	$('#content').tinyscrollbar({axis:'y'});
	$('body').append($buffer);
	$('.artikelnavi').each(function(idx){
		var $link = $(this),
			container = $('#content'),
			$this = $('#content'+$link.attr('id'));
		$link.click(function(event){
			if(this.id == 'artikel_5'){
				var fa = $('a',$this),
					evObj = document.createEvent('MouseEvents');
				evObj.initMouseEvent ("click", true, true, window, 0, 
												event.screenX, event.screenY, event.clientX, event.clientY, 
												event.ctrlKey, event.altKey, event.shiftKey, event.metaKey, 
												0, null);
				fa[0].dispatchEvent(evObj);
				return;
			}
			$('.viewport', container).css('width','405px');
			$('.overview',container).append($this);
			container.show();
			container.tinyscrollbar_update();
			if($('.scrollbar', container).css('display') == 'none'){
				$('.viewport', container).css('width','410px');
				//$this.css('width')
			}
			$back.show();
			$back.click(function(){
				$buffer.append($this);
				container.hide();
				$back.hide();
			});
		});
		$link.mouseover(function(){
			if(naviIDs[this.id]){
				$('.'+naviIDs[this.id]).show().css({opacity:1});
			}
			$(this).css({backgroundPosition:'0 0', opacity:1});
		});
		$link.mouseout(function(){
			if(naviIDs[this.id]){
				$('.'+naviIDs[this.id]).hide();
			}
			$(this).css({backgroundPosition:'-200px -200px'});
		});
		$buffer.append($this);
	});
	
	$('#logo').click(function(){
		$('.artikelnavi').stop(false, true).css({opacity:1,backgroundPosition:'0 0'}).animate({opacity:0},1000,'linear',function(){
			$(this).css({opacity:1,backgroundPosition:'-200px -200px'});
		}).each(function(){
			if(naviIDs[this.id]){
				$('.'+naviIDs[this.id]).stop(false, true).show().css({opacity:1}).animate({opacity:0},1000,'linear', function(){
					$(this).hide();
				});
			}
		});
	});
	$('#wochenkarteLink').click(function(){
		$('.overview .artikelContent>*').hide();
		$('#wochenkarteContainer').show();
		$('#content').tinyscrollbar_update();
	});
	$('.wochenkarteBackLink').click(function(){
		$('.overview .artikelContent>*').show();
		$('#wochenkarteContainer').hide();
		$('#content').tinyscrollbar_update();
	});
});
