// JavaScript Document
	function Photo(){
		this.image;
		this.caption;
	}
	function Photolist(){
		this.listarray = new Array();
		this.currentIndex = 0;
	}
	
	var currentAlbum;
	var photodivstring_alt;
	function getalbumthumbs(whichAlbum){
		currentAlbumid=whichAlbum;
		
		if(whichAlbum==0){
			document.getElementById('thumbdisplay').innerHTML='<br><br><br><br><br><br>No Photos Albums';
			return;
		}
		document.getElementById('thumbdisplay').innerHTML="<br><br><br><br><br><br><img src='" + scriptroot + "/images/loading.gif'>";
		AJAXObject=AJAXrequest();
		AJAXObject.onreadystatechange=function(){
			if(AJAXObject.readyState == 4){
				//alert(AJAXObject.getAllResponseHeaders());
				currentAlbum = null;
				currentAlbum = new Photolist();
				
				response = AJAXObject.responseXML;
				albuminfo=response.getElementsByTagName("albuminfo");
				album=response.getElementsByTagName("photo");
				albumname = albuminfo[0].childNodes[0].childNodes[0].nodeValue;
				
				albuminfostring = "<h2>Album: \"" +albumname+ "\"</h2>";
				photodivstring = "<div class='thumblist'>";
				
				photodivstring_alt = "<div id='thumblist_alt'>";
				
				var numphotos=album.length;
				var hcount=0;
				var vcount=0;
				for (i=0; i<numphotos; i++){
					var thumbnail = album[i].childNodes[0].childNodes[0].nodeValue;
					var thumbnail2 = album[i].childNodes[1].childNodes[0].nodeValue;
					var photourl = album[i].childNodes[2].childNodes[0].nodeValue;
					
					currentAlbum.listarray[i]=photourl;
					
					var divX=hcount*80;
					var divY=vcount*75;
					hcount++;
					if(hcount==4){
						hcount=0;
						vcount++;
					}
					photodivstring += "<div id='image" +i+ "' class='thumbpic' onclick='displayphoto(" + i + ")'>";
					photodivstring +=  "<img class='tpic' src='" + thumbnail + "'/>";
					photodivstring += "</div>";
					
					//photodivstring_alt += "<div id='image" +i+ "' class='thumbpic' onclick='displayphoto(" + i + ")'>";
					photodivstring_alt += "<img class='tpic' src='" + thumbnail2 + "' onclick='displayphoto(" + i + ")' />";
					
					
					
				}
				photodivstring += "</div>";
				
				photodivstring_alt += "</div>";
				
				document.getElementById('thumblist_alt_wrapper').innerHTML=photodivstring_alt;
				document.getElementById('albuminfodisplay').innerHTML=albuminfostring;
				document.getElementById('thumbdisplay').innerHTML=photodivstring;
			}
		}
		
		params="whichAlbum=" + whichAlbum;
		url = scriptroot+"/classes/Modules/Photos/photos.ajax.php";
		AJAXObject.open("GET", url + "?" + params, true);
		AJAXObject.setRequestHeader("Connection", "close");
		AJAXObject.send();
	}
	function openpanel(){
		document.getElementById("photowrapper").style.display='block';
		//document.getElementById("photowrapper").innerHTML += photodivstring_alt
	}
	function closepanel(){
		document.getElementById("photowrapper").style.display='none';
	}
	function nextimage(){
		total =currentAlbum.listarray.length;
		current = currentAlbum.currentIndex;
		
		if(current+1 < total){
			 displayphoto(current+1);
		}
	}
	function previmage(){
		total =currentAlbum.listarray.length;
		current = currentAlbum.currentIndex;
		
		if(current-1 >= 0){
			 displayphoto(current-1);
		}
	}
	
	var tempimage;
	function displayphoto(photoindex){
		openpanel();
		document.getElementById('photo_status').innerHTML="<img src='" + scriptroot + "/images/loakinghorz.gif'>";
		currentAlbum.currentIndex=photoindex;
		imagePanel=document.images['imagetag'];
		if(tempimage){delete tempimage;}
		tempimage = new Image;
		tempimage.src = currentAlbum.listarray[photoindex];
		$("#thumblist_alt > img").removeClass("thumbalt_selected");
		$("#thumblist_alt > img").addClass("thumbalt_not");
		$("#thumblist_alt > img").eq(photoindex).addClass("thumbalt_selected");
		loadTest(tempimage);
	}	
	function loadTest(tempimage){
		if(tempimage.complete){
			image_loaded_show(tempimage);
		}else{
			testimage = setTimeout('loadTest(tempimage)',1000);
		}
	}
	function image_loaded_show(tempimage){
		imagePanel=document.images['imagetag'];
		imagePanel.src = tempimage.src;
		
		document.getElementById('photo_status').innerHTML = (currentAlbum.currentIndex+1) + " of " + currentAlbum.listarray.length;
		var targetH = 500;
		var targetW = 700;
		
		thisheight=tempimage.height;
		thiswidth=tempimage.width;
		
		if(thisheight>targetH){	
			// the idea here is to get the scale value from image to target and then applying scale value to image
			scaleH=thisheight/targetH;
			thisheight=thisheight/scaleH;
			thiswidth=thiswidth/scaleH;	
			if(thiswidth>targetW){
				scaleW=thiswidth/targetW;
				
				thisheight=thisheight/scaleW;
				thiswidth=thiswidth/scaleW;
			}
		}
		if(thiswidth > targetW){
			//alert('changing in height')
			scaleW=thiswidth/targetW;
			thisheight=thisheight/scaleW;
			thiswidth=thiswidth/scaleW;
			if(thisheight > targetH){			
				scaleH=thisheight/targetH;
				
				thisheight=thisheight/scaleH;
				thiswidth=thiswidth/scaleH;
			}
		}

		leftValue=(699 - thiswidth) * .5;
		topValue=(499 - thisheight) * .5;
		
		imagePanel.height=thisheight;
		imagePanel.width=thiswidth;
		document.getElementById('photoPanel').style.height=thisheight;
		document.getElementById('photoPanel').width=thiswidth;
		document.getElementById('photoPanel').style.top=topValue +'px';
		//document.getElementById('photoPanel').style.left=leftValue +'px';
		
		//alert(document.getElementById('photoPanel').style.left + "leftValue: " + leftValue)
		//alert(document.getElementById('photoPanel').style.top + "topValue: " + topValue)
	}
	function showalbumdiv(whichdiv){
		if(document.getElementById(whichdiv).style.display == 'none'){
			document.getElementById(whichdiv).style.display = 'block';
		}else{
			document.getElementById(whichdiv).style.display = 'none';
		}
	}


