/*
 */
 var maxwidth=480;
 var maxheight=300;
 var maxwidththumb=100;
 var maxheightthumb=100;
 
 function runonload(){
	 //alert("xxxxx");
	 //sizeall();
	 showimage(0);
 }
 function sizeall(){
	 var obj=document.getElementById("imgMainDisplay");
	 //alert(obj.id);
	 scaleImage(obj,maxwidth,maxheight);

	 var done=0;
	 var idx=0;
	 var obj;
	 while (done==0){
		 try {
			 obj=document.getElementById("imgStore"+idx);
//alert(obj.id);
			 scaleImage(obj,maxwidth,maxheight);
			 obj=document.getElementById("imgThumbStore"+idx);
			 scaleImage(obj,maxwidththumb,maxheightthumb);
		 }catch(e){
			 done=1;
		 }
		 idx++;
	 }
	 
			 
 }
 var scrollid=0;
 function movethumbnails(direction){
	 if (direction=="left"){
		 if (displayid>0){
			 showimage(displayid-1);
		 }
	 }else{
		 if (displayid<(imagecount-1)){
			 showimage(displayid+1);
		 }
	 }
 }
 function setThumbnail(id){
	 var start,end;
	 //slots=3;
	 //if (imagecount<3) slots=imagecount;
	 downoffset=Math.floor(slots/2);
	 upoffset=Math.ceil(slots/2);
	 start=id-downoffset;
//	 end=start+(slots-1);
//alert(id+" "+downoffset+" "+slots+" "+imagecount+" "+start+" "+end);	 
	 if (start<0){
		start=0;
//		end=slots-1;
	 }
	 if((start+slots)>imagecount){
		 start=imagecount-slots;
	 }
//	 if (end>=(slots+1)){
//		 end=imagecount+1;
//		 start=end-(slots+1);
//	 }
//alert(id+" "+downoffset+" "+upoffset+" "+start+" "+end);	 
/*	 if (id==0){
		start=0;
		end=slots;
	 }else if(id==imagecount){
		 start=(imagecount-slots)+1;
		 end=imagecount;
	 }else{
		 start=id-1;
		 end=id+1;
	 }
*/	 for (var i=0; i<slots; i++){
		 //var src=document.getElementById("imgThumbStore"+i);
		
		 var obj=document.getElementById("thumb"+i);
		 //obj.style.height=src.clientHeight;
		 //obj.style.width=src.clientWidth;
		 obj.src=thumblist[start+i];
		 obj.alt=alttext[start+i];
		 obj.title=alttext[start+i];
//alert(thumblist[start+i]); 
		 obj.setAttribute("imageid",start+i);
//alert(obj.id+" - "+obj.getAttribute("imageid"));		 
		 if (start+i==id) highlightThumbnail(i);
			 
	 }
		 
 }
 var displayid=-1;
 function showimage(id){
	 displayid=id;
	 var obj=document.getElementById("imgMainDisplay");
	 setThumbnail(id);
	 obj.src=watermarkedlist[id];
	 document.getElementById("divMainTitle").innerHTML=alttext[id];
	 //document.getElementById("divMainInfo").innerHTML=desctext[id];
//scaleImage(obj, maxwidth, maxheight);
 }
 function showfullimage(){
	 //window.open('http://www.aquaecnic.info/images/Gallery/'+imagelist[displayid],'_gallery','menubar=no;toolbar=no;');
//alert("new window");
	 //window.open(imagelist[displayid],'_gallery','');
	 window.open('http://www.aquatecnic.info/showimage.php?iu='+imagelist[displayid]+'&it='+alttext[displayid]+'','_gallery','');
 }
 /*
//alert(id);
	 var src=document.getElementById("imgStore"+id);
	
	 var obj=document.getElementById("imgMainDisplay");
	 obj.style.height=src.clientHeight;
	 obj.style.width=src.clientWidth;
	 obj.src=imagelist[id];
	 var info=src.getAttribute("info");
	 //info.replace("///gi;","");
	 var exp=/_/gi;
	 
	 info=info.replace(exp,"\"");
	 var exp=/~/gi;
	 info=info.replace(exp,">");
	 var exp=/\^/gi;
	 info=info.replace(exp,"<");
	 //alert(info);
	 document.getElementById("divMainInfo").innerHTML=info;
	 setThumbnail(id);
	 //scaleImage(obj);
 }*/
 function highlightThumbnail(showing){
	 for (var i=0;i<slots;i++){
		 document.getElementById("thumb"+i).style.borderStyle="solid";
		 document.getElementById("thumb"+i).style.borderColor="white";
	 }
	 document.getElementById("thumb"+showing).style.borderStyle="solid";
	 document.getElementById("thumb"+showing).style.borderColor="black";
 }
 function scaleImage(obj,maxwidth,maxheight){
	 //alert("scaleImage");
	//alert(obj.clientWidth+" - "+obj.clientHeight+" : "+obj.parentNode.clientWidth+" - "+obj.parentNode.clientHeight);
	 var realh=obj.clientHeight;
	 var realw=obj.clientWidth;
	 //alert("scaleImage 2 "+obj.parentNode.id);
	 
	 var parenth=obj.parentNode.clientHeight-10;
	 var parentw=obj.parentNode.clientWidth-10;
	 var parenth=maxheight;
	 var parentw=maxwidth;
	 //alert("scaleImage 3 "+parenth+" "+parentw+" "+obj.parentNode.id);
	 var proph=parenth/realh;
	 var propw=parentw/realw;
	 //alert("scaleImage 4");
	 var prop=propw;
	 if (proph<propw){
		 prop=proph;
	 }
	alert(realw+" - "+realh+" - "+parentw+" - "+parenth+" - "+propw+" - "+proph+" - "+prop);
	obj.style.height=realh*prop;
	obj.style.width=realw*prop;
	alert(obj.style.width+" - "+obj.style.height);
 }
 

