//position globals
var posTitle;
var posType;
var posBy;
var posCopy;
var posCopyDate;
var posImg;
var posPrevImg;
var posNextImg;

/***********************************************
* Image Thumbnail viewer- c Dynamic Drive (www.dynamicdrive.com)
* Last updated Sept 26th, 03'. This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//===========================================================================
// *** showSingle ***		
//---------------------------------------------------------------------------
//     CALLED WITH:
//	   RETURNS:  boolean
//         PURPOSE:
//      WRITTEN BY:  visit http://www.dynamicdrive.com/
// MODIFICATION BY:  Christian Hankel
//===========================================================================
function showSingle(ttl,typ,by,crBy,crYr,pth,lr){
	//close the word layer and set the globals
	CloseWordLayer();
	
	//get the image
	var thisimg = new Image();
	thisimg.onload = function(){loadSingle(thisimg,ttl,typ,by,crBy,crYr,lr)};
	thisimg.src = pth;
}
//end showPic

//function showSingle(ttl,typ,by,crBy,crYr,pth,lr){
function loadSingle(thisimg,ttl,typ,by,crBy,crYr,lr){
	if (ie || ns6){
		var horzpos;
    var vertpos;
		var thisimg;
		var divnav;
		
		//get the main div		
			//OBSOLETE:  imgobj = document.getElementById ? document.getElementById("showimage") : document.all.showimage;
		imgobj = document.getElementById("showimage");
		
		//get the width of the image
		var imgwd = thisimg.width;
	  
		//calculate the position of the layer
		vertpos = PageVertPos(imgwd);
		horzpos = PageHorzPos(lr, imgwd);
		
		//set the position and width of the div object
    imgobj.style.left = horzpos+"px";
		imgobj.style.top  = vertpos+"px";
		imgobj.style.width = imgwd+"px";
		
		//construct strings for each of the sub divs
		/*divnav 	= '<div id="imgnav">'
							+ '<span id="imgclosetext"'
							+ 'onClick="closepreview()"'
							+ 'onmouseover="cursorchange_img(closePointer);return true;"' 
							+ 'onmouseout="cursorchange_img(closeMove);return true;">close</span></div>';*/
		divnav 	= '<div id="imgnav"><span id="imgclosetext" onClick="closepreview()">close</span></div>';
    //concatenate the strings and turn on the object   
		imgobj.innerHTML = divtitleby(ttl, typ, by) + divimg(thisimg.src) + divcopy(crYr, crBy) + divnav;
		imgobj.style.visibility = "visible";		
    return false;
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
	return true;
}
//end showSingle

//===========================================================================
// *** showPic ***		
//---------------------------------------------------------------------------
//     CALLED WITH:
//	   RETURNS:  boolean
//         PURPOSE:
//      WRITTEN BY:  Christian Hankel
//===========================================================================
function showPic(pos, lr, hasNav){
	//close the word layer and set the globals
	CloseWordLayer();
	
	//check for out-of-bound values and wrap to front or back of array
	pos = wraparray(pos, imgs.length, 6);
		
	//set position globals
	setpos(pos);
	
	//get the image
	var thisimg = new Image();
	thisimg.onload = function(){loadPic(thisimg, lr, hasNav)};
	thisimg.src = imgs[posImg];
}
//end showPic


//===========================================================================
// *** loadPic ***		
//---------------------------------------------------------------------------
//     CALLED WITH:
//	   RETURNS:  boolean
//         PURPOSE:
//      WRITTEN BY:  visit http://www.dynamicdrive.com/
// MODIFICATION BY:  Christian Hankel
//===========================================================================
function loadPic(thisimg, lr, hasNav){ 
	if (ie || ns6){
		var horzpos;
    var vertpos;
		var divnav;
		var spanclose;
		
		//get the main div		
			//OBSOLETE:  imgobj = document.getElementById ? document.getElementById("showimage") : document.all.showimage;
		imgobj = document.getElementById("showimage");
		
		//get the width of the image
		var imgwd = thisimg.width;
		 
		//calculate the position of the layer
		vertpos = PageVertPos(imgwd);
		horzpos = PageHorzPos(lr, imgwd);
		
		//set the position and width of the div object
    imgobj.style.left = horzpos+"px";
		imgobj.style.top  = vertpos+"px";
		imgobj.style.width = imgwd+"px";
		
		//construct strings for each of the sub divs
		/*spanclose	= '<span id="imgclosetext"'
							+ 'onClick="closepreview()"'
							+ 'onmouseover="cursorchange_img(closePointer);return true;"' 
							+ 'onmouseout="cursorchange_img(closeMove);return true;">close</span>';
		if (hasNav){	
			divnav 	= '<div id="imgnav">'
							+ '<span id="imgprevtext"'
							+ 'onClick="return showPic('+posPrevImg+','+lr+',true)"'
							+ 'onmouseover="cursorchange_img(prevPointer);return true;"' 
							+ 'onmouseout="cursorchange_img(prevMove);return true;">prev</span>'
							+ spanclose
							+ '<span id="imgnexttext"'
							+ 'onClick="return showPic('+posNextImg+','+lr+',true)"'
							+ 'onmouseover="cursorchange_img(nextPointer);return true;"' 
							+ 'onmouseout="cursorchange_img(nextMove);return true;">next</span></div>';
		}else{
			divnav 	= '<div id="imgnav">'+spanclose+'</div>';
		}*/
		spanclose	= '<span id="imgclosetext" onClick="closepreview()">close</span>';
		if (hasNav){	
			divnav 	= '<div id="imgnav">'
							+ '<span id="imgprevtext" onClick="return showPic('+posPrevImg+','+lr+',true)">prev</span>'
							+ spanclose
							+ '<span id="imgnexttext" onClick="return showPic('+posNextImg+','+lr+',true)">next</span></div>';
		}else{
			divnav 	= '<div id="imgnav">'+spanclose+'</div>';
		}
		
    //concatenate the strings and turn on the object   
		imgobj.innerHTML	= divtitleby(imgs[posTitle], imgs[posType], imgs[posBy]) 
											+ divimg(imgs[posImg])
											+ divcopy(imgs[posCopyDate], imgs[posCopy]) 
											+ divnav;
		imgobj.style.visibility = "visible";		
    return false;
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
	return true;
}
//end loadPic

//===========================================================================
// *** cursorchange_img ***		
//---------------------------------------------------------------------------
//     CALLED WITH:  cursorStyle  - type of cursor to change to
//         PURPOSE:  Change the style of the cursor to indicate a rollover.
//      WRITTEN BY:  Christian Hankel
//===========================================================================
/*function cursorchange_img(cursorStyle){
	switch(cursorStyle){
		case titleMove :
			imgtitletext.style.cursor="move";
			break;
		case titleText :
			imgtitletext.style.cursor="text";
			break;
		case byMove :
			imgbytext.style.cursor="move";
			break;
		case byText :
			imgbytext.style.cursor="text";
			break;
		case copyMove :
			imgcopytext.style.cursor="move";
			break;
		case copyText :
			imgcopytext.style.cursor="text";
			break;
		case prevMove :
			imgprevtext.style.cursor="move";
			break;
		case prevPointer :
			imgprevtext.style.cursor="pointer";
			break;      
		case closeMove :
			imgclosetext.style.cursor="move";
			break;
		case closePointer :
			imgclosetext.style.cursor="pointer";
			break;
		case nextMove :
			imgnexttext.style.cursor="move";
			break;
		case nextPointer :
			imgnexttext.style.cursor="pointer";
			break;
		default :
			break;
	}//endswitch
}*/
//end cursorchange_img

//===========================================================================
// *** setpos ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:  Christian A. Hankel
//===========================================================================
function setpos(pos){
	posTitle		= (pos * 6) + 0;
	posType			= (pos * 6) + 1;
	posBy				= (pos * 6) + 2;
	posCopy			= (pos * 6) + 3;
	posCopyDate	= (pos * 6) + 4;
	posImg			= (pos * 6) + 5;
	posPrevImg	= pos - 1;
	posNextImg	= pos + 1;
}
//end setpos

//===========================================================================
// *** divtitleby ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:  Christian A. Hankel
//===========================================================================
function divtitleby(ttl, typ, by){
	/*return 	'<div id="imgtitle">'
					+ '<span id="imgtitletext"'
					+ 'onmouseover="cursorchange_img(titleText);return true;"' 
					+ 'onmouseout="cursorchange_img(titleMove);return true;">'+ttl+'</span></div>'
					+ '<div id="imgby">'
					+ '<span id="imgbytext"'
					+ 'onmouseover="cursorchange_img(byText);return true;"'
					+ 'onmouseout="cursorchange_img(byMove);return true;">'+typ+' by '+by+'</span></div>';*/
	return 	'<div id="imgtitle"><span id="imgtitletext">'+ttl+'</span></div>'
			+ '<div id="imgby"><span id="imgbytext">'+typ+' by '+by+'</span></div>';
}
//end divtitleby

//===========================================================================
// *** divcopy ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:  Christian A. Hankel
//===========================================================================
function divcopy(copyYr, copyBy){
	/*return	'<div id="imgcopy">'
					+ '<span id="imgcopytext"'
					+ 'onmouseover="cursorchange_img(copyText);return true;"' 
					+ 'onmouseout="cursorchange_img(copyMove);return true;">'
					+ 'copyright (c) '+copyYr+' '+copyBy+'</span></div>';*/
	return	'<div id="imgcopy"><span id="imgcopytext">copyright &copy; '+copyYr+' '+copyBy+'</span></div>';
}
//end divcopy

//===========================================================================
// *** divimg ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:  Christian A. Hankel
//===========================================================================
function divimg(imgPos){
	return	'<img src="'+imgPos+'" id="imgimage">';
}
//end divimg

//===========================================================================
// *** PageVertPos ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:  
//===========================================================================
function PageVertPos(imgwd){
	var pgyoffset;
	var vertpos;
	var op = (window.opera && window.innerHeight);
		
	pgyoffset = ns6 ? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop); //used in Opera calculation
	vertpos = ns6 ? pageYOffset+10 : ietruebody().scrollTop+10;
	if (op){ //compensate for Opera toolbar
		vertpos = pgyoffset+(window.innerHeight/2)-(imgwd);
		vertpos = Math.max(pgyoffset, vertpos)+10;
	}
	return vertpos;
}
//end PageVertPos

//===========================================================================
// *** PageHorzPos ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:
//			MODIFIED BY:	Christian A. Hankel  
//===========================================================================
function PageHorzPos(lr, imgwd){
	var horzpos;
	var edgeofpage;
	var ns6winwd;
	var iewinwd;
	var iescrollwd;
	
	//calculate each of these values once
	ns6winwd = window.innerWidth;
	iewinwd = ietruebody().clientWidth;
	iescrollwd = ietruebody().scrollLeft;		
	
	if (lr == _left){
		horzpos = ns6 ? pageXOffset+(ns6winwd/2)-(imgwd) : iescrollwd+(iewinwd/2)-(imgwd);
		edgeofpage = ns6 ? pageXOffset : iescrollwd; //get the left edge of the window
		if (horzpos < (edgeofpage + 10)){
			horzpos = edgeofpage + 10;
		}
 	}else if (lr == _right){
		horzpos = ns6 ? pageXOffset+(ns6winwd/2) : iescrollwd+(iewinwd/2);
		edgeofpage = ns6 ? ns6winwd : iescrollwd+(iewinwd); //get the right edge of the window
		if ((horzpos + imgwd) > (edgeofpage - 10)){
			horzpos = edgeofpage - imgwd - 10;
		}
	}else if (lr == _center){      
		horzpos = ns6 ? pageXOffset+(ns6winwd/2)-(imgwd/2) : iescrollwd+(iewinwd/2)-(imgwd/2)
	}//endif
	return horzpos
}
//end PageHorzPos

//===========================================================================
// *** CloseWordLayer ***		
//---------------------------------------------------------------------------
//      WRITTEN BY:	Christian A. Hankel  
//===========================================================================
function CloseWordLayer(){		
	//if a word layer is open, close it
	if (wordlayer == true){
		wordobj.style.visibility="hidden";			
	}
			
	//set the layer type globals
	wordlayer = false;
	imglayer = true;
}
//end CloseWordLayer
	
