//workaround for RE-writing window HTML
function writeHTML(target,HTML){
  target.document.write(HTML);
}

var popUpWindow = '';
var winHTML = '';

function newWindow(target, caption, format, setHeight, setWidth) {

  var _target = target; //source image to display
  var _caption = caption; //caption for popup window;
  var _format = format; //either "landscape" or "portrait" (324*406)
  var winl; //popup window top-left position from left
  var wint; //popup window top-left position from top 
 
  //size window according to format parameter
  formatting:
  switch (_format){
 	case 'landscape':
		h=324;
		w=406;
		break formatting;
	case 'portrait':
		h=406;
		w=324;
		break formatting;
	case 'custom':
		h=setHeight;
		w=setWidth;
		break formatting;
  }
  
  // centre popup window if possible
  if(screen.width){
  	winl = (screen.width-w)/2;
  	wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;

  settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
 
  
  popUpWindow = window.open('../assets/scripts/popup.htm','test',settings);

  //open Window and write image HTML dynamically
  winHTML='<HTML><TITLE>'+_caption+'</TITLE><BODY>';
  winHTML += '<IMG style="position:absolute; top=0; left=0;" src="'+target+'" width="'+w+'" height="'+h+'" border=0>';
  winHTML += '</BODY></HTML>';

  popUpWindow.resizeTo(w,h);

 
  //workaround for RE-writing window
  setTimeout('writeHTML(popUpWindow,winHTML)','200');
  popUpWindow.window.focus();

}