var rControlla;
var panControlla;
var panoramica="";


function Request_dx(name,dati)
{	
	if (dati=="undefined") dati="";
    $("#colonnaDx").load(name,dati); 
};  



function Request_sx(name)
{	
	if (dati=="undefined") dati="";
    $("#colonnaSx").load(name,dati); 
};

function Request(id_tag,name,dati)
{	
	if (dati=="undefined") dati="";
    $("#"+id_tag).load(name,dati); 
};

function entsub(e) {
  if (window.event && window.event.keyCode == 13) {
    document.login.submit();
  }
};

function webcam_home()
{	
	var webdate = new Date();
    document.getElementById("webcam").innerHTML="<img src='http://82.85.91.83/public/webcam.jpg#e"+ Math.random()+"' border='0' alt='immagine da una webcam del Parco' style='display:block;text-align:center;margin:0;padding:0;width:256px;height:196px;' >"; 
	clearTimeout(rControlla);
	if (document.getElementById("webcam")&&webdate.getHours()>5&&webdate.getHours()<22) {rControlla = setTimeout("webcam_home()", 60000);}
};  

function webcam_vivere() {
	var webdate = new Date();
	document.getElementById("webcam").innerHTML="<img src='http://82.85.91.83/public/webcam.jpg#e"+ Math.random()+"' border='0' alt='immagine da una webcam del Parco' style='display:block;text-align:center;margin:0;padding:0;width:205px;height:148px;' >"; 
	clearTimeout(rControlla);
	if (document.getElementById("webcam")&&webdate.getHours()>5&&webdate.getHours()<22) {
		rControlla = setTimeout("webcam_vivere()", 60000);
	}
};  

function Pan_aggiorna() {
	Request('panPoetto','../vivere/panoramiche.php');
	clearTimeout(panControlla);
	panControlla = setTimeout("Pan_aggiorna()", 600000);
	// 10 minuti
};


function toolbar_naviga(txt) {
	document.getElementById("navig").innerHTML=txt;	
};

function toolbar_naviga1(txt) {
	document.getElementById("navig1").innerHTML=txt;	
};

function so_applyStyle(obj,str){
	if(document.all && !window.opera) {
    	obj.style.setAttribute("cssText",str);
	}else{
    	obj.setAttribute("style",str);
	}
}; 


function menu_colore(classe,colore){
	var as = document.getElementsByTagName("a:hover");
	var us = document.getElementsByTagName("ul:hover");
	for(i=0;i<as.length;i++){
   		if(as[i].className==classe) so_applyStyle(as[i],colore);
	} 
	for(i=0;i<us.length;i++){
   		if(us[i].className==classe) so_applyStyle(us[i],colore);
	} 
};

function font_size(fs) {
	document.getElementById("Body").style.fontSize=fs+"%";
	if (fs>76) {$('#contenitore').css({width: '1200px'});  } else { $('#contenitore').css({width: '1003px'});}
};

function contrasto_alto(f) {
	document.getElementById("Body").style.backgroundColor="#000000";
	document.getElementById("Body").style.color="#ffffff";
	font_size(120);
}; 


function contrasto_normale(f) {
	document.getElementById("Body").style.backgroundColor="#ffffff";
	document.getElementById("Body").style.color="#222222";
	font_size(100);
};



$(document).ready(
	function(){   
  		$("#navigator li").hover(
				function(){   
      				$(this).children('ul:first:hidden').css({visibility: "visible",display:'block'});},   
			    function(){   
   				   $(this).children('ul:first:visible').css({visibility: "hidden",display:'none'});}
  		);   

	}
	


 );  


var currentSheet, doc = window.document;

var activators = {
	onhover:{on:'onmouseover', off:'onmouseout'},
	onactive:{on:'onmousedown', off:'onmouseup'}
};

function parseStylesheets() {
	
	var sheets = doc.styleSheets, l = sheets.length;
	for(var i=0; i<l; i++) {
		parseStylesheet(sheets[i]);
	}
};
	function parseStylesheet(sheet) {
		var l, rules, imports;
		if(sheet.imports) {
			imports = sheet.imports, l = imports.length;
			for(var i=0; i<l; i++) {
				parseStylesheet(sheet.imports[i]);
			}
		}
		rules = (currentSheet = sheet).rules, l = rules.length;
		for(var j=0; j<l; j++) {parseCSSRule(rules[j]);}
	};

	function parseCSSRule(rule) {
		var select = rule.selectorText, style = rule.style.cssText;
		if(!(/(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i).test(select) || !style) return;
		
		var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
		var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
		var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
		var affected = select.replace(/:hover.*$/, '');
		var elements = getElementsBySelect(affected);

		currentSheet.addRule(newSelect, style);
		for(var i=0; i<elements.length; i++)
			new HoverElement(elements[i], className, activators[pseudo]);
	};

function HoverElement(node, className, events) {
	if(!node.hovers) node.hovers = {};
	if(node.hovers[className]) return;
	node.hovers[className] = true;
	node.attachEvent(events.on,
		function() { node.className += ' ' + className; });
	node.attachEvent(events.off,
		function() { node.className = 
			node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
};

function getElementsBySelect(rule) {
	var parts, nodes = [doc];
	parts = rule.split(' ');
	for(var i=0; i<parts.length; i++) {
		nodes = getSelectedNodes(parts[i], nodes);
	}	return nodes;
};
	function getSelectedNodes(select, elements) {
		var result, node, nodes = [];
		var classname = (/\.([a-z0-9_-]+)/i).exec(select);
		var identify = (/\#([a-z0-9_-]+)/i).exec(select);
		var tagName = (/^[a-z0-9]+/i).exec(select.toUpperCase()) || '*';
		for(var i=0; i<elements.length; i++) {
			result = elements[i].getElementsByTagName(tagName);
			if (result.length == 0 && tagName == "*")	// either no child elements, or getElementsByTagName("*") failed
			{
				result = ie_getElementsByTagName(elements[i],"*");
			}	
			for(var j=0; j<result.length; j++) {
				node = result[j];
				if((identify && node.id != identify[1]) || (classname && !(new RegExp('\\b' +
					classname[1] + '\\b').exec(node.className)))) continue;
				nodes[nodes.length] = node;
			}
		}	return nodes;
	};
	
function ie_getElementsByTagName(root,str) {
 // Map to the all collections
 if (str=="*") {return root.all;} else { return root.all.tags(str);}
 };

   function popup(nomefile,larghezza,altezza) {
      var w = larghezza;
      var h = altezza;
      var pw = Math.floor((screen.width-w)/2);
      var ph = Math.floor((screen.height-h)/2);
      window.open(nomefile,"","scrollbars=yes, width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);
   };
	function SelectFile( field, doc,descr ) {
		window.opener.SetTesto( field,doc,descr ) ;
		window.close() ;
	};
	
	
	




