/**
 * USAGE
 *
 * <script src='path_to_iwPopImage.js' type='text/javascript'></script>
 *
 * <a href="#" onclick="iwPopImage('path/to/file','Popup Window Title')>open image</a>
 *
 */

var scr_pos_x=150;
var scr_pos_y=150;

var scr_default_height=500;
var scr_default_width =500;

var win=null;
function iwPopImage(src, title){
	var html = "<html><head><title>"+title+"</title></head><body style='margin:0px;'><a href='' onclick='self.close();'><img alt='click to close' title='click to close' border='0' id='imgContainer' onload='opener.__imageLoaded();' src='"+src+"'></a></body></html>";
		
	win = window.open('about:blank','','scrollbars=no,width='+scr_default_width+',height='+scr_default_height+',left='+scr_pos_x+',top=' + scr_pos_y);
	win.document.writeln(html);
}
	
function __imageLoaded(){
	var img=win.document.getElementById('imgContainer');

	win.resizeTo(img.width,img.height);
	
	if( typeof(win.innerHeight) != 'undefined' ){
		height = win.innerHeight;
	}else if( typeof(win.document.body.clientHeight) != 'undefined'){
		height 	= win.document.body.clientHeight;
	}else if( typeof(win.document.documentElement.clientHeight) != 'undefined'){
		height 	= win.document.documentElement.clientHeight;
	}


	win.resizeTo(img.width,img.height+(img.height-height));
}