/***********************************************
* Image Thumbnail viewer- © 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
***********************************************/
//modifications for BPW by billy 6.8.05

function truebody(){
	return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body;
}

var drag = 1;
var last_img = null;
function enlarge(which, e, position, imgwidth, imgheight){
	if (document.all || document.getElementById) {
		if (last_img == which) {
			closepreview();
			return;
		}
		last_img = which;

		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage;
		
		if (position=="center") {
			pgyoffset=_isMozilla_? parseInt(pageYOffset) : parseInt(truebody().scrollTop);
			horzpos=_isMozilla_? pageXOffset+window.innerWidth/2-imgwidth/2 : truebody().scrollLeft+truebody().clientWidth/2-imgwidth/2;
			vertpos=_isMozilla_? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+truebody().clientHeight/2-imgheight/2;
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
				vertpos=pgyoffset+window.innerHeight/2-imgheight/2;
			vertpos=Math.max(pgyoffset, vertpos);
		}
		else{
			var horzpos=_isMozilla_? pageXOffset+e.clientX : truebody().scrollLeft+event.clientX;
			var vertpos=_isMozilla_? pageYOffset+e.clientY : truebody().scrollTop+event.clientY;
		}

		if (horzpos < 0) horzpos = 2;
		if (vertpos < 0) vertpos = 2;
		crossobj.style.left=horzpos+"px";
		crossobj.style.top=vertpos+"px";

		crossobj.style.overflow = "hidden";	

		if (imgwidth > truebody().clientWidth) { 
			crossobj.style.width = (truebody().clientWidth - 10) + 'px';
			crossobj.style.overflow = "auto";
		}
		else
			crossobj.style.width = imgwidth + 'px';; 
		
		if (imgheight > truebody().clientHeight) {
			crossobj.style.height = (truebody().clientHeight - 10) + 'px';
			crossobj.style.overflow = "auto";
		}
		else
			crossobj.style.height = imgheight + 'px';
	
		crossobj.innerHTML='<div id="dragbar" title="Drag"' + ((drag) ? ' style="background:url(\'images/drag_bar.gif\') repeat-x;"><img src="images/drag_bar.gif" border="0" />' : '>') + '</div><img src="'+which+'" onClick="closepreview()" />';
		crossobj.style.visibility="visible";
		crossobj.style.display="block";
		toggleSelects('hide');
		return false;
	}
	else { //if NOT IE 4+ or NS 6+, simply display image in full browser window
		openWin('imageviewer.html?url=' + which,'_pic','no','no','no','no','yes','no','yes',imgwidth,imgheight,5,5,0,0,1);
		return false; //open in new win
	}
}

function closepreview() {
	last_img = null;
	crossobj.style.visibility="hidden";
	crossobj.style.display="none";
	toggleSelects('show');
}

function drag_drop(e){
	if (_isIE_&&dragapproved){
		crossobj.style.left=tempx+event.clientX-offsetx+"px";
		crossobj.style.top=tempy+event.clientY-offsety+"px";
	}
	else if (_isMozilla_&&dragapproved){
		crossobj.style.left=tempx+e.clientX-offsetx+"px";
		crossobj.style.top=tempy+e.clientY-offsety+"px";
	}
	return false;
}

function initializedrag(e){
	if (_isIE_&&event.srcElement.id=="dragbar"||_isMozilla_&&e.target.id=="dragbar") {
		offsetx=_isIE_? event.clientX : e.clientX;
		offsety=_isIE_? event.clientY : e.clientY;
		
		tempx=parseInt(crossobj.style.left);
		tempy=parseInt(crossobj.style.top);
		
		dragapproved=true;
		document.onmousemove=drag_drop;
	}
}

document.onmousedown=initializedrag;
document.onmouseup=new Function("dragapproved=false");

