// $Id: $

function findPos(obj) {
	var curleft = 0;
	var curtop = 0;


	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft - obj.scrollLeft;   
			curtop += obj.offsetTop - obj.scrollTop;   
			
			var position = '';   
			
			if (obj.style&&obj.style.position) 
				position = obj.style.position.toLowerCase();   
				
			if ((position == 'absolute')||(position == 'relative')) 
				break;
			
			while (obj.parentNode!=obj.offsetParent) {
			    obj = obj.parentNode;
			    
			    curleft -= obj.scrollLeft;    
			    curtop -= obj.scrollTop;   
			}

			obj = obj.offsetParent;
		}
	} else {
		if (obj.style && obj.style.left)
			curleft += obj.style.left;
		else     
			if (obj.x)
				curleft += obj.x;

		if (obj.style && obj.style.top)
			curtop += obj.style.top;
		else
			if (obj.y)
				curtop += obj.y;
	}
	
	return {left:curleft,top:curtop};
}

function popImage(imageURL,imageTitle,imgID) {
	tb_show(imageTitle, imageURL, false);
}

function popImageSize(imageURL,imageTitle,imgID,sizeW,sizeH) {
	tb_show(imageTitle, imageURL, false, sizeW, sizeH);
}

function popImageGroup(imageURL,imageTitle,imageGroup,imgID,sizeW,sizeH) {
	tb_show(imageTitle, imageURL, imageGroup, sizeW, sizeH);
}

function popImage_old(imageURL,imageTitle,imgID) {
	// Set the horizontal and vertical position for the popup
	
	var PositionX = 100;
	var PositionY = 100;
	
	if (document.getElementById(imgID)) {
		PositionX = findPos(document.getElementById(imgID)).left;
		PositionY = findPos(document.getElementById(imgID)).top;
	}
	
	// Set these value approximately 20 pixels greater than the
	// size of the largest image to be used (needed for Netscape)
	
 	var defaultWidth  = 500;
	var defaultHeight = 500;
	
	// Set autoclose true to have the window close automatically
	// Set autoclose false to allow multiple popup windows
	
	var AutoClose = true;
	
	update_stats(imageURL);
	
	if (navigator.appVersion.charAt(0)>="4") {
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
	}
	
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	
	if (isNN) {
		imgWin=window.open('about:blank','',optNN);
	}
	
	if (isIE) {
		imgWin=window.open('about:blank','',optIE);
	}
	
	with (imgWin.document){
		writeln('<html>');
		writeln('	<head>');
		writeln('		<title>Loading...</title>');
		writeln('		<style>body{margin:0px;}</style>');
		
		writeln('		<sc'+'ript>');
		writeln('			var isNN,isIE;');
		
		writeln('			if (navigator.appVersion.charAt(0)>="4") {');
		writeln('				isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('				isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;');
		writeln('			}');
		
		writeln('			function reSizeToImage() {');
		writeln('				if (isIE) {');
		writeln('					window.resizeTo(300,300);');
		writeln('					width=300-(document.body.clientWidth-document.images[0].width);');
		writeln('					height=300-(document.body.clientHeight-document.images[0].height);');
		writeln('					window.resizeTo(width,height);');
		writeln('				}');
		
		writeln('				if (isNN) {');
		writeln('					window.innerWidth=document.images["pic"].width;');
		writeln('					window.innerHeight=document.images["pic"].height;');
		writeln('				}');
		writeln('			}');
		
		writeln('			function doTitle() { ');
		writeln('				document.title="'+imageTitle+'";');
		writeln('			}');
		writeln('		</sc'+'ript>');
		
		if (!AutoClose) {
			writeln('	</head>');
			
			writeln('	<body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		} else {
			writeln('	</head>');
			
			writeln('	<body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onclick="self.close()" onblur="self.close()">');
		}
		
		writeln('		<img name="pic" src='+imageURL+' style="display:block">');
		writeln('	</body>');
		writeln('</html>');
		
		close();		
	}
}

function popImage_new(imageURL,imageTitle,imgID) {
	// Set the horizontal and vertical position for the popup
	
	var PositionX = 100;
	var PositionY = 100;
	
	var p=document.getElementById(imgID);
	
	if (p) {
		PositionX = findPos(p).left;
		PositionY = findPos(p).top;
	}
	
	// Set these value approximately 20 pixels greater than the
	// size of the largest image to be used (needed for Netscape)
	
	var defaultWidth  = 500;
	var defaultHeight = 500;
	
	// Set autoclose true to have the window close automatically
	// Set autoclose false to allow multiple popup windows
	
	var AutoClose = true;
	
	update_stats(imageURL);
	
	if (document.all && !window.opera) {
		var canvas = document.createElement('img');
		
		canvas.src = p.src;
		
		// Added Border and Dropshadow
		canvas.style.filter = "progid:DXImageTransform.Microsoft.DropShadow(Color=#AAAAAA, OffX=3, OffY=3, Positive=1)";
		canvas.style.border = "solid 5px #fff";
	} else {
		var canvas = document.createElement('canvas');

		
		var w=p.width;
		var h=p.height;
		
		canvas.style.width = canvas.width = w + 24;
		canvas.style.height = canvas.height = h + 24;
		
		var context = canvas.getContext('2d');
		context.save();
		
		// Added by darookee
		// Creates a Border and another border
		// And a Dropshadow
		context.fillStyle = 'rgba(0,0,0,0.1)';
		context.fillRect(0,0,w+12,h+12);
		
		context.fillStyle = 'rgba(0,0,0,0.11)';
		context.fillRect(-6,-6,w+12,h+12);
		
		context.fillStyle = '#ffffff';
		context.fillRect(-5,-5,w+10,h+10);
		
		try {
			context.drawImage(p, 0, 0, w, h);
		} catch(err) {
//			console.log("09-p.src: "+canvas.oImage.src+", w: "+canvas.oImage.width+", h: "+canvas.oImage.height+", err: "+err);
			
			return null;
		}
		
		context.restore();
	}
	
	canvas.left = p.left;
	canvas.top = p.top;
	canvas.id = p.id;
	canvas.angle = p.angle;
	canvas.alt = p.alt;
	canvas.title = p.title;
	
	canvas.style.zIndex = p.style.zIndex;		
//	canvas.style.left = canvas.left = p.style.left;
//	canvas.style.top = canvas.top = p.style.top;
	canvas.style.left = p.style.left;
	canvas.style.top = p.style.top;
	canvas.style.position = p.style.position;
	canvas.style.display = p.style.display;
	canvas.style.visibility = p.style.visibility;
	
	p.parentNode.appendChild(canvas);
}

