onerror=handleErr;
var txt="";

function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n";
txt+="Error: " + msg + "\n";
txt+="URL: " + url + "\n";
txt+="Line: " + l + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
return true;
}




	 
function addOnload(newFunction){
		 var oldOnload=window.onload;
		 
		 if(typeof oldOnload=="function"){
			 window.onload=function(){
				 if(oldOnload){
					 oldOnload();
				    }
				 newFunction();
			 }
		 }else{
			 window.onload=newFunction;
		 }
}
	
addOnload(newWinLinks);
addOnload(initAll);

			
function newWinLinks() {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].className == "newWin") {
			var img = document.links[i].href;
			document.links[i].onclick = viewPic; 
			return false;
			
		    }else if (document.links[i].className == "newWinHistory") {
			document.links[i].onclick = newWindowHistory;
		    }
			
	    }
	
}


function initAll() {
	var allLinks = document.getElementsByTagName("a");
	
	for (var i=0; i<allLinks.length; i++) {
		if (allLinks[i].className.indexOf("seeSublevel") > -1) {
			allLinks[i].onclick = toggleMenu;
		}
		
	}
	
	/*var allUls = document.getElementsByTagName("ul");
	
	for (var i=0; i<allUls.length; i++) {
		if (allUls[i].className.indexOf("rolloff") > -1) {
			allUls[i].onmouseout = UlRollOff;
		}
		
	}*/
}




function newWindow() {
	var thisImageNumber = this.id;
	var imageHeight = document.images[thisImageNumber].height;
	alert("this image height is " + imageHeight);
	var roadWindow = window.open(this.href, "roadWin", "resizable=yes,width=1250,height=650");
	roadWindow.focus();
	return false;
}

/*function newWindowHistory() {
	var roadWindow = window.open(this.href, "roadWin", "resizable=no,width=900,height=662");
	roadWindow.focus();
	return false;
}*/

//using img as parameter - the picture we want to view, this function assigns the src to a variable and calls function filecheck:
function viewPic()
{ 	
    var img = this.href;
	picfile = new Image(); 
    picfile.src =(img); 
    fileCheck(img);
	return false;
	
	
}

//this function checks to see if the picture has a size, and then calls the function makeWindow, else it delays the function call, in cas something is still loading:
function fileCheck(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img); 
    }
    else 
    {
        funzione="fileCheck('"+img+"')"; 
        intervallo=setTimeout(funzione,50); 
    }
}
 
// this function gets the dimensions of the image we want to show, adds 20px to the dimensions for padding, centers the picture in the screen using scrren.availHeight etc, and opens the window with the image, name and arguments just formed:
function makeWindow(img)
{ 	
    ht = picfile.height + 40;
    wd = picfile.width + 40; 

    var args= "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
	
   window.open(img, '', args);
	
	
}

						
//function that shows the menu sublevels when the top level is clicked:
function toggleMenu() {
	var startMenu = this.href.lastIndexOf("/")+1;
	var stopMenu = this.href.lastIndexOf(".");
	var thisMenuName = this.href.substring(startMenu,stopMenu);

	var thisMenu = document.getElementById(thisMenuName);
	thisMenu.className = (thisMenu.className == "nohover_click") ? "" : "nohover_click";
	
	/*var thisClass = document.getElementById(thisMenuName);
	thisClass.className = (thisClass.className == "selected_menu") ? "menuLink" : "selected_menu";
	alert("class name is: " + thisClass.className);*/
	
	
	
	return false;
	
	
}						


/*function UlRollOff(){
	var startMenu = this.href.lastIndexOf("/")+1;
	var stopMenu = this.href.lastIndexOf(".");
	var thisMenuName = this.href.substring(startMenu,stopMenu);

	var thisMenu = document.getElementById(thisMenuName);
	thisMenu.className = (thisMenu.className == "nohover_click") ? "" : "nohover_click";
}*/
