var ph = new Object;
ph['pictureTitle'] = new Object;
ph['pictureCaption'] = new Object;
ph['pictureThumbFileName'] = new Object;
ph['pictureSlideFileName'] = new Object;
ph['pictureFileName'] = new Object;
ph['pictureWidth'] = new Object;
ph['pictureHeight'] = new Object;
ph['slideWidth'] = new Object;
ph['slideHeight'] = new Object;
ph['thumbWidth'] = new Object;
ph['thumbHeight'] = new Object;
ph['click'] = new Object;
ph['mouseover'] = new Object;
ph['mouseout'] = new Object;

var galleryKeywordList = '';
var libraryKeywordList = '';
var gallerySettings = new Object;
var pictureCount = 0;
var blockSize = 0;
var pictureNumber = 1;
var thumbNumber = 1;
var searchType = 0;
var searchList = '';
var searchList2 = '';
var slideAlign = 2;
var thumbAlign = 2;

var continuous = 0;
var lastFadeState = 0;
var slideTransition = 1;
var fadeDuration = 500;
var transitionInitialised = 0;
var galleryInitialised = 0;

var blockCounter = 1;
var currentBlockStart = 0;
var currentBlockEnd = 0;

function imageRoll(){
 blendimage('td'+templateAlias+'_picturePlaceImageHolder','div'+templateAlias+'_picturePlaceImage',ph['pictureSlideFileName'][pictureNumber]);
}
function changeOpac(opacity,id){
 var object=document.getElementById(id).style;
 object.opacity=(opacity/100);
 object.MozOpacity=(opacity/100);
 object.KhtmlOpacity=(opacity/100);
 object.filter="alpha(opacity="+opacity+")";
 if (opacity == 0){
 	 lastFadeState = 1;
   setTimeout("imageRoll()",100);
 }
 if (continuous == 1){
  if (opacity == 100){
   setTimeout("imageRoll()",100);
  }
 }
}
function setSlide(img){
	img.alt = ph['pictureTitle'][pictureNumber];
	if (customSlideSize==0){
		if (ph['pictureWidth'][pictureNumber]>ph['pictureHeight'][pictureNumber]){
		 if (NavYes==1){
				img.style.width = slideWidth + "px";
				img.style.height = slideHeight + "px";
		 } else {
				img.style.width = slideWidth;
				img.style.height = slideHeight;
		 }
		} else {
		 if (NavYes==1){
				img.style.width = portraitSlideWidth + "px";
				img.style.height = slideHeight + "px";
		 } else {
				img.style.width = portraitSlideWidth;
				img.style.height = slideHeight;
		 }
		}
	} else {
	 if (NavYes==1){
			img.style.width = ph['slideWidth'][pictureNumber] + "px";
			img.style.height = ph['slideHeight'][pictureNumber] + "px";
	 } else {
			img.style.width = ph['slideWidth'][pictureNumber];
			img.style.height = ph['slideHeight'][pictureNumber];
	 }
	}
	if (showPrints==1){
		img.onClick = "fullScreen(pictureNumber);";
	}
}
function imgLoad(e) {
	imageid='div'+templateAlias+'_picturePlaceImage';
 var speed=Math.round(fadeDuration/100);
 var timer=0;
	if (!e) var e = window.event;
	var img = e.currentTarget || e.srcElement;
//	if (galleryInitialised == 1){
	 setSlide(img);
 	for(i=1;i<=100;i++){
 		setTimeout("changeOpac("+i+",'"+imageid+"')",(timer*speed));
 	 timer++;
 	}
//	}
	galleryInitialised = 1;
 if ((y=findObj('div'+templateAlias+'_picturePlaceLoader')) !=null){
 	y.style.visibility='hidden';
 }
}

function addEvent(obj, ev, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(ev, fn, false);
	} else if (obj.attachEvent) {
		obj.attachEvent('on' + ev, fn);
	}
}

function blendimage(divid,imageid,imagefile){
 var speed=Math.round(fadeDuration/100);
 var timer=0;
 if (lastFadeState == 1){
	 lastFadeState=0;
	 img = document.getElementById(imageid);
	 addEvent(img, 'load', imgLoad);
  img.src = imagefile;
 } else {
 	if ((y=findObj('div'+templateAlias+'_picturePlaceLoader')) !=null){
 		y.style.visibility='visible';
 	}
  for(i=99;i>=0;i--){
  	setTimeout("changeOpac("+i+",'"+imageid+"')",(timer*speed));
   timer++;
  }
 }
}

function gotoThumb(thumbTarget){
// if (thumbNumber<thumbTarget){
//  pictureRight(thumbTarget-thumbNumber);
// } else {
//  pictureLeft(thumbNumber-thumbTarget);
// }
	if (pictureNumber>=currentBlockStart && pictureNumber<=currentBlockEnd){
		restoreThumb(thumbNumber,pictureNumber);
	}
	thumbNumber=thumbTarget;
	pictureNumber = currentBlockStart + thumbTarget -1;
	selectThumb(thumbNumber,pictureNumber);
}

function restoreThumb(thumbNumber,pictureNumber){
	if ((x=findObj('div'+templateAlias+'_thumb' + thumbNumber)) !=null){
	 newCode = '<table cellspacing=0 cellpadding=0 style="width:100%;height:100%;';
	 if (thumbBorder!='' && highlightingStyle==1){
			newCode = newCode + thumbBorder;
	 } else {
			newCode = newCode + 'border:0px none #000000';
		}
	 newCode = newCode + ';margin:0px;padding:0px;"><tr><td';
		if (thumbAlign==1){
			newCode = newCode + ' align="left"';
		} else if (thumbAlign==2){
			newCode = newCode + ' align="center"';
		} else {
			newCode = newCode + ' align="right"';
		}
		newCode = newCode + '><img src="' + ph['pictureThumbFileName'][pictureNumber]+ '" alt="'+ph['pictureTitle'][pictureNumber]+'"';
		if (galleryStyle==3 && showPrints==1){
			newCode = newCode + ' onclick="fullScreen('+thumbNumber+');"';
		} else {
			newCode = newCode + ' onclick="gotoThumb('+thumbNumber+');"';
		}
		if (highlightingStyle==0 || highlightingStyle==3){  //none
			if (galleryStyle==3 && showPrints==1){
				newCode = newCode + ' style="cursor:crosshair;"';
			}
		} else if (highlightingStyle==1 || highlightingStyle==4){  //fade
			if (galleryStyle==3 && showPrints==1){
				newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:100);opacity:1;';
			} else {
				newCode = newCode+' style="filter:alpha(opacity:100);opacity:1;';
			}
			newCode = newCode+'"';
		} else if (highlightingStyle==2 || highlightingStyle==5){  //focus
			if (galleryStyle==3 && showPrints==1){
				newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';';
			} else {
				newCode=newCode+' style="filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';';
			}
			newCode = newCode+'"';
		}
		if (customThumbSize==0){
			if (ph['pictureWidth'][pictureNumber]>ph['pictureHeight'][pictureNumber]){
				newCode=newCode+' width="'+ thumbWidth +'" height="'+ thumbHeight +'" ';
			} else {
				newCode=newCode+' width="'+portraitThumbWidth+'" height="'+ thumbHeight +'" ';
			}
		} else {
			newCode=newCode+' width="'+ ph['thumbWidth'][pictureNumber] +'" height="'+ ph['thumbHeight'][pictureNumber] +'" ';
		}
		newCode=newCode+'></td></tr></table>';
		x.innerHTML = newCode;
	}
	if ((x=findObj('div'+templateAlias+'_thumbTitle' + thumbNumber)) !=null){
		x.innerHTML = ph['pictureTitle'][pictureNumber];
	}
	if ((x=findObj('div'+templateAlias+'_thumbCaption' + thumbNumber)) !=null){
		x.innerHTML = ph['pictureCaption'][pictureNumber];
	}
}

function selectThumb(thumbNumber,pictureNumber){
 if ((x=findObj('div'+templateAlias+'_thumb' + thumbNumber)) !=null){
	 newCode = '<table cellspacing=0 cellpadding=0 style="width:100%;height:100%;';
	 if (thumbBorder!='' && (highlightingStyle==1 || highlightingStyle>=3)){
			newCode = newCode + thumbBorder;
	 } else {
			newCode = newCode + 'border:0px none #000000';
		}
	 newCode = newCode + ';margin:0px;padding:0px;"><tr><td';
		if (thumbAlign==1){
			newCode = newCode + ' align="left"';
		} else if (thumbAlign==2){
			newCode = newCode + ' align="center"';
		} else {
			newCode = newCode + ' align="right"';
		}
		newCode = newCode + '><img src="' + ph['pictureThumbFileName'][pictureNumber]+ '" alt="'+ph['pictureTitle'][pictureNumber]+'"';
			if (galleryStyle==3 && showPrints==1){
 	  newCode = newCode + ' onclick="fullScreen('+thumbNumber+');"';
   } else {
 	 	newCode = newCode + ' onclick="gotoThumb('+thumbNumber+');"';
   }
			if (highlightingStyle==0 || highlightingStyle==3){  //none
	  	if (galleryStyle==3 && showPrints==1){
					newCode = newCode + ' style="cursor:crosshair;"';
	  	}
			} else if (highlightingStyle==1 || highlightingStyle==4){  //fade
	  	if (galleryStyle==3 && showPrints==1){
					newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';"';
	  	} else {
					newCode=newCode+' style="filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';"';
	  	}
			} else if (highlightingStyle==2 || highlightingStyle==5){  //focus
	  	if (galleryStyle==3 && showPrints==1){
					newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:100);opacity:1;"';
	  	} else {
					newCode=newCode+' style="filter:alpha(opacity:100);opacity:1;"';
	  	}
			}
			if (highlightingStyle>=3){
				thumbAdj = thumbBorderWidth*2;
			} else {
				thumbAdj = 0;
			}
			if (customThumbSize==0){
				if (ph['pictureWidth'][pictureNumber]>ph['pictureHeight'][pictureNumber]){
					newCode=newCode+' width="'+ (thumbWidth - thumbAdj) +'" height="'+ (thumbHeight - thumbAdj)  +'" ';
				} else {
					newCode=newCode+' width="' + (portraitThumbWidth - thumbAdj) +'" height="'+ (thumbHeight - thumbAdj)  +'" ';
				}
			} else {
				newCode=newCode+' width="'+ (ph['thumbWidth'][pictureNumber] - thumbAdj) +'" height="'+ (ph['thumbHeight'][pictureNumber] - thumbAdj)  +'" ';
			}
  	newCode=newCode+'></td></tr></table>';
   x.innerHTML = newCode;
   setPictureTitles(pictureNumber);
 }
	if ((x=findObj('div'+templateAlias+'_thumbTitle' + thumbNumber)) !=null){
		x.innerHTML = ph['pictureTitle'][pictureNumber];
	}
	if ((x=findObj('div'+templateAlias+'_thumbCaption' + thumbNumber)) !=null){
		x.innerHTML = ph['pictureCaption'][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('div'+templateAlias+'_picturePlace')) !=null){
		if (slideTransition==0 || transitionInitialised==0){
			if ((y=findObj('div'+templateAlias+'_picturePlaceLoader')) !=null){
				y.innerHTML='<table style="width:100%;height:100%;vertical-align:middle;"><tr><td><img src="/siteLibrary/imageLoading.gif"></td></tr></table>'
			}
			transitionInitialised = 1;
			newCode='<table cellspacing=0 cellpadding=0 style="width:100%;height:100%;border:0px none #000000;margin:0px;padding:0px;"><tr><td';
			if (slideAlign==1){
				newCode = newCode + ' align="left"';
			} else if (slideAlign==2){
				newCode = newCode + ' align="center"';
			} else {
				newCode = newCode + ' align="right"';
			}
			newCode = newCode + '>';
			newCode = newCode + '<table cellspacing=0 cellpadding=0 style="border:0px none #000000;margin:0px;padding:0px;';
			newCode = newCode + '"><tr><td bgcolor="white" id="td' + templateAlias + '_picturePlaceImageHolder" >';

			newCode = newCode + '<img src="' + ph['pictureSlideFileName'][pictureNumber] + '" alt="' + ph['pictureTitle'][pictureNumber]+ '"' + '" id="div' + templateAlias + '_picturePlaceImage"';
			if (customSlideSize==0){
				if (ph['pictureWidth'][pictureNumber]>ph['pictureHeight'][pictureNumber]){
					newCode=newCode+' width="'+ slideWidth +'" height="'+ slideHeight +'" ';
				} else {
					newCode=newCode+' width="'+portraitSlideWidth+'" height="'+ slideHeight +'" ';
				}
			} else {
				newCode=newCode+' width="'+ ph['slideWidth'][pictureNumber] +'" height="'+ ph['slideHeight'][pictureNumber] +'" ';
			}
 		if (showPrints==1){
				newCode=newCode+' onClick="fullScreen(pictureNumber);"';
 		}
 		newCode = newCode + ' style="';
 		newCode = newCode + 'filter:alpha(opacity:0);opacity:0;';
 		if (slideBorder!=""){
				newCode = newCode + slideBorder;
			}
			newCode = newCode + '"';
			newCode=newCode + '>';

			newCode = newCode + '</td></tr></table>';
			newCode=newCode+'</td></tr></table>';
			x.innerHTML =  newCode;
			if (galleryInitialised == 0){
				imageid = 'div'+templateAlias+'_picturePlaceImage';
				img = document.getElementById(imageid);
	 		addEvent(img, 'load', imgLoad);
			}
		} else {
			imageRoll();
		}
	}
	if ((x=findObj('div'+templateAlias+'_titleText'))!=null){
		x.innerHTML = html_entity_decode(ph['pictureTitle'][pictureNumber]);
	}
	if ((x=findObj('div'+templateAlias+'_pictureCaption'))!=null){
		x.innerHTML = html_entity_decode(ph['pictureCaption'][pictureNumber]);
	}
}

function pictureLeft(moveCount){
	if (pictureNumber >1){
		if (pictureNumber>=currentBlockStart && pictureNumber<=currentBlockEnd){
			restoreThumb(thumbNumber,pictureNumber);
			thumbNumber=thumbNumber-moveCount;
		} else {
			thumbNumber=1;
		}
		if (thumbNumber>0){
			pictureNumber = currentBlockStart + thumbNumber -1;
			selectThumb(thumbNumber,pictureNumber);
			if (pictureNumber == 1){
				if ((x=findObj('div'+templateAlias+'_picLeft')) !=null){
					x.style.visibility='hidden';
				}
 		}
 		if (pictureNumber < pictureCount){
				if ((x=findObj('div'+templateAlias+'_picRight')) !=null){
					x.style.visibility='visible';
				}
  	}
  } else {
  	pictureNumber = (currentBlockStart - 1);
  	thumbsLeft(1,0,1);
 	}
	}
}

function pictureRight(moveCount){
	if (pictureNumber < pictureCount){
		if (pictureNumber>=currentBlockStart && pictureNumber<=currentBlockEnd){
			restoreThumb(thumbNumber,pictureNumber);
			thumbNumber=thumbNumber+moveCount;
		} else {
			thumbNumber=1;
		}
		if (thumbNumber<=blockSize){
			pictureNumber = currentBlockStart + thumbNumber -1;
 		selectThumb(thumbNumber,pictureNumber);
 		if (pictureNumber > 1) {
				if ((x=findObj('div'+templateAlias+'_picLeft')) !=null){
  			x.style.visibility='visible';
				}
 		}
 		if (pictureNumber == pictureCount) {
				if ((x=findObj('div'+templateAlias+'_picRight')) !=null){
  			x.style.visibility='hidden';
				}
 		}
		} else {
			pictureNumber = (currentBlockEnd + 1);
 		thumbsRight(0,0,1);
  }
 }
}

function thumbsLeft(highlightLastThumbFlag,sync,forceSet){
	blockCounter=blockCounter-1;
	if (blockCounter >= 0){
 	currentBlockStart = (blockCounter*blockSize)+1;
 	currentBlockEnd = currentBlockStart + blockSize -1;
 	counter=0;
 	for (i=currentBlockStart;i<=currentBlockEnd;i++){
  	counter ++;
 		if ((x=findObj('div'+templateAlias+'_thumb' + counter)) !=null){
				if (i>pictureCount){

					newCode="";
					x.innerHTML = newCode;
					if (((x=findObj('div'+templateAlias+'_thumbTitle' + counter)) !=null) || ((x=findObj('div'+templateAlias+'_thumbCaption' + counter)) !=null))	x.innerHTML = '';

 			} else {

	  		newCode = '<table cellspacing=0 cellpadding=0 style="width:100%;height:100%;';
	  		if (((((counter == 1 && highlightLastThumbFlag==0) || (counter == blockSize && highlightLastThumbFlag==1)) && sync==1) || pictureNumber==i) && (thumbBorder!='' && (highlightingStyle==1 || highlightingStyle>=3))){
	  			if (highlightingStyle>=3){
	 					newCode = newCode + thumbBorder;
	 				} else {
	  				newCode = newCode + 'border:0px none #000000';
	 				}
	  		} else {
		  		newCode = newCode + 'border:0px none #000000';
					}
	  		newCode = newCode + ';margin:0px;padding:0px;"><tr><td';
					if (thumbAlign==1){
						newCode = newCode + ' align="left"';
					} else if (thumbAlign==2){
						newCode = newCode + ' align="center"';
					} else {
						newCode = newCode + ' align="right"';
					}
					newCode = newCode + '><img src="' + ph['pictureThumbFileName'][i]+ '" alt="'+ph['pictureTitle'][i]+'"';
  			if (galleryStyle==3 && showPrints==1){
	 				newCode = newCode + ' onclick="fullScreen('+i+');"';
  			} else {
 	 			newCode = newCode + ' onclick="gotoThumb('+counter+');"';
  			}
	  		if ((((counter == 1 && highlightLastThumbFlag==0) || (counter == blockSize && highlightLastThumbFlag==1)) && sync==1) || pictureNumber==i){  //first block item
	  			if (highlightingStyle>=3){
	  				thumbAdj = thumbBorderWidth*2;
	  			} else {
	  				thumbAdj = 0;
	  			}
	  			if (pictureNumber==i){
				  	if (highlightingStyle==1 || highlightingStyle==4){  //fade
	 		 			newCode=newCode+' style="filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';"';
			   	} else if (highlightingStyle==2 || highlightingStyle==5){  //focus
	  	 			newCode=newCode+' style="filter:alpha(opacity:100);opacity:1;"';
			 	 	}
	  			}
			 	 if (customThumbSize==0){
 						if (ph['pictureWidth'][i]>ph['pictureHeight'][i]){
								newCode=newCode+' width="'+ (thumbWidth - thumbAdj) +'" height="'+ (thumbHeight - thumbAdj) +'" ';
 						} else {
 							newCode=newCode+' width="' + (portraitThumbWidth - thumbAdj)+'" height="'+ (thumbHeight - thumbAdj) +'" ';
 						}
						} else {
							newCode=newCode+' width="'+ (ph['thumbWidth'][i] - thumbAdj) +'" height="'+ (ph['thumbHeight'][i] - thumbAdj) +'" ';
 					}
 					newCode=newCode+'></td></tr></table>';

  			} else {  //item within block
						if (highlightingStyle==0){  //none
			  		if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;'+thumbBorder+'"';
			  		} else {
								newCode = newCode + ' style="'+thumbBorder+'"';
			  		}
						} else if (highlightingStyle==3){  //hide border
			  		if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;"';
			  		}
						} else if (highlightingStyle==1 || highlightingStyle==4){  //fade
			  		if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:100);opacity:1;';
			  		} else {
  						newCode=newCode+' style="filter:alpha(opacity:100);opacity:1;';
			  		}
			  		newCode=newCode+'"';
						} else if (highlightingStyle==2 || highlightingStyle==5){  //focus
			  		if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';';
			  		} else {
  						newCode=newCode+' style="filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';';
			  		}
			  		newCode=newCode+'"';
				 	}
						if (customThumbSize==0){
 						if (ph['pictureWidth'][i]>ph['pictureHeight'][i]){
								newCode=newCode+' width="'+ thumbWidth +'" height="'+ thumbHeight +'" ';
 						} else {
 							newCode=newCode+' width="'+portraitThumbWidth+'" height="'+ thumbHeight +'" ';
 						}
						} else {
							newCode=newCode+' width="'+ ph['thumbWidth'][i] +'" height="'+ ph['thumbHeight'][i] +'" ';
 					}
 					newCode=newCode+'></td></tr></table>';
  			}
					x.innerHTML = newCode;
					if ((x=findObj('div'+templateAlias+'_thumbTitle' + counter)) !=null){
						x.innerHTML = ph['pictureTitle'][i];
					}
					if ((x=findObj('div'+templateAlias+'_thumbCaption' + counter)) !=null){
						x.innerHTML = ph['pictureCaption'][i];
					}
  		}
 		}
 	}
 }
 if (pictureNumber>currentBlockStart && pictureNumber<currentBlockEnd){
 	thumbNumber=(pictureNumber-parseInt(pictureNumber/blockSize)*blockSize);
 } else {
	 if (highlightLastThumbFlag == 1){
			thumbNumber=blockSize;
		} else {
	 	thumbNumber=1;
		}
 	if (sync==1 || forceSet==1){
		 if (highlightLastThumbFlag == 1){
				pictureNumber=currentBlockEnd;
			} else {
				pictureNumber=currentBlockStart;
			}
	 	setPictureTitles(pictureNumber);
		}
 }
 if (pictureNumber == 1){
 	if ((x=findObj('div'+templateAlias+'_picLeft')) !=null){
			x.style.visibility='hidden';
 	}
 }
	if ((x=findObj('div'+templateAlias+'_picRight')) !=null){
		if (pictureNumber < pictureCount){
  	x.style.visibility='visible';
 	} else {
  	x.style.visibility='hidden';
 	}
 }
	if ((x=findObj('div'+templateAlias+'_fastLeft')) !=null){
		if (currentBlockStart <= blockSize){
			x.style.visibility='hidden';
 	} else {
			x.style.visibility='visible';
 	}
	}
	if ((x=findObj('div'+templateAlias+'_fastRight')) !=null){
		if (currentBlockEnd < pictureCount && pictureCount > blockSize){
			x.style.visibility='visible';
		} else {
			x.style.visibility='hidden';
		}
	}
}

function thumbsRight(highlightLastThumbFlag,sync,forceSet){
	blockCounter=blockCounter+1;
	currentBlockStart = (blockCounter*blockSize)+1;
	if (currentBlockStart <= pictureCount){
		currentBlockEnd = currentBlockStart + blockSize -1;
		counter=0;
		for (i=currentBlockStart;i<=currentBlockEnd;i++){
			counter ++;
			if ((x=findObj('div'+templateAlias+'_thumb'+counter)) !=null){
				if (i>pictureCount){
					newCode="";
					x.innerHTML = newCode;
					if (((x=findObj('div'+templateAlias+'_thumbTitle' + counter)) !=null) || ((x=findObj('div'+templateAlias+'_thumbCaption' + counter)) !=null))	x.innerHTML = '';
				} else {
					if ((counter == 1 && sync==1) || pictureNumber==i){
	   		newCode = '<table cellspacing=0 cellpadding=0 style="width:100%;height:100%;';
		  		if (((counter == 1 || counter == blockSize) || (pictureNumber==i)) && (thumbBorder!='' && (highlightingStyle==1 || highlightingStyle>=3))){
		  			if (highlightingStyle>=3){
	 						newCode = newCode + thumbBorder;
	 					} else {
	  					newCode = newCode + 'border:0px none #000000';
	 					}
	  			} else {
		  			newCode = newCode + 'border:0px none #000000';
						}
	   		newCode = newCode + ';margin:0px;padding:0px;"><tr><td';
						if (thumbAlign==1){
							newCode = newCode + ' align="left"';
						} else if (thumbAlign==2){
							newCode = newCode + ' align="center"';
						} else {
							newCode = newCode + ' align="right"';
						}
						newCode = newCode + '><img src="' + ph['pictureThumbFileName'][i] +'" alt="'+ph['pictureTitle'][i]+'"';
	  			if (galleryStyle==3 && showPrints==1){
		 				newCode = newCode + ' onclick="fullScreen('+i+');"';
	  			} else {
 		 			newCode = newCode + ' onclick="gotoThumb('+counter+');"';
  				}
	  			if (highlightingStyle>=3 && pictureNumber==i){
	  				thumbAdj = thumbBorderWidth*2;
	  			} else {
	  				thumbAdj = 0;
	  			}
	  			if (pictureNumber==i){
		   		if (highlightingStyle==1 || highlightingStyle==4){  //fade
	 		 			newCode=newCode+' style="filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';"';
			   	} else if (highlightingStyle==2 || highlightingStyle==5){  //focus
	 		 			newCode=newCode+' style="filter:alpha(opacity:100);opacity:1;"';
			   	}
	  			}
	  			if (customThumbSize==0){
 						if (ph['pictureWidth'][i]>ph['pictureHeight'][i]){
								newCode=newCode+' width="'+ (thumbWidth - thumbAdj) +'" height="'+ (thumbHeight - thumbAdj)  +'" ';
 						} else {
 							newCode=newCode+' width="' + (portraitThumbWidth - thumbAdj) +'" height="'+ (thumbHeight - thumbAdj)  +'" ';
 						}
						} else {
							newCode=newCode+' width="'+ (ph['thumbWidth'][i] - thumbAdj) +'" height="'+ (ph['thumbHeight'][i] - thumbAdj)  +'" ';
 					}
						newCode=newCode+'></td></tr></table>';
 					x.innerHTML = newCode;

 				} else {
		 			newCode = '<table cellspacing=0 cellpadding=0 style="width:100%;height:100%;border:0px none #000000;margin:0px;padding:0px;"><tr><td';
						if (thumbAlign==1){
							newCode = newCode + ' align="left"';
						} else if (thumbAlign==2){
							newCode = newCode + ' align="center"';
						} else {
							newCode = newCode + ' align="right"';
						}
						newCode = newCode + '><img src="' + ph['pictureThumbFileName'][i]+ '" alt="'+ph['pictureTitle'][i]+'"';
 	 			if (galleryStyle==3 && showPrints==1){
	 					newCode = newCode + ' onclick="fullScreen('+i+');"';
  				} else {
 	 				newCode = newCode + ' onclick="gotoThumb('+counter+');"';
  				}
						if (highlightingStyle==0){  //none
				  	if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;'+thumbBorder+'"';
				  	} else {
								newCode = newCode + ' style="'+thumbBorder+'"';
				  	}
						} else if (highlightingStyle==1){  //fade
				  	if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:100);opacity:1;'+thumbBorder+'"';
				  	} else {
  						newCode=newCode+' style="filter:alpha(opacity:100);opacity:1;'+thumbBorder+'"';
				  	}
		 			} else if (highlightingStyle==2){  //focus
				  	if (galleryStyle==3 && showPrints==1){
								newCode = newCode + ' style="cursor:crosshair;filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';'+thumbBorder+'"';
				  	} else {
  						newCode=newCode+' style="filter:alpha(opacity:'+thumbOpacity+');opacity:'+(thumbOpacity/100)+';'+thumbBorder+'"';
				  	}
					 }
						if (customThumbSize==0){
 						if (ph['pictureWidth'][i]>ph['pictureHeight'][i]){
								newCode=newCode+' width="'+ thumbWidth +'" height="'+ thumbHeight +'" ';
 						} else {
 							newCode=newCode+' width="'+portraitThumbWidth+'" height="'+ thumbHeight +'" ';
 						}
						} else {
							newCode=newCode+' width="'+ ph['thumbWidth'][i] +'" height="'+ ph['thumbHeight'][i] +'" ';
 					}
						newCode=newCode+'></td></tr></table>';
 				}
					x.innerHTML = newCode;
					if ((x=findObj('div'+templateAlias+'_thumbTitle' + counter)) !=null){
						x.innerHTML = ph['pictureTitle'][i];
					}
					if ((x=findObj('div'+templateAlias+'_thumbCaption' + counter)) !=null){
						x.innerHTML = ph['pictureCaption'][i];
					}
				}
			}
		}
 }
 if (pictureNumber>currentBlockStart && pictureNumber<currentBlockEnd){
 	thumbNumber=(pictureNumber-parseInt(pictureNumber/blockSize)*blockSize);
 } else {
 	thumbNumber=1;
 	if (sync==1 || forceSet==1){
			pictureNumber=currentBlockStart;
	 	setPictureTitles(pictureNumber);
		}
 }
	if (pictureNumber > 1) {
		if ((x=findObj('div'+templateAlias+'_picLeft')) !=null){
			x.style.visibility='visible';
		}
 	}
	if (pictureNumber == pictureCount) {
		if ((x=findObj('div'+templateAlias+'_picRight')) !=null){
			x.style.visibility='hidden';
		}
	}
	if ((x=findObj('div'+templateAlias+'_fastLeft')) !=null){
		if (currentBlockStart <= blockSize){
			x.style.visibility='hidden';
 	} else {
			x.style.visibility='visible';
 	}
	}
	if ((x=findObj('div'+templateAlias+'_fastRight')) !=null){
		if (currentBlockEnd < pictureCount && pictureCount > blockSize){
			x.style.visibility='visible';
		} else {
			x.style.visibility='hidden';
		}
	}
}

var playSlidesStatus = 0;
var moveImageID;
function playSlides(){
	if (playSlidesStatus == 0){
	  if ((x=findObj('div'+templateAlias+'_slideShowControlsPlay')) !=null){
	  		x.style.visibility='hidden';
	  }
	  if ((x=findObj('div'+templateAlias+'_slideShowControlsPause')) !=null){
	  		x.style.visibility='visible';
	  }
		playSlidesStatus = 1;
		moveImage();
	} else {
		playSlidesStatus = 0;
	}
}

function moveImage(){
	clearInterval(moveImageID);
	if (playSlidesStatus == 1){
		nextCall="moveImage()";
		moveImageID=setInterval(nextCall,screenshowSpeed);
		if (pictureNumber < pictureCount){
			thumbTarget = thumbNumber + 1;
			gotoThumb(thumbTarget);
		} else {
			pictureNumber = blockSize+1;
			thumbsLeft(0);
		}
	} else {
	  if ((x=findObj('div'+templateAlias+'_slideShowControlsPlay')) !=null){
	  		x.style.visibility='visible';
	  }
	  if ((x=findObj('div'+templateAlias+'_slideShowControlsPause')) !=null){
	  		x.style.visibility='hidden';
	  }
	}
}

function speedChange(){
  if ((x=findObj('slideShowSpeed')) !=null){
	 	screenshowSpeed=x.options[x.selectedIndex].value;
 		if (playSlidesStatus == 1){
 			moveImage();
 		}
  }
}

function loadSlideOptions(){
 if ((x=findObj("div'+templateAlias+'_slideShowDurationBox")) != 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(pictureNumber){
	indexDisplayOptions="toolbars=no,titlebar=no,width=" + (parseInt(ph["pictureWidth"][pictureNumber])+10) + ",height=" + (parseInt(ph["pictureHeight"][pictureNumber])+10) + ",resizeable=yes";
	fullSizeWin = window.open(ph['pictureFileName'][pictureNumber],"PictureIt", indexDisplayOptions);
	fullSizeWin.focus();
}