function showPhoto(which,caption,w,h,level)
{	
  var x = (screen.width - (w+50)) / 2;
  var y = (screen.height - (h+75)) / 2;

  var html = "";
  var imgsrc = level==1 ? "../" : "";
  imgsrc = imgsrc + "images/photos/" + which + ".jpg";
  var winFeatures = "width=" + (w+50) + ",height=" + (h+75) + ",left="+ x + ",top=" + y;
  //alert(winFeatures);
  if(level == 1)
	  html = html + "<html>\r\n<head>\r\n  <title>Dolce Roma - Foto Gallery</title>\r\n";
  else
	  html = html + "<html>\r\n<head>\r\n  <title>Dolce Rome - Photo Gallery</title>\r\n";	  
  
  html = html + "</head>\r\n<body TEXT='#000000' BGCOLOR='#FFFFFF'>\r\n";
  html = html + "<p align='center'><table border='0' width='" + w + "'><tr><td width='75%'align='left'><font face='Arial'>"+ caption + "</font></td><td width='25%' align='right' valign='top'><font face='Arial'>";
  if(level == 1)
  	html = html + "<a href='javascript:self.close();'>Chiudi</a></font></td></tr></table>\r\n"; 
  else
  	html = html + "<a href='javascript:self.close();'>Close</a></font></td></tr></table>\r\n"; 
  html = html + "<img src='" + imgsrc + "' width='" + w + "' height='" + h + "' border='1'>\r\n</body>\r\n</html>\r\n";
  
  //html = html + "<img src='" + imgsrc + "' width='" + w + "' height='" + h + "' border='1'><br><font face='Arial'>" + caption + "</p>";
  //html = html + "<p> </p><p align='right'><a href='javascript:self.close();'>Close</a></p></font>\r\n</body>\r\n</html>\r\n";
    
  popWindow = open("","photos",winFeatures);
  popWindow.document.open();
  popWindow.document.writeln(html);
  popWindow.document.close();
  popWindow.opener = self;
  popWindow.focus();

}

function imageitem(level,which)
{
	this.images = new Array();
	
	path = level==1 ? "../" : "";
	for(i = 1; i < 3; i++) {   
		this.images[i] = new Image();   
		this.images[i].src = path + "images/common/" + which + i + ".jpg";
	}
	this.counter = 2;
}	
function animate(cnt,imgTag) 
{   
	theImageItem = animations[cnt];
	imgTag.src = theImageItem.images[theImageItem.counter].src;
	
	theImageItem.counter++
	if(theImageItem.counter>2)
		theImageItem.counter = 1;
}

function showImagePopup(which,level,theType,caption,w,h)
{	
  var x = (screen.width - (w+50)) / 2;
  var y = (screen.height - (h+75)) / 2;

  var html = "";
  var imgsrc = "";
  var winFeatures = "width=" + (w+50) + ",height=" + (h+75) + ",left="+ x + ",top=" + y;
  
  for(i=0;i<level;i++)
	{
		imgsrc += "../";
	}
  imgsrc += "images/common/" + theType + "/" + which + ".jpg";
  
  //alert(winFeatures);
  html = html + "<html>\r\n<head>\r\n  <title>Villa di Collina - Photo Gallery</title>\r\n";
  html = html + "</head>\r\n<body TEXT='#003366' BGCOLOR='#FFFFFF'>\r\n";
  html = html + "<p align='center'><table border='0' width='" + w + "'><tr><td width='50%'align='left'><font face='Arial'>"+ caption + "</font></td><td width='50%'align='right'><font face='Arial'><a href='javascript:self.close();'>Close</a></font></td></tr></table>\r\n"; 
  html = html + "<img src='" + imgsrc + "' width='" + w + "' height='" + h + "' border='1'>\r\n</body>\r\n</html>\r\n";
  
  //html = html + "<img src='" + imgsrc + "' width='" + w + "' height='" + h + "' border='1'><br><font face='Arial'>" + caption + "</p>";
  //html = html + "<p> </p><p align='right'><a href='javascript:self.close();'>Close</a></p></font>\r\n</body>\r\n</html>\r\n";
    
  popWindow = open("","photos",winFeatures);
  popWindow.document.open();
  popWindow.document.writeln(html);
  popWindow.document.close();
  popWindow.opener = self;
  popWindow.focus();

}

function showPopup(which,w,h)
{
	
  popWindow = open(which,"popup","width=" + w + ",height=" + h);
  popWindow.opener = self;
  popWindow.focus();

}

function initPage(which,level,theLang)
{
	
	setSelButton(which,level,theLang);
}

function turnAllOff(level,theLang)
{
	setButton('home',level,theLang,"off");
	setButton('about_villa',level,theLang,"off");
	setButton('about_tuscany',level,theLang,"off");
	setButton('photo_gallery',level,theLang,"off");
	setButton('rental_rates',level,theLang,"off");
	setButton('booking',level,theLang,"off");
	setButton('links',level,theLang,"off");
	setButton('contact',level,theLang,"off");
	
	
}

function setSelButton(which, level, theLang)
{
	
	turnAllOff(level,theLang);
	if(which != "" && document.images[which])
	{
		document.images[which].src = buildPath(which,level,theLang,"sel");
	}
	
}


function preLoad(which, level, lang, setting)
{
	theImage = new Image();
	//alert(buildPath(which, level, lang, setting));
	theImage.src = buildPath(which, level, lang, setting);
	return(theImage);
}

function turnOn(which, level, lang)
{
	if(isSel(which))
		return;
	//alert(buildPath(which, level, lang, "on"));
	setButton(which, level, lang, "on");
}

function turnOff(which, level, lang)
{
	
	if(isSel(which))
		return;
	//alert(buildPath(which, level, lang, "on"));
	setButton(which, level, lang, "off");
}

function setButton(which, level, lang, setting)
{	
	//alert(buildPath(which, level, lang, setting));
	document.images[which].src = buildPath(which, level, lang, setting);
}


function buildPath(which, level, lang, setting)
{
	path = "";

	for(i=0;i<level;i++)
	{
		path += "../";
	}

	path +=	"images/" + 
		(lang==null?"":lang) +
		(lang==null?"":"/") +
		which + 
		(setting==null?"":"_"+setting) +
		".gif";
	return(path);
}


function replaceImage(which,imgName)
{
	document.images[which].src = "../images/" + imgName + ".gif";
}

/* determines if button is selected in order to disable/enable mouseover functions*/
function isSel(which)
{
	if(document.images[which] &&
	   document.images[which].src &&
	   document.images[which].src.indexOf("_sel") == -1)
		return false;
	else
		return true;	

}


