var htmlStore = null;
// images
imgs = new Array();
	
//thumbs
var thumbId = 0;
	
var currImg = null;
	
var imgShown = false;

function registerImg(theURL, theCap, theUid, theIndex, w, h){

	if(imgs[theUid+""] == undefined){
		imgs[theUid+""] = new Array();
		
	}
	if (imgs[theUid+""][theIndex] == undefined){
		imgs[theUid+""][theIndex] = new Array(theURL, theCap, w, h);
	}
}
	
// define id for thumbnails
function defineId(id){
	thumbId = id;
}

var lastScroll = 0;

		  function popDiv(theURL, theCap, theUid, theIndex, w, h, ex, historyMode, callr){
		  				
		  	imgShown = true;

			var div = $("showPic");
			
			var cc  = $("contentContainer");
			var hcc   = cc.getSize().y;
			if(hcc > h)	div.setStyle('height', hcc + 'px');
			
		  	var htm = "<table cellpaddin='0' cellspacing='0'>";
		  	htm  += "<tr><td class='caption'>";
		  	htm  += "<div id='prevNext'><span id='prevImg'></span>";
			htm += "<a href='javascript:hidePic();' id='closeImg'>close</a>";
		  	htm += "<span id='nextImg'></span></div>";
		  	htm += theCap+"</td></tr>";
		  	htm += "<tr><td class='img'><a href='javascript:hidePic();'><img border='0' src='" + theURL + "'width='"+w+"' height='"+h+"'/></a></td></tr>";
		  	htm += "</table>";
		  	
		    
		    // add img link to next
		    var nIndex = 0;
			
		    if((theIndex + 1) < imgs[theUid].length){
		      nIndex = theIndex + 1;
		    }
		  	var nURL = imgs[theUid][nIndex][0];
		  	var nCap = imgs[theUid][nIndex][1];
		  	var w = imgs[theUid][nIndex][2];
		  	var h = imgs[theUid][nIndex][3];
		  	

			div.set('html', htm);
			
		  	div.setStyle('display', 'block');
			
		  	if(htmlStore == null) htmlStore = document.getElementById("contentContainer").innerHTML;
			
		  	document.getElementById("contentContainer").innerHTML = "";
		  	document.getElementById("prevNext").style.display = "block";
		  	
		  	
		  	if (theIndex > 0){
		  		writePrevNext(theUid, theIndex-1, "prevImg", "previous");
		  	}
		  			  	
		  	if((theIndex + 1) < imgs[theUid].length){
		  		writePrevNext(theUid, theIndex+1, "nextImg", "next");
		  	}
		  	
		  	var wScroll = window.getScroll();
		  	if(wScroll.y > 0) {
		  		lastScroll = wScroll.y;
		  		var myFx = new Fx.Scroll(window, {duration: 900}).toTop();
			}
		  }


function writePrevNext(theUid, theIndex, direction, theString){
  	var s = document.getElementById(direction);
  	if(imgs[theUid][theIndex] == undefined) return;
	var theURL = imgs[theUid][theIndex][0];
  	var theCap = imgs[theUid][theIndex][1];
  	var w = imgs[theUid][theIndex][2];
  	var h = imgs[theUid][theIndex][3];
		  	
  	s.innerHTML="<a href=\"javascript:popDiv('"+ theURL+"', '"+ theCap+"', '"+theUid+"', "+theIndex+", "+w+", "+h+");\">"+theString+"</a>";
		  }
		  
function hidePic(){
	  var div = document.getElementById("showPic");
	  div.innerHTML = "";
	  div.style.display = "none";
	  document.getElementById("contentContainer").innerHTML = htmlStore;
	  
	  if(lastScroll > 0){
	  	var myFx = new Fx.Scroll(window, {duration: 900}).start(0,lastScroll);
	  	lastScroll = 0;
	  }
}