var homeBoard = {
	board: null,

	build: function() {

		// contenitore dell'homeBoard
		var cont = $('bannerWrapArea');
		cont.setStyle({position:'relative'});
		
		
		this.board = new Element('div');
		
		this.board.setStyle({position:'absolute',
						width:'100%',
						height:'100%',
						top:0,
						left:0,
						backgroundImage:'url(http://excogita/public/banners/web.jpg)',
						backgroundRepeat:'no-repeat',
						backgroundPosition:'center center',
						color:'#ffffff',
						textAlign:'justify'});
	
		var boardTextCont = new Element('div');
		this.board.appendChild(boardTextCont);
		boardTextCont.setStyle({position:'absolute',
								height:'100%',
								width:'300px',
								left:0,
								top:0,
								backgroundColor:'#FFAE2F',
								opacity:0.85});
	
		var text = new Element('p');
		boardTextCont.appendChild(text);
		text.setStyle({ padding:'10px',color:'#ffffff', fontSize:'11px', lineHeight:'22px', fontWeight:'bold' });
	
		// text.innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla nulla quam, porta vel gravida vel, varius at orci. In id enim at turpis egestas ullamcorper. Mauris volutpat dapibus risus a ultrices! Aliquam faucibus neque et nisi porta vehicula accumsan mauris faucibus. Vivamus non tincidunt velit.';
	
		this.hide();
		cont.appendChild(this.board);

	},

	removeBoard: function() {

		var board = $('bannerWrapArea').firstDescendant().next();
		if(board) board.remove();

	},

	start: function(conf) {
		this.build();

		// BDG var homePar = $$('.parTitle');
		conf = $A(conf);

		var obj = this;

		var hiderId = null;

		conf.each(function(el) {

			var parent = $(el.id);

			Event.observe(parent,'mouseenter',function(e) { 
				e.stop();

				window.clearTimeout(hiderId);

				var src = el.src;
				var text = el.text;
				this.show(src,text);

			}.bindAsEventListener(obj));

			Event.observe(parent,'mouseleave',function(e) { 
				e.stop();

				hiderId = this.hide.delay(1,this);

			}.bindAsEventListener(obj));

			

		});
	},
	
	hide: function(obj) {
		obj ? obj.board.hide() : this.board.hide();
	},
	
	show: function(imgSrc,text) {
		this.board.show();
		if(imgSrc!=undefined) {
			this.board.setStyle({backgroundImage:'url(\'' + imgSrc+ '\')'});
		}
		if(text!=undefined)
			this.board.down('p').innerHTML = text;
	}
	
	

};

Event.observe(window.document,'dom:loaded',function() { 

	new Ajax.Request('plugin/board/board.json',{
		method: 'get',
		onSuccess: function(t) {
			var boardConf = t.responseText.evalJSON();
			homeBoard.start(boardConf);
		}
	});

	// var el = $('textArea').getElementsByClassName('imgUp')[0].getAttribute('id'); // -20 punti ERRORE GRAVISSIMO!!!
	
	var a_par = $$('.paragraph');
	
	// alert(a_par);
	

	// per ciascun elemento dell'array attacco l'evento desiderato
	a_par.each(function(el) {
		
		
		Event.observe(el,'mouseenter',function(e) { 
			// e.stop();
			el.removeClassName('imgUp').addClassName('imgDown');
		});
		
		Event.observe(el,'mouseleave',function(e) { 
			// e.stop();
			el.removeClassName('imgDown').addClassName('imgUp');
		});
						
	});	

	

	
	 
});
