            $(function() {
                var current = -1;
				
				var loaded  = 0;
				for(var i = 1; i <6; ++i)
					$('<img />').load(function(){
						++loaded;
						if(loaded == 5){
							$('#bg1,#bg2,#bg3,#bg4,#bg5').mouseover(function(e){
								
								var $this = $(this);
								if($this.parent().index() == current)
									return;

								var item = e.target.id;

								$('#menu .sub'+parseInt(current+1)).stop().animate({backgroundPosition:"(-160px 0)"},600,function(){
									$(this).find('li').hide();
								});

								if(current > $this.parent().index()){
									$('#menu > li').animate({backgroundPosition:"(-800px 0)"},0).removeClass('bg1 bg2 bg3 bg4 bg5').addClass(item);
									move(0,item);
								} else {
									$('#menu > li').animate({backgroundPosition:"(800px 0)"},0).removeClass('bg1 bg2 bg3 bg4 bg5').addClass(item);
									move(1,item);
								}


								
								current = $this.parent().index();
								
							   
								$('#menu .sub'+parseInt(current+1)).stop().animate({backgroundPosition:"(0 0)"},300,function(){
									$(this).find('li').fadeIn();
								});
							});
						}	
					}).attr('src', '/fileadmin/templates/images/'+i+'.jpg');
				
							
                /*
                dir:1 - move left->right
                dir:0 - move right->left
                 */
                function move(dir,item){
                    if(dir){
                        $('#bg1').parent().stop().animate({backgroundPosition:"(0 0)"},300);
                        $('#bg2').parent().stop().animate({backgroundPosition:"(-160px 0)"},600);
                        $('#bg3').parent().stop().animate({backgroundPosition:"(-320px 0)"},800);
                        $('#bg4').parent().stop().animate({backgroundPosition:"(-480px 0)"},1000);
                        $('#bg5').parent().stop().animate({backgroundPosition:"(-640px 0)"},1200,function(){
                            $('#menuWrapper').removeClass('bg1 bg2 bg3 bg4 bg5').addClass(item);
                        });
                    }
                    else{
                        $('#bg1').parent().stop().animate({backgroundPosition:"(0 0)"},1200,function(){
                            $('#menuWrapper').removeClass('bg1 bg2 bg3 bg4 bg5').addClass(item);
                        });
                        $('#bg2').parent().stop().animate({backgroundPosition:"(-160px 0)"},1000);
                        $('#bg3').parent().stop().animate({backgroundPosition:"(-320px 0)"},800);
                        $('#bg4').parent().stop().animate({backgroundPosition:"(-480px 0)"},600);
                        $('#bg5').parent().stop().animate({backgroundPosition:"(-640px 0)"},300);
                    }
                }
            });

