/////////////////////////////////////////////////////


// BROWSER SNIFFER (Sniff out the good and bad browsers)

function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
}

var is = new Is();

function onerror() {
    document.location.href = "javascript:";
}

// DOCUMENT OBJECT SWITCH (Used for building cross_browser functions)

if(is.ns4) {
    doc = "document";
    sty = "";
    htm = ".document"
} else if(is.ie4) {
    doc = "document.all";
    sty = ".style";
    htm = ""
}

/////////////////////////////////////////////////////



var count = 0;

function preLoad() {
    	
	stemma = new Image();
    stemma.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    stemma.src = "images/stemma.GIF";
	
	roccabig1 = new Image();
    roccabig1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    roccabig1.src = "images/roccabig1.GIF";
	
	storia1 = new Image();
    storia1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    storia1.src = "images/Pulsanti/storia.GIF";
	
	eventi1 = new Image();
    eventi1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    eventi1.src = "images/Pulsanti/eventi.GIF";
	
	info1 = new Image();
    info1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    info1.src = "images/Pulsanti/Info.GIF";
	
	borgo1 = new Image();
    borgo1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    borgo1.src = "images/Pulsanti/AnticoBorgo.GIF";
	
	storiar1 = new Image();
    storiar1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    storiar1.src = "images/Pulsanti/storiar.GIF";
	
	
	eventir1 = new Image();
    eventir1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    eventir1.src = "images/Pulsanti/eventir.GIF";
	
	infor1= new Image();
    infor1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    infor1.src = "images/Pulsanti/Infor.GIF";
	
	borgor1 = new Image();
    borgor1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    borgor1.src = "images/Pulsanti/AnticoBorgor.GIF";
	
	
	
	territorio1 = new Image();
    territorio1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    territorio1.src = "images/Pulsanti/territorio.GIF";
	
	territorior1 = new Image();
    territorior1.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    territorior1.src = "images/Pulsanti/territorior.GIF";
	
	barr = new Image();
    barr.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    barr.src = "images/barra9.gif";
	
	stemmafr = new Image();
    stemmafr.onload  = (is.ns4b) ? loadCheck() : loadCheck;
   	stemmafr.src = "images/stemma_frosinon.gif";
	
}

function loadCheck() {
    count++;
    if(count == 14) {
        var status = eval(doc + '["msgLyr"]' + sty);
        status.visibility = "hidden";
        positionLayers();
    } else {
        var status = eval(doc + '["msgLyr"]' + htm);
        var msg = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=300><TR><TD WIDTH=' + Math.round((count/14)*100) + '% BGCOLOR=#FF0000 ALIGN=RIGHT>' + '<FONT class="status">' + Math.round((count/14)*100) + '%</FONT>' +'</TD><TD BGCOLOR=#800000 VALIGN=MIDDLE>&nbsp;</TD></TR><TR><TD COLSPAN=2 ALIGN=CENTER><FONT class="main">Percent Images Loaded</FONT></TD></TR></TABLE>';
        if(is.ns4) {
            status.write(msg);
            status.close();
        } else if(is.ie4) {
            status.innerHTML = msg;
        }
    }
}





/////////////////////////////////////////////////////


function positionLayers() {
   
    
	buttonImg = eval(doc + '["titleLyr"]' + '.document');
    titleObj = eval(doc + '["titleLyr"]' + sty);
    titleObj.left = 5;
    titleObj.top = 0;
	
	infomenuObj = eval(doc + '["infomenuLyr"]' + sty);
    infomenuObj.left = 8;
    infomenuObj.top = 140;

	
    infosObj = eval(doc + '["infosLyr"]' +  sty);
    infosObj.left = 245;
    infosObj.top = 10;

	arrivareObj = eval(doc + '["arrivareLyr"]' +  sty);
    arrivareObj.left = 245;
    arrivareObj.top = -1010;
   	
    arrowObj = eval(doc + '["arrowLyr"]' + sty);
    arrowObj.left = 720;
	arrowObj.top = 150;
    

    
    
	titleObj.visibility = "visible";
    arrowObj.visibility = "visible";
    infosObj.visibility = "visible";
	infomenuObj.visibility = "visible";
      
}




/////////////////////////////////////////////////////


var menu_selection = "infos";
var info_selection ="infos"

function buttonOver(selection,pos) {
    if(menu_selection != selection) {
	switch(selection) {
				case	'infos':
				   
				    buttonImg[selection].src = infor1.src;
    				break;
				case	'borgos':
					
					buttonImg[selection].src = borgor1.src;
					break;
				case	'storia':
					
					buttonImg[selection].src = storiar1.src;
					break;
				case	'eventis':
					
					buttonImg[selection].src = eventir1.src;
					break;
			case	'home':
					
					buttonImg[selection].src = homer1.src;
					break;
			
			case	'territorio':
					
					buttonImg[selection].src = territorior1.src;
					break;
			
	}
	
	}
	
}

function buttonOut(selection) {
if(menu_selection != selection) {
switch(selection) {
				case	'infos':
				    buttonImg[selection].src = info1.src;
    				break;
				case	'borgos':
				    buttonImg[selection].src = borgo1.src;
					break;
				case	'storia':
		     		buttonImg[selection].src = storia1.src;
					break;
				case	'eventis':
					
					buttonImg[selection].src = eventi1.src;
					break;
			case	'home':
					
					buttonImg[selection].src = home1.src;
					break;
			case	'territorio':
					
					buttonImg[selection].src = territorio1.src;
					break;
			
	}
}
   // if(menu_selection != selection) {
    //    buttonImg[selection].src = freccia1.src;
    //}
}

function menuToggle(selection) {
//menuObj.visibility = "visible";
    //buttonImg[menu_selection].src = freccia1.src;
    //buttonImg[selection].src = freccia2.src;

    var old_page = eval(menu_selection + "Obj");
    old_page.visibility = "hidden";

    var new_page = eval(selection + "Obj");
    new_page.visibility = "visible";

    

    menu_selection = selection;

}


function menuToggleBis(selection) {
    
	
if(info_selection != "arrivare") {
	switch(info_selection) {
			case	'infos':
					infos.visibility = "hidden";
					//buttonImg[menu_selection].src = infos.src;
					break;
			
			
		}

	}
	
	
	
}


/////////////////////////////////////////////////////


var loop = true;
var direction = "up";
var speed = 10;
var timer1 = null;

function scroll(dir,spd) {
    direction = dir;
    speed = spd;
	if (info_selection != "infos")
	{var page = eval(info_selection + "Obj");
	}
	else {
    var page = eval(menu_selection + "Obj");}
    var y_pos = parseInt(page.top);
   
    if(loop == true) {
        if(direction == "dn") {
                      
			switch(info_selection) {
				case	'infos':
				    if( y_pos>-1430) {
            		page.top = (y_pos-(speed));
				    }
    				break;
				case	'arrivare':
					if( y_pos>-430) {
            		page.top = (y_pos-(speed));
									    }
					break;
				
			
	}
		   
		 
            clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
        } else if(direction == "up" && y_pos < 10) {
            page.top = (y_pos+(speed));
          
            clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
        } else if(direction == "top") {
            page.top = 10;
       
        }
    }
	else if (loop == false)
	{page.top = 10;
	y_pos = parseInt(page.top);
	page.top = (y_pos-(speed));
	}
}



function scrollpage(selection,dir,spd) {
    direction = dir;
    speed = spd;
    var page = eval(menu_selection + "Obj");
    var y_pos = parseInt(page.top);
    
	 if (loop == false)
	{
	
page.top = 10;
	y_pos = parseInt(page.top);
	page.top = (y_pos-(speed));
    //sunObj.left = 0;

	}
}

//Usato dalle pagine delle informazioni
function changepage(selection,dir,spd) {
	direction = dir;
    speed = spd;
    var page = eval( selection + "Obj");
    var y_pos = parseInt(page.top);
   
    
	if(info_selection != selection) {
	switch(info_selection) {
				case	'infos':
				    infosObj.visibility = "hidden";
				    infosObj.top = -1310;
    				break;
				case	'arrivare':
					arrivareObj.visibility = "hidden";	
					arrivareObj.top = -1010;
					break;
				
			
	}
	
	switch(selection) {
				case	'infos':
				    infosObj.visibility = "visible";
				    infosObj.top = 10;
    				break;
				case	'arrivare':
					arrivareObj.visibility = "visible";	
					arrivareObj.top = 10;
					break;
				
			
	}
	
	} //fine if
	info_selection = selection;
	if (loop == false)
	{
	page.top = 10;
	y_pos = parseInt(page.top);
	page.top = (y_pos-(speed));
    
	}
}


function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}

function saveFile (fname)
{
	document.execCommand('SaveAs',null,fname);
}

function varitext(text){
//text=infosLyr
print(text)
}

function selectWin(source,h1,w1){
 newWin = window.open(source,'','height=' + h1 + ',width=' + w1 + ',top=1,left=1');
}

function writeWin(source){

 f = window.open();
 f.document.write(['infosLyr']);
 f.document.close();
}

function Wopen(){
switch(info_selection ) {
		case	'arrivare':
				//  apri=eval(source + "1Light.htm" );   
				 newWin = window.open('ArrivareLight.htm','Informazioni','scrollbars=yes,resize=yes,width=640,height=500');
				// apri='Storia1Light.htm';   
    				break;
				case	'infos':
					 newWin = window.open('InfoLight.htm','Informazioni','scrollbars=yes,width=520,height=500');
				  
					break;
				
			
	}
	clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
//clearTimeout(timer2);
//timer2 = setTimeout("Wopen()", 1);
}



