var onloads = new Array();
function bodyOnLoad() {
     for ( var i = 0 ; i < onloads.length ; i++ )
        onloads[i]();
}

var menu={
	opened:null,
	init:function() {
		var uri=parseUri(document.URL);
		var id=null;
		switch(uri.fileName) {
			case 'lofric_primo.php':
         case 'lofric_sense.php':
			case 'hydro_kit.php':
			case 'lofric.php':
			case 'altri_prodotti.php':
				id="linea"
			break;
			case 'nuova_assistenza.php':
			case 'blue_book.php':
				id="pubb";
			break;
			case 'uti.php':
			case 'autocateterismo.php':
				id="info";
			break;
			case 'unita_spinali.php':
			case 'centri_riabilitazione.php':
				id="riabil";
			break;
			case '25_anni.php':
			case 'expo_sanita_2008.php':
				id="inter";
			break;
            
            case 'molise.php':
            case 'umbria.php':
            case 'trentino.php':
            case 'sicilia.php':
            case 'sardegna.php':
            case 'calabria.php':
            case 'basilicata.php':
            case 'puglia.php':
            case 'campagna.php':
            case 'abruzzo.php':
            case 'lazio.php':
            case 'marche.php':
            case 'toscana.php':
            case 'piemonte.php':
            case 'emilia.php':
            case 'veneto.php':
            case 'lombardia.php':
            case 'friuli.php':
            case 'liguria.php':
            case 'aosta.php':
			case 'nazionali.php':
			case 'regionali.php':
				id="assoc";
			break;
		}
		if (id) {
			var context=this;
			Effect.toggle(id,'appear',{afterFinish:function() { context.opened=id; } });
		}
	},
	showMenu:function(id) {
		var context=this;
		if (!this.opening) {
			if (this.opened) {
				if (this.opened==id) {
					context.opening=true;
					Effect.toggle(id,'appear',{afterFinish:function() { context.opened=null; context.opening=false; } });	
				} else {
					context.opening=true;
					Effect.toggle(context.opened,'appear',{afterFinish:function() { 
						Effect.toggle(id,'appear',{afterFinish:function() { context.opened=id;context.opening=false; } });
					} });
				}
				
			
			} else {
				context.opening=true;
				Effect.toggle(id,'appear',{afterFinish:function() { context.opened=id;context.opening=false; } });	
			}
		}
	}
}
function parseUri(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};
    
    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }
    
    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }
    
    return uri;
}

onloads.push(function(){
	menu.init();
});

Event.observe(window,'load',bodyOnLoad);
