function PopWindow( url ) {
  // URL of the page to be loaded into the new window:
  if ( url == null ) url = "";
  this.url = url;
  this.winHandle = null;
  this.winName = "mx_view";
  // Width and height of the new window:
  this.width = null;
  this.height = null;
  // window features
  this.directories = null;
  this.location = null;
  this.menubar = null;
  this.resizable = 1;
  this.scrollbars = 1;
  this.status = 1;
  this.toolbar = 1;
}

// Method to open a new window:
function PUW_open() {
  var features = "";
  for ( var prop in this ) {
    with ( this ) {
      if ( typeof eval( prop ) != "function" ) {
        if ( prop != "url" && prop != "winHandle" ) {
          if ( eval( prop ) != null ) {
            if ( prop == "width" || prop == "height" ) {
              features += prop + "=" + eval( prop ) + ",";
            } else if ( eval( prop ) ) {
              features += prop + "=yes,";
            } else {
              features += prop + "=no,";
            }
          }
        }
      }
    }
  }

  this.winHandle = window.open( this.url, this.winName, features+",top=0,left=0" );
  if ( this.url == "" ) this.document = this.winHandle.document;
  // Browser bug fix:
  if ( !this.winHandle.opener ) this.winHandle.opener = self;
}
PopWindow.prototype.open = PUW_open;

// Close the window:
function PUW_close() {
  if ( this.winHandle != null ) this.winHandle.close();
  this.winHandle = null;
}
PopWindow.prototype.close = PUW_close;


function PUW_setWidth( pixels ) {
  pixels = parseInt( pixels );
  if ( !isNaN( pixels ) && pixels >= 0 ) this.width = pixels;
}
PopWindow.prototype.setWidth = PUW_setWidth;


function PUW_setHeight( pixels ) {
  pixels = parseInt( pixels );
  if ( !isNaN( pixels ) && pixels >= 0 ) this.height = pixels;
}
PopWindow.prototype.setHeight = PUW_setHeight;


function PUW_setDirectories( booleanValue ) {
  this.directories = booleanValue;
}
PopWindow.prototype.setDirectories = PUW_setDirectories;


function PUW_setLocation( booleanValue ) {
  this.location = booleanValue;
}
PopWindow.prototype.setLocation = PUW_setLocation;


function PUW_setMenubar( booleanValue ) {
  this.menubar = booleanValue;
}
PopWindow.prototype.setMenubar = PUW_setMenubar;


function PUW_setResizable( booleanValue ) {
  this.resizable = booleanValue;
}
PopWindow.prototype.setResizable = PUW_setResizable;


function PUW_setScrollbars( booleanValue ) {
  this.scrollbars = booleanValue;
}
PopWindow.prototype.setScrollbars = PUW_setScrollbars;


function PUW_setStatus( booleanValue ) {
  this.status = booleanValue;
}
PopWindow.prototype.setStatus = PUW_setStatus;


function PUW_setToolbar( booleanValue ) {
  this.toolbar = booleanValue;
}
PopWindow.prototype.setToolbar = PUW_setToolbar;



// Call Function
function pop(picture,number,audioURL){

//		alert(audioURL);
		if(audioURL)
		{
			playaudio(audioURL);
		}
		else
		{}
       var win = new PopWindow();
       win.setWidth( (window.screen.width-10) );
       win.setHeight( (window.screen.height-112) );
       win.open();            // open an empty window
       win.document.open();   // open document for writing
       win.document.write( '<html>\n<head>\n<META http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<title>MAGIX PictureViewer</title>\n<style type="text/css">A {font-family: verdana, arial, helvetica, geneva, trebuchet ms, sans-serif;font-size: 16px;color: #666666;font-weight: bold;text-decoration: none;text-align : center;}\n}\n</style>\n</head>\n<body onload=set_counter()>\n\n' );

	   win.document.writeln( "<script language=\"JavaScript\">\n" );
	// Write Pictures
	   win.document.write( "var pictures = new Array;\npictures[0]=\"dummy\";\n" );
        for(i=1;i<picture_text.length;i++){
            win.document.write( "pictures["+i+"]=\""+pictures[i].replace(" ","%20")+"\";\n" ); // Write to Array
        }
	   win.document.writeln( "\n" );

	// Write Kommentar
	   win.document.write( "var picture_text = new Array;\npicture_text[0]=\"dummy\";\n" );
        for(i=1;i<picture_text.length;i++){
            win.document.write( "picture_text["+i+"]='"+picture_text[i].substr(0,picture_text[i].indexOf('|'))+"';\n" ); // Write to Array
        }

	   win.document.writeln( "var number=" + number + ";\n" );
	   win.document.writeln( "var time_on=0;\n" );

//	   win.document.writeln( "alert(pictures.length-1)\n" );
//	   win.document.writeln( "document.input.counter_all.value=pictures.length;\n");

	   win.document.writeln( "\nfunction change_pic(direction,time_cange){");
	   win.document.writeln( "if(direction == 1 && number < (pictures.length-1)){");
	   win.document.writeln( "	number = (number + 1);");
	   win.document.writeln( "}else if(direction == -1 && number > 1){");
	   win.document.writeln( "	number = (number - 1);");
	   win.document.writeln( "}\n");
	   win.document.writeln( "document.viewer.src=pictures[number];\n");
	   win.document.writeln( "document.input.kommentar.value=picture_text[number];\n");
	   win.document.writeln( "document.input.counter.value=number;\n");
	   win.document.writeln( "document.input.counter_all.value=pictures.length-1;\n");
	   win.document.writeln( "if(time_cange==1){time_on=0;}\n");
	    win.document.writeln( "}\n");

	   win.document.writeln( "\nfunction jump_pic(jump_direction){");
	   win.document.writeln( "if(jump_direction == 1 && number < (pictures.length-1)){");
	   win.document.writeln( "	number = (pictures.length-1);");
	   win.document.writeln( "}else if(jump_direction == -1 && number > 1){");
	   win.document.writeln( "	number = 1;");
	   win.document.writeln( "}\n");
	   win.document.writeln( "document.viewer.src=pictures[number];\n");
	   win.document.writeln( "document.input.kommentar.value=picture_text[number].substr(0,picture_text[number].indexOf('|'));\n");
	   win.document.writeln( "document.input.counter.value=number;\n");
	   win.document.writeln( "document.input.counter_all.value=pictures.length-1;\n");
	   win.document.writeln( "time_on=0;\n");
	   win.document.writeln( "}\n");

	   win.document.writeln( "\nfunction set_counter(){");
	   win.document.writeln( "document.input.counter.value=number;\n");
	   win.document.writeln( "document.input.counter_all.value=pictures.length-1;\n");
	   win.document.writeln( "}\n");

	   win.document.writeln( "\nfunction start_slideshow(){");
	   win.document.writeln( "\ntime_on=1;\n");
	   win.document.writeln( "\ntime_slideshow();\n");
	   win.document.writeln( "}\n");

	   win.document.writeln( "\nfunction time_slideshow(){");
	   win.document.writeln( "\nif(time_on==1){\n");
	   win.document.writeln( "	var w=window.setTimeout(\"time_slideshow()\",5000);\n");
	   win.document.writeln( "change_pic(1,0);\n\n}\n");
	   win.document.writeln( "}\n");

	   win.document.writeln( "</script>\n" );

       win.document.writeln( "\n<form name=\"input\"><table border=\"0\" width=\"800\" height=\"600\">\n");
       win.document.writeln( '\n<tr valign=\"top\"><td align=\"left\" valign=\"middle\"><a href="javascript:jump_pic(-1);"><img src=\"mxassets/btn_back.gif\" border=\"0\"></a></td><td align=\"left\" valign=\"middle\"><a href="javascript:change_pic(-1,1);"><img src=\"mxassets/btn_step_back.gif\" border=\"0\"></a></td><td align=\"left\" valign=\"middle\"><a href="javascript:change_pic(1,1);"><img src=\"mxassets/btn_step_forward.gif\" border=\"0\"></a></td><td align=\"left\" valign=\"middle\"><a href="javascript:start_slideshow();"><img src=\"mxassets/btn_play.gif\" border=\"0\"></a></td><td align=\"left\" valign=\"middle\"><a href="javascript:jump_pic(1);"><img src=\"mxassets/btn_forward.gif\" border=\"0\"></a></td><td align=\"right\" valign=\"middle\" width=\"50\"><input style=\"border:0px; text-align:right; font-family: verdana, arial, helvetica, geneva, trebuchet ms, sans-serif;font-size: 12px;color: #666666;font-weight: bold;text-decoration: none;\" type=\"text\" size=\"3\" name=\"counter\" value=\"1\"></td><td align=\"center\" valign=\"middle\" width=\"10\">/</td><td align=\"left\" valign=\"middle\" width=\"240\"><input style=\"border:0px; text-align:left; font-family: verdana, arial, helvetica, geneva, trebuchet ms, sans-serif;font-size: 12px;color: #666666;font-weight: bold;text-decoration: none;\" type=\"text\" size=\"3\" name=\"counter_all\" value=\"1\"></td><td align=\"right\" valign=\"middle\" width=\"330\"><img src=\"mxassets/1x1_trans.gif\" border=\"0\" width=\"330\" height=\"1\"></td><td align=\"right\" valign=\"middle\" width=\"20\"><a href=\"javascript:window.close();\"><img src=\"mxassets/btn_close.gif\" border=\"0\"></a></td></tr>\n' );
       win.document.writeln( "\n<tr><td valign=\"middle\" align=\"center\" colspan=\"9\"><img src=\"" + pictures[number] + "\" name=\"viewer\"></td></tr>\n" );
       win.document.writeln( "\n<tr><td valign=\"middle\" align=\"middle\" colspan=\"9\"><input type=\"text\" size=\"100\" name=\"kommentar\" value=\'" + picture_text[number].substr(0,picture_text[number].indexOf('|')) + "\'></td></tr>\n</table>" );
	   win.document.writeln( "\n</form></body>\n</html>" );
       win.document.close();  // close document
}
