document.writeln("<link rel='stylesheet' type='text/css' href='resizeimgs.css'>");
document.writeln("<div id='showimage'></div>");

// =============================================================================
// Updates
// =============================================================================
/*
** 11 Jan 2008 by Bruno Alexandre <" target=_blankhttp://forum.snitz.com/forum/pop_profile.asp?mode=display&id=4520>
		[showpic.asp]
		- Opening in a new window, the user can click in the image to close that window
		
		[resizeimgs.css]
		- Moved the CSS of the DIV that shows in the same page to the CSS file and added a 20px margin, you are free to remove it if you dont like it
		
		[resizeimgs.js]
		- Opening the image in the same page, the DIV will close if the user click in the image		
		- Added an automatic Scroll if using the "Show image in same window" so it jumps to the top in order to see the original image (it's quoted, unquoted if you want to use it)
		- The DIV that shows the image in the same no longer appears in the top of the page but in the top where the user stands in the scroll (so the user always sees it, instead need to scroll up to the top in order to see the original picture)
		- Also added the Dashed Red border to the pictures that are bigger than the size specified in the fixedWidth variable
**
*/
// =============================================================================
// Begin user defined variables
// =============================================================================
var resizeType = 1; // 0 = Dynamically resize to a fraction of the users desktop
                    //     width divided by the dynamicDivisor variable below. 
                    //     (i.e. 1024/4 = 256 or 1280/4 = 320)
                    // 1 = Resize the image if it is wider than the fixedWidth
                    //     variable below
var enlargeType    = 1     // 0 = Opens in the same window
			               // 1 = Opens in a new window
var fixedWidth     = 650;  // Resize the image if it is wider than this many 
                           // pixels. Only used when resizeType = 1.
var dynamicDivisor = 2;    // Resize images to users screen width divided by 
                           // this number. Only used when resizeType = 0.
var alignClose   = "left"; // Values are 'left' or 'right'. Default is right.
var topSpacing   = 25;      // Spaces the pop-up window this number of pixels 
                           // from the top of the window
var leftSpacing  = 25;      // Spaces the pop-up window this number of pixels 
                           // from the left of the window
// =============================================================================
// End of user defined variables
// =============================================================================




// =============================================================================
// Do not modify below this line
// =============================================================================
var ie=document.all
var ns=document.layers
var ns6=document.getElementById&&!document.all
var nsx,nsy,nstemp

function walkImages(){
    re = /^img/;
    if (document.images){
        for (a=0;a<document.images.length;a++){
          if (re.test(document.images[a].name)) resizeImage(document.images[a]);
        }
    }
}

function doimage(imgObj,event){
    if (document.images) enlargeimg(imgObj,event);
}

//Thumbnail image viewer- 
//© Dynamic Drive (www.dynamicdrive.com)

function resizeImage(thisimage) {
    if (resizeType == 0) fixedWidth = parseInt(screen.width/dynamicDivisor);
    if (thisimage.width > fixedWidth) {
		thisimage.width = fixedWidth;
		thisimage.style.cursor='pointer';
		thisimage.style.border='1px dashed #FF0000';
		thisimage.title='Click to enlarge';
	}
}

function enlargeimg(which,e){
    if (resizeType == 0) fixedWidth = parseInt(screen.width/dynamicDivisor);
	if (which.width < fixedWidth) {return false;}
	if (enlargeType == 0) {
		if (ie||ns6){
			crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage;
			if (crossobj.style.visibility=="hidden"){
				crossobj.style.left = (ns6? pageXOffset : document.body.scrollLeft) + leftSpacing;
				crossobj.style.top  = (ns6? pageYOffset : document.body.scrollTop) + topSpacing;
			    alignRE = /^left$/i;
				crossobj.innerHTML= (alignRE.test(alignClose)) ? '<div class="tvhead" align="left" id="drag"> <span class="tvclosex" onClick="closepreview();" style="cursor:pointer;"> X </span> <span class="tvclose" onClick="closepreview();">Close window</span> </div><img src="'+which.src+'" onClick="closepreview();" style="cursor:hand;" title="Click to close">' : '<div class="tvhead" align="right" id="drag"> <span class="tvclose" onClick="closepreview();">Close window</span> <span class="tvclosex" onClick="closepreview();" style="cursor:pointer;"> X </span> </div><img src="'+which.src+'" onClick="closepreview();" style="cursor:hand;" title="Click to close">';
				crossobj.style.visibility="visible";
				// scroll(0,0); // unquoted to automatically scroll the page to top
			}
			else
				crossobj.style.visibility="hidden";
				return false;
		}
		else if (document.layers){
			if (document.showimage.visibility=="hide"){
				document.showimage.document.write('<a href="#" onMouseover="drag_dropns(showimage);"><img src="'+which.src+'" style="border:none;"></a>');
				document.showimage.document.close();
				document.showimage.left=e.x;
				document.showimage.top=e.y;
				document.showimage.visibility="show";
				// scroll(0,0); // unquoted to automatically scroll the page to top
			}
			else
				document.showimage.visibility="hide";
				return false;
		}
		else
			return true;
	}
	else if (enlargeType == 1) {
			eval('window.open("showpic.asp?pic=' + which.src + '","","width='+which.width+'px,height='+which.height+'px,resizable=1,scrollbars=0")');
	}
}


function closepreview(){
	crossobj.style.visibility="hidden";
}

function drag_dropns(name){
	temp=eval(name);
	temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
	temp.onmousedown=gons;
	temp.onmousemove=dragns;
	temp.onmouseup=stopns;
}

function gons(e){
	temp.captureEvents(Event.MOUSEMOVE);
	nsx=e.x;
	nsy=e.y;
}
function dragns(e){
	temp.moveBy(e.x-nsx,e.y-nsy);
	return false;
}

function stopns(){
	temp.releaseEvents(Event.MOUSEMOVE);
}

function drag_drop(e){
	if (ie&&dragapproved){
	crossobj.style.left=tempx+event.clientX-offsetx;
	crossobj.style.top=tempy+event.clientY-offsety;
	}
	else if (ns6&&dragapproved){
	crossobj.style.left=tempx+e.clientX-offsetx;
	crossobj.style.top=tempy+e.clientY-offsety;
	}
	return false;
}

function initializedrag(e){
	if (ie&&event.srcElement.id=="drag"||ns6&&e.target.id=="drag"){
	offsetx=ie? event.clientX : e.clientX;
	offsety=ie? 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");
document.onload=walkImages();
