var ph = new Object;
ph['pictureTitle'] = new Object;
ph['pictureCaption'] = new Object;
ph['pictureThumbFileName'] = new Object;
ph['pictureSlideFileName'] = new Object;
ph['picturePrintFileName'] = new Object;
ph['picturePrintWidth'] = new Object;
ph['picturePrintHeight'] = new Object;
ph['pictureShootingDate'] = new Object;
ph['pictureSubject'] = new Object;
ph['pictureEvent'] = new Object;
ph['pictureLocation'] = new Object;
ph['pictureComment'] = new Object;
ph['picturePhotographer'] = new Object;
ph['cameraMake'] = new Object;
ph['cameraModel'] = new Object;
ph['cameraLens'] = new Object;
ph['cameraFocalLength'] = new Object;
ph['cameraFlash'] = new Object;
ph['cameraISOSpeed'] = new Object;
ph['cameraAperture'] = new Object;
ph['cameraShutterSpeed'] = new Object;
ph['cameraExposureCompensation'] = new Object;
ph['cameraResolution'] = new Object;
ph['cameraWhiteBalance'] = new Object;
ph['pictureColourType'] = new Object;
ph['extraTechnical1'] = new Object;
ph['extraTechnical2'] = new Object;
ph['extraTechnical3'] = new Object;
ph['extraTechnical4'] = new Object;
ph['extraTechnical5'] = new Object;
ph['extraInfo1'] = new Object;
ph['extraInfo2'] = new Object;
ph['extraInfo3'] = new Object;
ph['extraInfo4'] = new Object;
ph['extraInfo5'] = new Object;
ph['picturePrice1'] = new Object;
ph['picturePrice2'] = new Object;
ph['picturePrice3'] = new Object;
ph['picturePrice4'] = new Object;
ph['picturePrice5'] = new Object;
var galleryKeywordList = '';
var libraryKeywordList = '';
var pictureCount = 0;
var pictureLibrarySettings = new Object;
var blockSize = 4;
var pictureNumber = 5;
var thumbNumber = 1;
var searchType = 0;
var searchList = '';
var searchList2 = '';

function gotoThumb(thumbTarget){
  if (thumbNumber<thumbTarget){
    pictureRight(thumbTarget-thumbNumber);
  } else {
    pictureLeft(thumbNumber-thumbTarget);
  }
}
function restoreThumb(thumbNumber,pictureNumber){
	if ((x=findObj('divthumb' + thumbNumber)) !=null){
		newCode='<img onClick="gotoThumb('+thumbNumber+');" src="' + ph['pictureThumbFileName'][pictureNumber]+ '" alt="'+ph['pictureTitle'][pictureNumber]+'"';
		if (pictureLibrarySettings['scaleForThumb']==1){
 			newCode=newCode+' width="'+pictureLibrarySettings['thumbWidth']+'" height="'+pictureLibrarySettings['thumbHeight']+'" ';
		}
 		newCode=newCode+'>';
		x.innerHTML = newCode;
  }
}
function selectThumb(thumbNumber,pictureNumber){
  if ((x=findObj('divthumb' + thumbNumber)) !=null){
	 newCode = '<img onClick="gotoThumb('+thumbNumber+');" src="' + ph['pictureThumbFileName'][pictureNumber]+ '" style="border-style:double;border-width:1px;border-color:#FF9900;" alt="'+ph['pictureTitle'][pictureNumber]+'"';
	if (pictureLibrarySettings['scaleForThumb']==1){
 	  newCode=newCode+' width="'+pictureLibrarySettings['thumbWidth']+'" height="'+pictureLibrarySettings['thumbHeight']+'" ';
   	}
   	newCode=newCode+'>';
   	x.innerHTML = newCode;
   	setPictureTitles(pictureNumber);
  }
}
function html_entity_decode(parseString){
	if (parseString!=""){
		startString = parseString;
		parseString = parseString.replace(/&lt;/gi,'<');
		parseString = parseString.replace(/&gt;/gi,'>');
		parseString = parseString.replace(/&amp;/gi,'&');
		parseString = parseString.replace(/&quot;/gi,'"');
	}
	return parseString;
}
function setPictureTitles(pictureNumber){
 if ((x=findObj('divpicturePlace')) !=null){
 	newCode='<img src="' + ph['pictureSlideFileName'][pictureNumber] + '" alt="' + ph['pictureTitle'][pictureNumber]+ '"';
	if (pictureLibrarySettings['scaleForSlide']==1){
 	  newCode=newCode+' width="'+pictureLibrarySettings['slideWidth']+'" height="'+pictureLibrarySettings['slideHeight']+'"';
   	}
   	if (pictureLibrarySettings['showPrints']==1){
   	  newCode=newCode+' onClick="fullScreen();"';
   	}
   	newCode=newCode+'>';
 	x.innerHTML =  newCode;
 }
 if ((x=findObj('divtitleText'))!=null){
 	x.innerHTML = html_entity_decode(ph['pictureTitle'][pictureNumber]);
 }
 if ((x=findObj('divcaptionText'))!=null){
	 x.innerHTML = html_entity_decode(ph['pictureCaption'][pictureNumber]);
 }
// showPictureInfo(pictureNumber);
}
function showPictureInfo(pictureNumber){
 infoText = "";
 for (key in pictureLibrarySettings){
 	if (key.substring(0,3) == 'has'){
	 if (pictureLibrarySettings[key] == 1){
		checkField = key.substring(3,key.length);
		if (ph[checkField][pictureNumber] != ""){
		 infoText = infoText + '<span class="mediumText" style="font-weight:bold;">' + pictureLibrarySettings['title'+checkField] + '</span>';
	   infoText = infoText + '<div class="mediumText" id="' + checkField + 'Text" style="text-align:left;border-width:2px;border-style:outset;margin-bottom:5px;">';
  	 infoText = infoText + html_entity_decode(ph[checkField][pictureNumber]);
  	 infoText = infoText + '</div>';
  	}
	 }
	}
 }
	if ((x=findObj('arenaCopy3')) !=null){
 		x.innerHTML = infoText;
	}
}

function loadPicGallery(){
	if (pictureLibrarySettings['preloadImages'] == '1'){
		tmp = '';
		for (i=1;i<=pictureCount;i++){
			tmp = tmp + '<img src="' + ph['pictureThumbFileName'][i] + '" alt="">';
			tmp = tmp + '<img src="' + ph['pictureSlideFileName'][i] + '" alt="">';
			if (pictureLibrarySettings['showPrints'] == '1'){
				tmp = tmp + '<img src="' + ph['pictureSlideFileName'][i] + '" alt="">';
			}
		}
	  if ((x=findObj('divpictureStore'))!=null){
	  	x.innerHTML = tmp;
	  }
	}
}

function pictureLeft(moveCount){
 if (pictureNumber >1){
	restoreThumb(thumbNumber,pictureNumber);
  thumbNumber=thumbNumber-moveCount;
  if (thumbNumber>0){
   pictureNumber = pictureNumber - moveCount;
   selectThumb(thumbNumber,pictureNumber);
   if (pictureNumber == 1){
		if ((x=findObj('divpicLeft')) !=null){
		  x.style.visibility='hidden';
		}
   }
   if (pictureNumber < pictureCount){
		if ((x=findObj('divpicRight')) !=null){
	    x.style.visibility='visible';
		}
   }
  } else {
   thumbsLeft(1);
  }
 }
}
function pictureRight(moveCount){
 if (pictureNumber < pictureCount){
	restoreThumb(thumbNumber,pictureNumber);
  thumbNumber=thumbNumber+moveCount;
  if (thumbNumber<=blockSize){
   pictureNumber = pictureNumber + moveCount;
   selectThumb(thumbNumber,pictureNumber);
   if (pictureNumber > 1) {
		if ((x=findObj('divpicLeft')) !=null){
	    x.style.visibility='visible';
		}
   }
   if (pictureNumber == pictureCount) {
		if ((x=findObj('divpicRight')) !=null){
	    x.style.visibility='hidden';
		}
   }
  } else {
   thumbsRight();
  }
 }
}
function thumbsLeft(jumpFlag){
 currentBlockStart = parseInt((pictureNumber-1)/blockSize);
 if (currentBlockStart > 0){
  currentBlockStart = ((currentBlockStart-1)*blockSize)+1;
  counter=0;
  for (i=currentBlockStart;i<currentBlockStart+blockSize;i++){
   counter ++;
   if ((x=findObj('divthumb' + counter)) !=null){
	   if ((counter == 1 && jumpFlag==0) || (counter == blockSize && jumpFlag==1)){
  	  newCode = '<img onclick="gotoThumb('+counter+');" src="' + ph['pictureThumbFileName'][i]+ '" style="border-style:double;border-width:2px;border-color:#FF9900;" alt="'+ph['pictureTitle'][i]+'"';
 			if (pictureLibrarySettings['scaleForThumb']==1){
 				newCode=newCode+' width="'+pictureLibrarySettings['thumbWidth']+'" height="'+pictureLibrarySettings['thumbHeight']+'" ';
 			}
 			newCode=newCode+'>';
 			x.innerHTML = newCode;
   	} else {
    	newCode = '<img onclick="gotoThumb('+counter+');" src="' + ph['pictureThumbFileName'][i]+ '" alt="'+ph['pictureTitle'][i]+'"';
 			if (pictureLibrarySettings['scaleForThumb']==1){
 				newCode=newCode+' width="'+pictureLibrarySettings['thumbWidth']+'" height="'+pictureLibrarySettings['thumbHeight']+'" ';
 			}
 			newCode=newCode+'>';
 			x.innerHTML = newCode;
   	}
   }
  }
 }
 if (jumpFlag == 1){
  thumbNumber=blockSize;
  pictureNumber=currentBlockStart+blockSize-1;
 } else {
  thumbNumber=1;
  pictureNumber=currentBlockStart;
 }
 setPictureTitles(pictureNumber);
 if (pictureNumber == 1){
  if ((x=findObj('divpicLeft')) !=null){
	  x.style.visibility='hidden';
  }
 }
 if ((x=findObj('divpicRight')) !=null){
	if (pictureNumber < pictureCount && pictureCount > blockSize){
  	x.style.visibility='visible';
 	} else {
  	x.style.visibility='hidden';
 	}
 }
 if (pictureNumber <= blockSize){
  if ((x=findObj('divfastLeft')) !=null){
	  x.style.visibility='hidden';
  }
 }
 if ((x=findObj('divfastRight')) !=null){
	 if ((pictureNumber+blockSize-1) < pictureCount && pictureCount > blockSize){
  	x.style.visibility='visible';
 	} else {
  	x.style.visibility='hidden';
 	}
 }
}
function thumbsRight(){
 currentBlockStart = parseInt((pictureNumber-1)/blockSize);
 if (currentBlockStart+blockSize <= pictureCount){
  currentBlockStart = ((currentBlockStart+1)*blockSize)+1;
  counter=0;
  for (i=currentBlockStart;i<currentBlockStart+blockSize;i++){
   counter ++;
	 if ((x=findObj('divthumb'+counter)) !=null){
	   if (counter == 1){
  	  newCode = '<img onclick="gotoThumb('+counter+');" src="' + ph['pictureThumbFileName'][i]+ '" style="border-style:double;border-width:2px;border-color:#FF9900;" alt="'+ph['pictureTitle'][i]+'"';
 			if (pictureLibrarySettings['scaleForThumb']==1){
 				newCode=newCode+' width="'+pictureLibrarySettings['thumbWidth']+'" height="'+pictureLibrarySettings['thumbHeight']+'" ';
 			}
 			newCode=newCode+'>';
 			x.innerHTML = newCode;
   	} else if ((currentBlockStart+counter-1)>pictureCount) {
    	x.innerHTML = '<img onclick="gotoThumb('+counter+');" src="' + pictureImageLibrary + 'blackBox.jpg>"';
   	} else {
    	newCode = '<img onclick="gotoThumb('+counter+');" src="' + ph['pictureThumbFileName'][i]+ '" alt="'+ph['pictureTitle'][i]+'"';
 			if (pictureLibrarySettings['scaleForThumb']==1){
 				newCode=newCode+' width="'+pictureLibrarySettings['thumbWidth']+'" height="'+pictureLibrarySettings['thumbHeight']+'" ';
 			}
 			newCode=newCode+'>';
 			x.innerHTML = newCode;
   	}
   }
  }
 }
 pictureNumber=currentBlockStart;
 thumbNumber=1;
 setPictureTitles(pictureNumber);
 if (pictureNumber > 1) {
  if ((x=findObj('divpicLeft')) !=null){
	  x.style.visibility='visible';
  }
 }
 if (pictureNumber == pictureCount) {
  if ((x=findObj('divpicRight')) !=null){
	  x.style.visibility='hidden';
  }
 }
 if (pictureNumber > blockSize) {
  if ((x=findObj('divfastLeft')) !=null){
		x.style.visibility='visible';
  }
 }
 if ((pictureNumber+blockSize-1) >= pictureCount) {
  if ((x=findObj('divfastRight')) !=null){
		x.style.visibility='hidden';
  }
 }
}

var playSlidesStatus = 0;
var moveImageID;
var slideSpeed = 10000;
function playSlides(){
	if (playSlidesStatus == 0){
	  if ((x=findObj('divslideShowControlsPlay')) !=null){
	  	x.style.visibility='hidden';
	  }
	  if ((x=findObj('divslideShowControlsPause')) !=null){
	  	x.style.visibility='visible';
	  }
		playSlidesStatus = 1;
		moveImage();
	} else {
		playSlidesStatus = 0;
	}
}
function moveImage(){
	clearInterval(moveImageID);
	if (playSlidesStatus == 1){
		nextCall="moveImage()";
		moveImageID=setInterval(nextCall,slideSpeed);
		if (pictureNumber < pictureCount){
			thumbTarget = thumbNumber + 1;
			gotoThumb(thumbTarget);
		} else {
			pictureNumber = blockSize+1;
			thumbsLeft(0);
		}
	} else {
	  if ((x=findObj('divslideShowControlsPlay')) !=null){
	  	x.style.visibility='visible';
	  }
	  if ((x=findObj('divslideShowControlsPause')) !=null){
	  	x.style.visibility='hidden';
	  }
	}
}
function speedChange(){
  if ((x=findObj('slideShowSpeed')) !=null){
	 	slideSpeed=x.options[x.selectedIndex].value;
 		if (playSlidesStatus == 1){
 			moveImage();
 		}
  }
}
function loadSlideOptions(){
 if ((x=findObj("divslideShowDurationBox")) != null){
 	newHTML="";
 	newHTML = newHTML + '<select class="mediumText" name="slideShowSpeed" id="slideShowSpeed" size=1 onChange="speedChange();">';
 	newHTML = newHTML + '<option value="25">1/40 second</option>';
 	newHTML = newHTML + '<option value="50">1/20 second</option>';
 	newHTML = newHTML + '<option value="100">1/10 second</option>';
 	newHTML = newHTML + '<option value="250">1/4 second</option>';
 	newHTML = newHTML + '<option value="500">1/2 second</option>';
 	newHTML = newHTML + '<option value="750">3/4 second</option>';
 	newHTML = newHTML + '<option value="1000">1 second</option>';
 	newHTML = newHTML + '<option value="2000">2 seconds</option>';
 	newHTML = newHTML + '<option value="3000">3 seconds</option>';
 	newHTML = newHTML + '<option value="4000">4 seconds</option>';
 	newHTML = newHTML + '<option value="5000">5 seconds</option>';
 	newHTML = newHTML + '<option value="6000">6 seconds</option>';
 	newHTML = newHTML + '<option value="7000">7 seconds</option>';
 	newHTML = newHTML + '<option value="8000">8 seconds</option>';
 	newHTML = newHTML + '<option value="9000">9 seconds</option>';
 	newHTML = newHTML + '<option value="10000" SELECTED>10 seconds</option>';
 	newHTML = newHTML + '<option value="20000">20 seconds</option>';
 	newHTML = newHTML + '<option value="30000">30 seconds</option>';
 	newHTML = newHTML + '<option value="40000">40 seconds</option>';
 	newHTML = newHTML + '<option value="50000">50 seconds</option>';
 	newHTML = newHTML + '<option value="60000">1 minute</option>';
 	newHTML = newHTML + '</select>';
 	x.innerHTML = newHTML;
 }
}
function fullScreen(){
	indexDisplayOptions="toolbars=no,titlebar=no,width=" + (ph["picturePrintWidth"][pictureNumber]+10) + "px,height=" + (ph["picturePrintHeight"][pictureNumber]+10) + "px,resizeable=yes";
	fullSizeWin = window.open(ph['picturePrintFileName'][pictureNumber],"PictureIt", indexDisplayOptions);
//	if (ExpYes){
//	} else {
//		fullSizeWin.innerWidth=ph["picturePrintWidth"][pictureNumber];
//		fullSizeWin.innerHeight=ph["picturePrintHeight"][pictureNumber];
//	}
	fullSizeWin.focus();
}
