// JavaScript Document

// Funzione di caricamento del search di Google

//function OnLoad() {
//
//  // Create a search control
//  var searchControl = new google.search.SearchControl();
//  
//  //Create a searcher
//  var siteSearch = new google.search.WebSearch();
//  
//  //Set search scope within www.divesouthafrica.co.za
//  siteSearch.setSiteRestriction("divesouthafrica.co.za");
//  
//  // Add the searcher to the search control
//  searchControl.addSearcher(siteSearch);
//  
//  // create a drawOptions object
//  var drawOptions = new google.search.DrawOptions();
//  drawOptions.setSearchFormRoot(document.getElementById("searchform"));
//
//  // Tell the searcher to draw itself and tell it where to attach
//  var element = document.getElementById("searchform");
//  searchControl.draw(element, drawOptions);
//}

// Funzione di pre-load delle immagini

function FP_preloadImgs() 
{//v1.0
 var d=document,a=arguments; 
 if(!d.FP_imgs) 
 	d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) 
 { 
 	d.FP_imgs[i]=new Image; 
	d.FP_imgs[i].src=a[i]; 
	}
}

// funzione che visualizza lo slide-show

function runSlideShow(){
   if (document.all){
      document.images.Slideshow.style.filter="blendTrans(duration=2)";
      document.images.Slideshow.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.Slideshow.filters.blendTrans.Apply();
   }
   document.images.Slideshow.src = preLoad[j].src;
   if (document.all){
      document.images.Slideshow.filters.blendTrans.Play();
   }
   j = j + 1;
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}

//---------------- Start Photogallery----------------------------------------------------------------------------------------------

// Gruppo di funzioni che caricano un documento XML contenente una lista di immmagini e da esso generano una photogallery e la relativa paginazione

function loadXMLDoc(dname) 
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e) {alert(e.message)}
  }
try 
  {
  xmlDoc.async=false;
  xmlDoc.load(dname);
  return(xmlDoc);
  }
catch(e) {alert(e.message)}
return(null);
}

function loadPhotogallery(dname, numimg)
{
	xmlDoc=loadXMLDoc(dname);
	dir = "Pictures";
	if (window.location.search)
	{
		url = window.location.search;
		beginposition = url.lastIndexOf('=')+1;
		numpage = parseInt(url.substr(beginposition));
	}
	else
		numpage = 1;
	firstimg = ((numpage-1)*numimg);
//	dir=xmlDoc.documentElement.attributes;
	x=xmlDoc.getElementsByTagName("fileName");
	y=xmlDoc.getElementsByTagName("title");
	w=xmlDoc.getElementsByTagName("width");
	h=xmlDoc.getElementsByTagName("height");
	if ((x.lenght-firstimg)<numimg)
	{numimg==(x.length-firstimg);}	
	for (i=firstimg;i<(firstimg+numimg);i++)
	  { 
		fileName=x[i].childNodes[0].nodeValue;
		title=y[i].childNodes[0].nodeValue;
		width=w[i].childNodes[0].nodeValue;
		height=h[i].childNodes[0].nodeValue;
		document.write('<div class="photo">');
		if (width>height) 
		{
			document.write('<a href="' + dir + '/' + fileName + '" rel="lightbox[dives]" title="' + title + '"><img src="' + dir + '/' + fileName + '"" width=156 height=104 /></a>');
		}
		else
		{		
			document.write('<a href="' + dir + '/' + fileName + '" rel="lightbox[dives]" title="' + title + '"><img src="' + dir + '/' + fileName + '"" width=104 height=156 /></a>');
		}
		document.write('<p>'+ title + '</p>');
		document.write('</div>');	
	  }
}

function writeNavBar(k)
{
	dir = document.title;
	if (window.location.search)
	{
		url = window.location.search;
		beginposition = url.lastIndexOf('=')+1;
		numpage = parseInt(url.substr(beginposition));
	}
	else
		numpage = 1;
	document.write('<div id="nav-bar">');
	for(i=1; i<=k; i++) //k deve valere il numero totale di pagine
	{
		if (i==numpage)
		{
			document.write('<a href="photogallery.html?page=' + i + '" style="background-color:#A9D8FF">' + i + '</a>');
		}
		else
		{
			document.write('<a href="photogallery.html?page=' + i + '">' + i + '</a>');
		}
	}
	if (numpage > 0)
	{
		document.write('<a href="photogallery.html?page=' + (numpage-1) + '">Back</a>');
	}
	if (numpage != k)
	{
		document.write('<a href="photogallery.html?page=' + (numpage+1) + '">Next</a>');
	}
	document.write('</div>');		
}
//----------------------- End Photogallery --------------------------------------------------------------------------------------------------

// funzione che apre un pop-up

function Popup(file, width, height) 
{
	var stile = "top=10, left=10, width=" + width + ", height=" + height + ", status=no, menubar=no, toolbar=no, scrollbar=no, resizable=no";
	/*var stile = "top=10, left=10, status=no, menubar=no, toolbar=no, scrollbar=yes";*/
    window.open(file, "", stile);
}

function startPopInfo(PopInfo)
{
var desktop=window.open(PopInfo,"_blank","toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=794,height=450");
}