previousLargeView=document.createElement('div');
nextLargeView=document.createElement('div');
oLargeView=new LargeView();
currentPNZSearchSerials=[];
currentPNZLargeView=0;
jsLargeViewEnabled=true;
pnzFadeInterval={};
currentPNZImageDetails={};
prevPNZImageDetails={};
nextPNZImageDetails={};
prevPNZImageKeywords=[];
currentPNZImageKeywords=[];
nextPNZImageKeywords=[];
function position() {
	var shield=document.getElementById('jsLargeViewShield');
	var view=document.getElementById('jsLargeView');
	var el=document.getElementById('jsLargeViewContent');
	var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;
	scrollTop=parseInt(scrollTop);
	shield.style.top=scrollTop+'px';
	if((parseInt(el.clientHeight)+67) < (parseInt(shield.clientHeight)-30))
		view.style.top=(scrollTop+15)+'px';
}
window.resizeActions[window.resizeActions.length]=position;
window.onscroll=position;
function showLargeView(num,fade) {
	var el=document.getElementById('jsLargeViewContent');
	var view=document.getElementById('jsLargeView');
	var shield=document.getElementById('jsLargeViewShield');
	var result={};
	var nextResult={};
	var prevResult={};
	var theseKeywords='';
	var doFade=(fade=="nofade")?false:true;
	if(!currentPNZSearchSerials.length) currentPNZSearchSerials=oLargeView.getSerials(pnzZoneID,pnzSearchID);
	if(!currentPNZSearchSerials.length) {
		jsLargeViewEnabled=false;
		return false;
	}
	try {
		el.innerHTML=_cf_loadingtexthtml+'<br><br><br><br><br><br><br>';
		if(doFade) {
			opacify('jsLargeView',0,100,250);
			opacify('jsLargeViewShield',0,80,250);
			document.body.style.overflow='hidden';
			document.body.parentNode.style.overflow='hidden';
		}
		position();
		result=oLargeView.getLargeView(pnzZoneID,currentPNZSearchSerials[num-1]);
		el.innerHTML=result.content;
		document.getElementById('keywordsContent').innerHTML=buildKeywordList(result.KEYWORDS);
		currentPNZImageKeywords=result.KEYWORDS;
		currentPNZLargeView=num;
		currentPNZImageDetails=result.DETAILS;
		toggleButtons();
		return true;
	} catch(x) {
		window.setTimeout("hideLargeView()",500);
		return false;
	}
}
function buildKeywordList(keywords) {
	var keyString='';
	for(var i=0;i<keywords.length;i++) {
		keyString+='<a href="/Main/GalleryMain/index.cfm/SearchType/QuickSearch/FuseAction/Search/SearchScope/AllPhotos/keywords/'+encodeURIComponent(keywords[i])+'/">'+keywords[i]+'</a>';
		if(i<(keywords.length-1)) {
			keyString+=', ';
		}
	}
	return keyString;
}
function ping() {
	oLargeView.ping();
}
window.setInterval(ping,900000); // Ping server every 15 minutes to keep the session scope active
function toggleButtons() {
	document.getElementById('pnzShowSimilarButton').className='function-showsimilar'+((currentPNZImageDetails.SIMILARTOSERIAL)?'':' disabled');
	document.getElementById('pnzHiResDownloadButton').className='function-downloadhires'+((currentPNZImageDetails.HIRESLINK)?'':' disabled');
	document.getElementById('pnzCompDownloadButton').className='function-downloadcomp'+((currentPNZImageDetails.COMPLINK)?'':' disabled');
	document.getElementById('pnzLargeViewLightboxButton').className=((currentPNZImageDetails.INLIGHTBOX)?'function-removefromlightbox':'function-addtolightbox')+((currentPNZImageDetails.ENABLELIGHTBOX)?'':' disabled');
	document.getElementById('pnzLargeViewLightboxCaption').innerHTML=(currentPNZImageDetails.INLIGHTBOX)?'Remove from Lightbox':'Add to Lightbox';
}
function showNextLargeView() {
	var el=document.getElementById('jsLargeViewContent');
	var result={};
	if(currentPNZLargeView<currentPNZSearchSerials.length) {
		showLargeView(++currentPNZLargeView,"nofade");
	}	
}
function showPreviousLargeView() {
	var el=document.getElementById('jsLargeViewContent');
	var result={};
	if(currentPNZLargeView>1) {
		showLargeView(--currentPNZLargeView,"nofade");
	}	
}
function hideLargeView() {
	opacify('jsLargeView',100,0,250);
	opacify('jsLargeViewShield',80,0,250);
	document.body.style.overflow='auto';
	document.body.parentNode.style.overflow='auto';
	//scroll 1px down and 1px back up, to make scrollbar reappear in webkit-based browsers (opera, chrome)
	window.scrollBy(0,1);
	window.scrollBy(0,-1);
}

function downloadComp(){
	if(currentPNZImageDetails.COMPLINK)
		window.open('/'+pnzZoneID+'/largeViewPopup_'+pnzGallery+'/index.cfm?fuseAction=compImageView&compImageID='+currentPNZSearchSerials[currentPNZLargeView-1], '_blank', 'top=50,left=70,width=820,height=600,scrollbars=1,resizable=1');
}
function downloadHiRes(){
	if(currentPNZImageDetails.HIRESLINK)
		window.open('/'+pnzZoneID+'/largeViewPopup_'+pnzGallery+'/index.cfm?fuseAction=hiRes&hiResImageName='+currentPNZSearchSerials[currentPNZLargeView-1], '_blank', 'top=50,left=70,width=955,height=600,scrollbars=1,resizable=1');
}
function showSimilar(){
	if(currentPNZImageDetails.SIMILARTOSERIAL)
		window.location.href='/'+pnzZoneID+'/'+pnzNodeID+'/index.cfm?fuseAction=similar&serial='+currentPNZSearchSerials[currentPNZLargeView-1]+'&similarToSerial='+currentPNZImageDetails.SIMILARTOSERIAL;
}
function togglelightboxfromlargeview(){
	if(currentPNZImageDetails.ENABLELIGHTBOX) {
		var el = document.getElementById('togglelightbox' + currentPNZSearchSerials[currentPNZLargeView-1]);
		currentPNZImageDetails.INLIGHTBOX=!currentPNZImageDetails.INLIGHTBOX;
		toggleButtons();
		togglelightbox(el,currentPNZSearchSerials[currentPNZLargeView-1]);
	}
}
function opacify(id, opacStart, opacEnd, ms) {
	var delta = opacEnd-opacStart;
	var speed = 40; // 25 FPS
	var step = Math.round(delta/Math.round(ms/speed));
	var el=document.getElementById(id);
	setOpacity(el,opacStart);
	el.style.display='block';
	pnzFadeInterval[id]=window.setInterval(function(){opacity(el,step,opacEnd)},speed);
}
function setOpacity(el,opacity){
	el.opac = opacity;
	el.style.opacity = (opacity / 100);
	el.style.MozOpacity = (opacity / 100);
	el.style.KhtmlOpacity = (opacity / 100);
	el.style.filter = "alpha(opacity=" + opacity + ")";
}
function opacity(el,delta,opacEnd) {
	if((delta>0&&el.opac+delta>=opacEnd)||(delta<0&&el.opac+delta<=opacEnd)) {
		setOpacity(el,opacEnd);
		clearInterval(pnzFadeInterval[el.id]);
		if(opacEnd==0) el.style.display='none';
	} else {
		setOpacity(el,el.opac+delta);
	}
}
function showImageHistory(serial) {
	var el=document.getElementById('jsLargeViewContent');
	var result="";
	try {
		el.innerHTML=_cf_loadingtexthtml+'<br><br><br><br><br><br><br>';
		position();
		result=oLargeView.getImageHistory(serial);
		el.innerHTML=result;
		return true;
	} catch(x) {
		showLargeView(currentPNZLargeView,"nofade");
		return false;
	}
}
function closeImageHistory() {
	showLargeView(currentPNZLargeView,"nofade");
}
