  var ids = new Array();
  var curid = 0;
  
  function openViewPhotoGallery(id){
  	curid = id;
  	scroll(0,0);
  	document.getElementsByTagName("body")[0].style.overflow = "hidden";
  	document.getElementById("mask").style.display = "";
  	document.getElementById("photoDesign").style.display = "";
  	if (curpos()!=0)
  		document.getElementById("previousPhoto").style.visibility = 'visible';
  	else
  		document.getElementById("previousPhoto").style.visibility = 'hidden';
  	if (curpos()!=ids.length-1)
  		document.getElementById("nextPhoto").style.visibility = 'visible';
  	else
  		document.getElementById("nextPhoto").style.visibility = 'hidden';

  	document.getElementById("indexPhoto").innerHTML = (curpos()+1)+" / "+ids.length;
  	document.getElementById("photoDesign").appendChild(document.getElementById(id));
  	document.getElementById(id).style.display= "";
  }
  
  function closeViewPhotoGallery(){
  	document.getElementsByTagName("body")[0].style.overflow = "auto";
  	document.getElementById("mask").style.display = "none";
  	document.getElementById("photoDesign").style.display = "none";
  	document.getElementsByTagName("body")[0].appendChild(document.getElementById(curid));
  	document.getElementById(curid).style.display= "none";
  	curid=0;
  }
  
  function curpos(){
	var curpos = 0;
  	for(var i=0; i<ids.length; i++){
  	    if (ids[i]==curid){
  	    	curpos = i;
  	    }
	}
	return curpos;
  }
  
  function changePhoto(pos){
	var call = 0;
  	for(var i=0; i<ids.length; i++){
  	    if (i==curpos()+pos){
  	    	call = ids[i];
  	    }
	}
	if (call != 0){
		closeViewPhotoGallery();
		openViewPhotoGallery(call);
	}
  }
  
  function Initiate(){
	  var span = document.createElement('span');
	  span.appendChild(document.createTextNode(' '));
	  span.setAttribute('id',"mask");
	  span.className="PhotoGalleryMask";
	  span.style.width = "100%";
	  span.style.height = "100%";
	  span.style.top = "0";
	  span.style.left = "0";
	  span.style.display = "none";
	  document.getElementsByTagName("body")[0].appendChild(span);
	  
	  var span = document.createElement('span');
	  span.appendChild(document.createTextNode(' '));
	  span.setAttribute('id',"photoDesign");
	  span.className="PhotoGallery";
	  span.style.top = "50%";
	  span.style.left = "50%";
	  span.style.width = "650px";
	  span.style.height = "670px";
	  span.style.marginTop = "-335px";
	  span.style.marginLeft = "-325px";
	  span.style.display = "none";
	  span.style.paddingTop = "0.5em";
	  document.getElementsByTagName("body")[0].appendChild(span);

	  var span = document.createElement('span');
	  span.appendChild(document.createTextNode('<<'));
	  span.setAttribute('id',"previousPhoto");
	  span.setAttribute('onClick',"changePhoto(-1);");
	  span.className="PhotoGalleryPreviousPhoto";
	  span.style.top = "40%";
	  span.style.left = "-1em";
	  document.getElementById("photoDesign").appendChild(span);

	  var span = document.createElement('span');
	  span.appendChild(document.createTextNode('>>'));
	  span.setAttribute('id',"nextPhoto");
	  span.setAttribute('onClick',"changePhoto(1);");
	  span.className="PhotoGalleryNextPhoto";
	  span.style.top = "40%";
	  span.style.right = "-1em";
	  document.getElementById("photoDesign").appendChild(span);

	  var span = document.createElement('span');
	  span.appendChild(document.createTextNode('x'));
	  span.setAttribute('id',"closePhoto");
	  span.setAttribute('onClick',"closeViewPhotoGallery();return false;");
	  span.className="PhotoGalleryClosePhoto";
	  span.style.top = "-1em";
	  span.style.right = "-3.5em";
	  document.getElementById("photoDesign").appendChild(span);

	  var span = document.createElement('span');
	  span.setAttribute('id',"indexPhoto");
	  span.setAttribute('onClick','closeViewPhotoGallery();return false;');
	  span.className="PhotoGalleryIndexPhoto";
	  span.style.top = "99%";
	  span.style.left = "-42%";
	  document.getElementById("photoDesign").appendChild(span);
  }
  
  	function startPhotoGallery() {
  		var tag = new Array();
	  	tag = document.getElementsByTagName("div");
	  	var j = 0;
	  	for (var i=0; i < tag.length; i++){
	  		if (tag[i].getAttribute("name")=="PhotoGallery"){
		  		tag[i].style.display="none";
				ids[j] = tag[i].id;
				document.getElementById('img'+ids[j]).style.cursor = "pointer";
				document.getElementById('img'+ids[j]).setAttribute('onClick', "openViewPhotoGallery("+ids[j]+");return false;");
				j++;
			}
	  	}
	  	if (j>0) Initiate();
	  	return false;
	}
  	
  	if (document.addEventListener) // For Firefox 
  		document.addEventListener("DOMContentLoaded", startPhotoGallery, false); // Call init function in Firefox 
  	else if(window.attachEvent)
  		window.attachEvent('onload', startPhotoGallery);
  	


