window.addEvent('domready', function() {
    
    var infoIsOpen = false;
    $$('.entry').setStyle('position', 'relative');
    var numImg = 10;
    var r = 1+Math.floor(Math.random()*numImg);
    var img = String('url(http://www.andreapinchi.it/py/headbg'+r+".png)");
    $('infocontent').setStyle('display', 'block');
    $('headbg').setStyle('background-image', img);

	var myVerticalSlide = new Fx.Slide('infocontent', {transition: 'sine:out', duration: 500});
	
	$('infotoggle').addEvent('click', function(e){
		e.stop(); 
		checkOpen();
        myVerticalSlide.toggle();
	});
	
	$('me').addEvent('click', function(e){
		e.stop(); 
		checkOpen();
        myVerticalSlide.toggle();
	});
	
	$('me').addEvent('mouseover',function(){
        $('infotoggle').setAttribute('class', 'active');
    });
    
    $('me').addEvent('mouseout',function(){
        $('infotoggle').setAttribute('class', '');
    });
	
	myVerticalSlide.hide();
	
	function checkOpen(){
		if(infoIsOpen){
			infoIsOpen = false;
			setTimeout("$$('.entry').setStyle('position', 'relative')", 502);
			$('content').setStyle('z-index', '20');
			$('otherlink').setStyle('position', 'static');
		}else{
			infoIsOpen = true;
			$('content').setStyle('position', 'relative');
			$('content').setStyle('z-index', '0');
			setTimeout("$('otherlink').setStyle('position', 'absolute')", 502);
			
		}
	}
	

	$$('.boximg').addEvent('mouseover',function(e){
		e.stop();
		this.set('morph', {duration: 300});
		this.morph('.imghover');
    });

   	$$('.boximg').addEvent('mouseout',function(e){
   		e.stop()
   		this.set('morph', {duration: 300});
        this.morph('.imgout');
   	});

    
    termSearch = false;
    
    function sel(){
    	elem = document.getElementById('s');
		elem.select();
	}
    
    if(!termSearch){
    	sel();
    	termSearch = true;
    }
});