window.onload = function(){

	/** Category Menu  */
	if($('categoryMenu')){
		
		var curMenuItem = $('menu-hauptmenu').getElement('.current-menu-item');
		var categoryMenu = $('categoryMenu');
		var content = $('content');
		
		var aLinks = $('categoryMenu').getElements('.anchorLink');	
		$('categoryMenu').getElements('a.anchorLink').addEvent('click', function(event){
			aLinks.each(function(el){
				el.getParent('li').removeClass('current-menu-item');
			});
			this.getParent('li').addClass('current-menu-item');
			curMenuItem = this;
		
			var cElement = $(this.get('href').replace('#', ''));
			if(cElement){
				var myFx = new Fx.Tween(content, {});
				myFx.start('left', content.offsetLeft, 300).chain(function(){
					myFx.start('left', content.offsetLeft, (cElement.offsetLeft-61) * -1);
				});
			}
		});
		if(aLinks){
			aLinks[0].getParent('li').addClass('current-menu-item');
		}		
	}
	if(curMenuItem && categoryMenu){
		categoryMenu.position({
			relativeTo: curMenuItem,
			position: 'bottomLeft',
			edge: 'bottomLeft',
			offset: {x: 0, y: 15}
		});
		categoryMenu.fade(0);
		categoryMenu.setStyle('display', 'block');
		categoryMenu.fade(0, 1);
	}
	
	/* scroll */
	var defTopPosHeader = parseInt($('header').getStyle('top'));
	var defTopPosContent = parseInt($('content').getStyle('top'));
	var defTopPosFooter = parseInt($('footer').getStyle('top'));	
	
	window.addEvent('scroll', function(e){
		posY = window.getScroll().y;
		$('header').setStyle('top', defTopPosHeader - posY + 'px');
		$('content').setStyle('top', defTopPosContent - posY + 'px');
		$('footer').setStyle('top', defTopPosFooter - posY + 'px');
	});
	
	if(categoryMenu){
		var fxLeft = new Fx.Tween($('goLeft'), {transition: Fx.Transitions.Bounce.easeInOut, duration: 500});
		var fxRight = new Fx.Tween($('goRight'), {transition: Fx.Transitions.Bounce.easeInOut, duration: 500});
		$('goLeft').addEvent('click', function(e){
			new Event(e).stop();
			var x = aLinks.length;
			while(x >= 0){
				if(x > 0){
					parentLi = aLinks[x-1].getParent();
					if(parentLi){
						if(parentLi.hasClass('current-menu-item')){
							x--;
							if(x > 0){						
								aLinks[x-1].fireEvent('click');
							}else{
								fxLeft.start('left', this.offsetLeft, this.offsetLeft + 5).chain(function(){
									fxLeft.start('left', this.offsetLeft, this.offsetLeft - 5);
								});								
							}
						}
					}					
				}
				x--;
			}
		});
		
		$('goRight').addEvent('click', function(e){
			new Event(e).stop();
			var x = 0;
			while(x < aLinks.length){
				parentLi = aLinks[x].getParent();
				if(parentLi){
					if(parentLi.hasClass('current-menu-item')){
						x++;
						if(x < aLinks.length){
							aLinks[x].fireEvent('click');					
						}else{
							fxRight.start('left', this.offsetLeft, this.offsetLeft + 5).chain(function(){
								fxRight.start('left', this.offsetLeft, this.offsetLeft - 5);
							});	
						}
						break;
					}			
				}
				x++;
			}
		});			
	}else{
		$('goLeft').setStyle('display', 'none');
		$('goRight').setStyle('display', 'none');
	}
}
