function loadAll(page) {
	 if (document.getElementById('google_map')!=null)
		initialize_gmaps();
	
	 if (document.getElementById('fotogallery')!=null)
		initialize_photos();
	
	makeNewsRotate("scroll_news");
	makeNewsRotate("scroll_appuntamenti");
	
}

function assegnaXMLHttpRequest() {
	var XHR = null,
	browserUtente = navigator.userAgent.toUpperCase();

	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();
	else if( window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0 ) {
		if(browserUtente.indexOf("MSIE 5") < 0)
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}

 return XHR;
} 

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}

function createElementAndAttributes(el, attributes, content) {
	var element=document.createElement(el);
	if (attributes!=undefined && attributes!=null) {
		for (k in attributes) {
			element.setAttribute(k,attributes[k]);
		}
	}
	if (content!=undefined && content!=null && content!="") {
		var contenuto=document.createTextNode(content);
		element.appendChild(contenuto);
	}
	return element;
}

function addbookmark() {
	if (document.all) 
		window.external.AddFavorite(location.href,document.title);
	else if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');
	
	
}
function initialCap(text) {
   return text.substr(0, 1).toUpperCase() + text.substr(1);
}


var automatic_moving=null;
var num_photos=0;
var current_photo=0;
var array_foto=null;
var automatic=true;

function initialize_photos() {
	var photos=document.getElementById("photo_place");
	if (photos!=undefined && photos!=null) {
		array_foto=photos.getElementsByTagName("img");
		num_photos=array_foto.length;
	}
	startTimer();
}


function setCurrentPhoto(i) {
	array_foto[current_photo].style.zIndex=0;
	current_photo=i;
	array_foto[current_photo].style.zIndex=10;
	
	var num_foto=document.getElementById("scritta_foto");
	if (num_foto!=null) {
		var tot=num_foto.innerHTML.split(" ")[2];
		num_foto.innerHTML=(i+1)+" di "+tot;
		
		var num_foto=document.getElementById("elenco_foto").getElementsByTagName("img");
		for (var k=0; k<num_foto.length; k++) {
			num_foto[k].src="./theme/polaroid_dot.png";
			if (i==k) num_foto[k].src="./theme/polaroid_dotselected.png";
		}
	}
}

function next_photo(automatic) {
	var i=current_photo+1;
	if (i>=num_photos) i=0;
	setCurrentPhoto(i);
	if (automatic==undefined || automatic==false) stopTimer();
}

function prec_photo() {
	var i=current_photo-1;
	if (i<0) i=num_photos-1;
	setCurrentPhoto(i);
	stopTimer();
}

function play_pause() {
	if (automatic) {
		stopTimer();
	} else {
		startTimer();
	}
}

function stopTimer() {
	clearInterval(automatic_moving);
	automatic=false;
	//document.getElementById("playpausebtn").src="./theme/btn/play.png";
}

function startTimer() {
	automatic_moving=setInterval("next_photo(true)", 3000);
	automatic=true;
	//document.getElementById("playpausebtn").src="./theme/btn/pause.png";
}

