function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(init);



function init()
{
	supps = document.getElementsByClassName('supp');
	supps.each(
		function(supp) {
			if ( supp.nodeName == 'DIV' ) {
				init_div(supp);
			} else if (supp.nodeName == 'A') {
				init_link(supp);
			}
		}
	);
}


function init_div(div)
{
	// attach a close link to the end of the element
	close_link = create_close_link(div);
	div.appendChild(close_link);
	
	// hide the element
	div.style.display = 'none';
}


function init_link(a)
{
	// get the href attribute and use it to determine the id of the div we're interested in
	var id = a.getAttribute('href');
	id = id.substring(id.indexOf('#')+1, id.length);
	
	// add onclick eventlistener to the link to show the hidden div
	a.onclick = function() {
			if ( $(id) ) Effect.Combo($(id), {duration : .2});
			return false;
		}
}
	
	
function create_close_link(div)
{
	// the class of the #header div gives me the language of the document - default to English
	lang = $('header') ? $('header').getAttribute('class') : 'en';
	if ( 'it' == lang )
	{
		t = document.createTextNode('chiudi');
	}
	else
	{
		t = document.createTextNode('close');
	}
	
	// insert the text into the link
	a = document.createElement('a');
	a.setAttribute('href', 'home');
	a.appendChild(t);
	
	// add the onclick handler to the link
	a.onclick = function() {
			Effect.CloseDown(div, {duration : .2});
			return false;
		}
	
	// attach the link to the paragraph
	p = document.createElement('p');
	p.className = 'close';
	p.appendChild(a);
	
	// return the paragraph element
	return p;
}




Effect.OpenUp = function(element) {
     element = $(element);
     new Effect.BlindDown(element, arguments[1] || {});
 }

 Effect.CloseDown = function(element) {
     element = $(element);
     new Effect.BlindUp(element, arguments[1] || {});
 }

 Effect.Combo = function(element) {
     element = $(element);
     if ( element.style.display == 'none' ) { 
          new Effect.OpenUp(element, arguments[1] || {}); 
     } else { 
          new Effect.CloseDown(element, arguments[1] || {}); 
     }
 }