jQuery('document').ready(function(){
    var proximity = 200;
    var divider = proximity / -10
    jQuery('body').mousemove(function(e){
		jQuery('#main_menu li:first').each(function(){
            var item = jQuery(this);
            var offset = item.offset();
            var distance = Math.sqrt(Math.pow((offset.left + item.width() / 2) - e.pageX, 2) +
            			   Math.pow((offset.top + item.height() / 2) - e.pageY, 2));
            if (distance < proximity) {
                item.css('marginBottom', distance / divider);
            } else {
				item.css('marginBottom', '-10px');
			}
        });
        jQuery('#main_menu li:not(:first)').each(function(){
            var item = jQuery(this);
            var offset = item.offset();
            var distance = Math.sqrt(Math.pow((offset.left + item.width() / 2) - e.pageX, 2) +
            			   Math.pow((offset.top + item.height() / 2) - e.pageY, 2));
            if (distance < proximity) {
                item.css('margin', distance / divider + 'px 0');
            } else {
				item.css('margin', '-10px 0');
			}
        });
    });
    
    //person menu
    
    var menuWidth = 0;
    $j('#person_menu li a').each(function(index,element){
		    var parentWidth = $j(element).width() + 6;
		    menuWidth += parentWidth;
		    var childWidth = $j(element).children('span').css({opacity: 0}).width() + 14;
		    $j(element).children('span').css({left: (parentWidth - childWidth) / 2});
		}).mouseenter(
		    function(){ 
		        $j(this).children('span').stop().animate({bottom: '15px', opacity: 0.8}, 100); 
		    }
	    ).mouseleave( 
		    function(){
		        $j(this).children('span').stop().animate({bottom: '60px', opacity: 0}, 500, function(){
				    $j(this).css({bottom: '-30px', opacity: 0});    
				});
		    }
		);
		
	$j('a[href*="gesichter"]').click(function(event){
	    event.preventDefault();
	    $j('a').each(function(index, element){
			$j(element).attr('href', $j(element).attr('href') + '?gesichter');
		});
	    $j('#content').html($j('#person_menu').css({visibility: 'visible'})).css({width: '700px', 'padding-left': 0});
	    $j('#person_menu li').each(function(){
	    	var rotation = 'rotate(' + (Math.random() * 4 - 2)  + 'deg)'
		    $j(this).css({
		    	top: Math.random() * 20 - 10, 
		    	left: Math.random() * 20 - 10, 
		    	'-moz-transform': rotation,
		    	'-webkit-transform': rotation, 
		    	'-o-transform': rotation,
		    	'-ms-transform': rotation   
		    	})
		});
	});

});

