var thumbnails;var currentImageIndex;var mainPhoto;var photoScalingInterval;var showLoadingTimeout;var showImageDataFadeTimeout
var MAIN_PHOTO_WIDTH=460;var PHOTO_MINIMISED=300;var SCALE_DOWN_FACTOR=12;var SCALE_UP_FACTOR=18;fullsizePhotos=new Array();fullsizeCount=0;addEvent(window,'load',init,false);function init(){if(!document.getElementById){return;}
var thumbholder=document.getElementById('gsThumbMatrix');if(!thumbholder){setupBackToAlbumLink();return;}
thumbnails=thumbholder.getElementsByTagName('img');for(var i=0;i<thumbnails.length;i++){thumbnails[i].thumbIndex=i;addEvent(thumbnails[i],'click',activateThumbnail,false);thumbnails[i].onclick=cancelEventSafari;}
if(readCookie('slideshowOffset')!=null&&Number(readCookie('slideshowOffset'))<thumbnails.length){currentImageIndex=Number(readCookie('slideshowOffset'));eraseCookie('slideshowOffset');addMessage('Restarting slideshow at index '+ currentImageIndex);}else{currentImageIndex=0;}
if(slideshowImages.length>0){setupMainImage();switchImages(currentImageIndex,true);}
setupSubAlbums();}
function setupMainImage(){mainPhoto=document.getElementById('main-image');if(slideshowImageWidths[currentImageIndex]<0||MAIN_PHOTO_WIDTH<=slideshowImageWidths[currentImageIndex]){mainPhoto.style.width=MAIN_PHOTO_WIDTH+'px';}else{mainPhoto.style.width=slideshowImageWidths[currentImageIndex]+'px';mainPhoto.style.left=parseInt(getElementStyle(mainPhoto.id,'left'))+
((MAIN_PHOTO_WIDTH- slideshowImageWidths[currentImageIndex])/2)+'px';}
mainPhoto.style.height='auto';mainPhoto.origWidth=parseInt(getElementStyle(mainPhoto.id,'width'));mainPhoto.origLeft=parseInt(getElementStyle(mainPhoto.id,'left'));mainPhoto.galleryimg='no';addEvent(mainPhoto,'click',showPhotoDetails,false);}
function activateThumbnail(e){var targetElement=window.event?window.event.srcElement:e?e.target:null;if(!targetElement){return;}
knackerEvent(e);switchImages(targetElement.thumbIndex);targetElement.blur();}
function switchImages(thumbIndex,firstLoad){removeImageDataBlock();if(currentImageIndex==thumbIndex&&!firstLoad){addMessage("That image is already selected.");return;}
if(thumbIndex<0){thumbIndex=thumbnails.length- 1;}else if(thumbIndex==thumbnails.length){thumbIndex=0;}
if(slideshowImageWidths[thumbIndex]<0){if(!firstLoad){location=slideshowImages[thumbIndex];}else{hideLoadingMessage();}
return;}
highlightCurrentThumb(thumbIndex);updateItemTitle(thumbIndex);hideLoadingMessage();var newImageSrc=slideshowImages[thumbIndex];var newImage=document.createElement('img');mainPhoto.id=null;mainPhoto.removeAttribute('id');newImage.id='main-image';addEvent(newImage,'load',bigPhotoLoad,false);addEvent(newImage,'error',bigPhotoFail,false);if(slideshowState==PLAYING){pause();returnToPlaying=true;}
showLoadingTimeout=setTimeout("showLoadingMessage()",600);addMessage("Swapping "+ currentImageIndex+", and "+ thumbIndex+"...");currentImageIndex=thumbIndex;newImage.src=newImageSrc;mainPhoto.parentNode.removeChild(mainPhoto);document.getElementById('sliding-frame').getElementsByTagName('p')[0].appendChild(newImage);setupMainImage();if(mainPhoto.state=='downsized'){insertimagedatablock();}}
function bigPhotoLoad(){mainPhoto.style.height='auto';addMessage('Photo loaded');hideLoadingMessage();mainPhoto.style.height='345px';mainPhoto.style.height='auto';if(returnToPlaying){play();}}
function bigPhotoFail(){addMessage('FAIL: Photo failed to load...');addMessage(mainPhoto.src);hideLoadingMessage();if(slideshowState==PLAYING){advanceSlideShow();}}
function showLoadingMessage(){var loadingMsg=document.createElement('div');loadingMsg.id='loading';loadingMsg.appendChild(document.createTextNode(LOADING_IMAGE));document.getElementById('main-image-container').appendChild(loadingMsg);}
function hideLoadingMessage(){clearTimeout(showLoadingTimeout);var loading=document.getElementById('loading');if(loading&&getElementStyle(loading.id,'-moz-opacity')>0.0){loading.style.MozOpacity=parseFloat(getElementStyle(loading.id,'-moz-opacity'))- 0.05;showLoadingTimeout=setTimeout("hideLoadingMessage()",50);}else if(loading){loading.parentNode.removeChild(loading);}}
function highlightCurrentThumb(thumbIndex){thumbnails[currentImageIndex].className=thumbnails[currentImageIndex].className.replace(/\bcurrentImage\b/,'');thumbnails[thumbIndex].className+=' currentImage';}
function updateItemTitle(thumbIndex){var itemTitle=document.getElementById('item-title').firstChild;itemTitle.data=thumbnails[thumbIndex].getAttribute('alt');}
function showPhotoDetails(e){addMessage('scaling image, dimensions: '+ mainPhoto.origWidth+'x'+ mainPhoto.origHeight);clearInterval(photoScalingInterval);if(slideshowState==PLAYING){pause();returnToPlaying=true;}
if(mainPhoto.state!='downsized'){photoScalingInterval=setInterval("downSizePhoto()",30);mainPhoto.state='downsized';}else{removeImageDataBlock();photoScalingInterval=setInterval("upSizePhoto()",20);mainPhoto.state='upsized';}}
function downSizePhoto(){if(parseInt(mainPhoto.style.width)>PHOTO_MINIMISED||parseInt(getElementStyle(mainPhoto.id,'left'))>40){if(parseInt(mainPhoto.style.width)>PHOTO_MINIMISED){mainPhoto.style.width=parseInt(mainPhoto.style.width)- SCALE_DOWN_FACTOR+'px';}
mainPhoto.style.height='auto';if(parseInt(getElementStyle(mainPhoto.id,'left'))>40){mainPhoto.style.left=(parseInt(getElementStyle(mainPhoto.id,'left'))-
mainPhoto.origLeft/12)+'px';}
if(getElementStyle(mainPhoto.id,'top')=='auto'){mainPhoto.style.top='0';}
if(parseInt(getElementStyle(mainPhoto.id,'top'))<40){mainPhoto.style.top=(parseInt(getElementStyle(mainPhoto.id,'top'))+ 5)+'px';}}else{clearInterval(photoScalingInterval);addMessage('Image scaled to '+ mainPhoto.style.width+'x'+ mainPhoto.style.height);mainPhoto.state='downsized';insertimagedatablock();}}
function upSizePhoto(){if(parseInt(mainPhoto.style.width)<mainPhoto.origWidth||parseInt(getElementStyle(mainPhoto.id,'left'))<mainPhoto.origLeft){if(parseInt(mainPhoto.style.width)<mainPhoto.origWidth-5){mainPhoto.style.width=(parseInt(mainPhoto.style.width)+ SCALE_UP_FACTOR)+'px';}
if(parseInt(getElementStyle(mainPhoto.id,'left'))<mainPhoto.origLeft){mainPhoto.style.left=(parseInt(getElementStyle(mainPhoto.id,'left'))+
mainPhoto.origLeft/10)+'px';}
if(parseInt(getElementStyle(mainPhoto.id,'top'))>0){mainPhoto.style.top=(parseInt(getElementStyle(mainPhoto.id,'top'))- 5)+'px';}}else{clearInterval(photoScalingInterval);mainPhoto.style.width=mainPhoto.origWidth+'px';mainPhoto.style.height='auto';mainPhoto.style.left=mainPhoto.origLeft+'px';mainPhoto.style.top='auto';addMessage('Image scaled back to '+ mainPhoto.width+'x'+ mainPhoto.height);mainPhoto.state='upsized';if(returnToPlaying){play();}}}
function insertimagedatablock(){var dataBlock=document.createElement('div');dataBlock.id='imagedatablock';var dataBlockHeading=document.createElement('h3');dataBlockHeading.appendChild(document.createTextNode(PHOTO_DATA));dataBlock.appendChild(dataBlockHeading);if(thumbnails[currentImageIndex].className.match(/size:=([0-9]+)=/)){var imageSize=Number(RegExp.$1)/1024;var sizeInfo=document.createElement('p');sizeInfo.appendChild(document.createTextNode(FILE_SIZE.replace(/%SIZE%/,Math.round(imageSize))));dataBlock.appendChild(sizeInfo);}
if(thumbnails[currentImageIndex].className.match(/summary:=([^=]+)=/)){var summaryInfo=document.createElement('p');summaryInfo.appendChild(document.createTextNode(SUMMARY+ RegExp.$1));dataBlock.appendChild(summaryInfo);}
if(thumbnails[currentImageIndex].className.match(/description:=(.+)=/)){var descriptionInfo=document.createElement('p');descriptionInfo.appendChild(document.createTextNode(DESCRIPTION+ RegExp.$1));dataBlock.appendChild(descriptionInfo);}
var fullsizeLink=document.createElement('a');fullsizeLink.id='fullsizelink';fullsizeLink.href=thumbnails[currentImageIndex].parentNode.href
+(thumbnails[currentImageIndex].parentNode.href.indexOf('?')>=0?'&':'?')
+'thumbIndex='+ currentImageIndex;addEvent(fullsizeLink,'click',saveCurrentImageIndex,false);fullsizeLink.appendChild(document.createTextNode(VIEW_IMAGE));var linkPara=document.createElement('p');linkPara.appendChild(fullsizeLink);dataBlock.appendChild(linkPara);dataBlock.style.MozOpacity=0.2;showImageDataFadeTimeout=setTimeout('fadeInImageDataBlock()',50);document.getElementById('main-image-container').appendChild(dataBlock);}
function fadeInImageDataBlock(){clearTimeout(showImageDataFadeTimeout);var dataBlock=document.getElementById('imagedatablock');if(dataBlock&&getElementStyle(dataBlock.id,'-moz-opacity')<0.92){dataBlock.style.MozOpacity=parseFloat(getElementStyle(dataBlock.id,'-moz-opacity'))+ 0.08;showImageDataFadeTimeout=setTimeout('fadeInImageDataBlock()',50);}}
function removeImageDataBlock(){var dataBlock=document.getElementById('imagedatablock');if(dataBlock){dataBlock.parentNode.removeChild(dataBlock);}}
function setupSubAlbums(){if(!document.getElementById('gsSubAlbumMatrix')){return;}
var subs=document.getElementById('gsSubAlbumMatrix').getElementsByTagName('td');for(var i=0;i<subs.length;i++){addEvent(subs[i],'click',selectSubAlbum,false);var hasLink=subs[i].getElementsByTagName('a')[0];if(hasLink){addEvent(subs[i],'mouseover',highlightSubAlbum,true);addEvent(subs[i],'mouseout',unHighlightSubAlbum,true);}}}
function highlightSubAlbum(e){var targetElement=window.event?window.event.srcElement:e?e.target:null;if(!targetElement){return;}
while(targetElement.nodeName.toLowerCase()!='td'&&targetElement.nodeName.toLowerCase()!='body'){targetElement=targetElement.parentNode;}
if(targetElement.nodeName.toLowerCase()=='body'){return;}
targetElement.className+=' sahover';}
function unHighlightSubAlbum(e){var targetElement=window.event?window.event.srcElement:e?e.target:null;if(!targetElement){return;}
while(targetElement.nodeName.toLowerCase()!='td'&&targetElement.nodeName.toLowerCase()!='body'){targetElement=targetElement.parentNode;}
if(targetElement.nodeName.toLowerCase()=='body'){return;}
targetElement.className=targetElement.className.replace(/\bsahover\b/,'');}
function selectSubAlbum(e){var targetElement=window.event?window.event.srcElement:e?e.target:null;if(!targetElement){return;}
knackerEvent(e);while(targetElement.nodeName.toLowerCase()!='td'&&targetElement.nodeName.toLowerCase()!='body'){targetElement=targetElement.parentNode;}
if(targetElement.nodeName.toLowerCase()=='body'){return;}
eraseCookie('slideshowOffset');var firstlink=targetElement.getElementsByTagName('a')[0];if(firstlink){window.location=firstlink.href;}}
function setupBackToAlbumLink(){var pageLinks=document.getElementsByTagName('a');for(var i=0;i<pageLinks.length;i++){if(pageLinks[i].className.match(/\bbacktoalbum\b/)){addEvent(pageLinks[i],'click',saveCurrentImageIndex,false);}}}
function saveCurrentImageIndex(){if(window.location.toString().match(/thumbIndex=([0-9]+)/)){createCookie('slideshowOffset',RegExp.$1);}else if(currentImageIndex){createCookie('slideshowOffset',currentImageIndex);}}
