var $basePath= "./lib/tpl/twReloaded/img/";



var $imgs= new Array();
$imgs[0]= "who.png";
$imgs[1]= "courses.png";
$imgs[2]= "projects.png";
$imgs[3]= "docs.png";
$imgs[4]= "contacts.png";
$imgs[5]= "network.png";
$imgs[6]= "tronwiki.png";
$imgs[7]= "login.png";

var $menu= new Array();
$menu[0]= "Who";
$menu[1]= "Courses";
$menu[2]= "Projects";
$menu[3]= "Docs";
$menu[4]= "Contacts";
$menu[5]= "Network";
$menu[6]= "Tronwiki";

function imgLink($id, $width, $height, $y, $x) {
this.id = $id;
this.style = $(this.id).style;
this.style.width= $width;
this.style.height= $height;
this.style.top= $y;
this.style.left= $x;
}
imgLink.prototype.addEvent = function($event, $action) {
//alert("document.getElementById('"+this.id+"')."+$event+"= function() {"+$action+"}");
eval("$('"+this.id+"')."+$event+"= function() {"+$action+"}");
}

window.onload = function() {

	if ($("menuLogin")) {
		$menu[7]= "Login"; 
	}

	// images preloader
	var $preloadedImgs = new Array();
	for ($i=0; $i<$imgs.length; $i++) {
		$preloadedImgs[$i]= new Image();
		$preloadedImgs[$i].src= $basePath+$imgs[$i];
	}

	// events manager
	var $current= "";
	var $overMenu= 0;
	var $overDesc= 0;
	var $login= $('menuLogout');
	for ($i=0; $i<$menu.length; $i++) {
		if (!$login) {
		$("menu"+$menu[$i]).onmouseover = function() {
			//if ($current != "" && document.getElementById($current).style.display != "none") {
			//Effect.Fade($current,{duration:.3});
			//}
			if (!$login) {
					var queue = Effect.Queues.get('global');
					queue.each(function(effect) { effect.cancel() });
					for($j=0; $j<$menu.length; $j++) {
						//alert(document.getElementById($menu[$j].toLowerCase).style.display);
						//if (document.getElementById($menu[$j].toLowerCase()).style.display != "none") {
						//Effect.Fade(document.getElementById($menu[$j].toLowerCase()),{duration:.3});
						$($menu[$j].toLowerCase()).style.display = "none";
						//}
					}
					$("auth").style.display= "none";
					$current = this.id.substring(4).toLowerCase();
					Effect.Appear($current,{duration:1});
			}
		}
	
		$("menu"+$menu[$i]).onmouseout = function() {
			Effect.Fade($current,{duration:1});
		}
	}
	}
	if ($login){
		Effect.Appear('auth',{duration:1});
	}

	// GESTIONE PULSANTE LOGIN
	if ($("menuLogin")) {
		$("menuLogin").onclick = function() {
			if(!$login) {
				$login = !$login;
				var queue = Effect.Queues.get('global');
				queue.each(function(effect) { effect.cancel() });
				Effect.Fade("login",{duration:1});
				for($j=0; $j<$menu.length-1; $j++) {
					$($menu[$j].toLowerCase()).style.display = "none";
				}
				Effect.Appear("auth",{delay:1},{duration:1});
			} else {
				Effect.Fade("auth",{duration:1});
				Effect.Appear("login",{delay:1},{duration:1});
				$login = !$login;
			}
		}
	}

	// LINK VIRTUALI SU DESCRIZIONE TW
	var ICT= new imgLink("ict", "38px", "23px", "66px", "409px")
	ICT.addEvent("onmouseover", "this.style.borderBottom= 'solid 1px #356AA0;'");
	ICT.addEvent("onmouseout", "this.style.borderBottom= 'none;'");
	ICT.addEvent("onclick", "location='http://it.wikipedia.org/wiki/ICT';"); 
	
	var tron= new imgLink("tron", "68px", "20px", "120px", "209px");
	tron.addEvent("onmouseover", "this.style.borderBottom= 'solid 1px #356AA0;'");
	tron.addEvent("onmouseout", "this.style.borderBottom= 'none;'");
	tron.addEvent("onclick", "location='http://www.tron.vi.it';"); 
}
