
/*
##############################################################################################
#   $Source: /home/dev/CVSHOME/blackjackscience/html/bbc/BBC\040-\040Science\040&\040Nature\040-\040Horizon_files/jst_win.js,v $
#   $Author: ruslan $
#   $Revision: 1.1.1.1 $
#   $Date: 2004/11/17 11:40:11 $
##############################################################################################
*/

bbcjs.trace('<b><font color="green">jst_win.js</font> was included.</b>',2);

bbcjs.win =
{
	version		: 0.1,
	numWindows	: 0
}

/* Open window functionality */

//Window constructor. Is basically META info for what will be a window eventually...
bbcjs.win.Window = function (url,width,height)
{
	this.url = url;

	this.features = {
		width : width,
		height : height,
		location : 'no',
		scrollbars : 'yes',
		fullscreen : 'no',
		status : 'yes',
		menubar : 'no',
		toolbar : 'no',
		directories : 'no',
		resizable : 'yes',
		top : 10+(bbcjs.win.numWindows*20),
		left: 10+(bbcjs.win.numWindows*20)
	};

	bbcjs.win.numWindows++;
	this.name = 'popwin_'+(bbcjs.win.numWindows);
	this.replace = false;
	this.open = bbcjs.win.open; //Set local method to be equal to bbcjs function
	this.openWindow = false; //hack - this will eventually hold a reference...
}

//Open window function, takes in either parameters, or called via Window object...
bbcjs.win.open = function(url,width,height)
{
	var win, featstr, t;

	bbcjs.trace("Window open function called...",3);
	//alert(typeof(this));

	//If this is an instance of a bbcjs.win.Window, use "this"...
	if (typeof(this.url)!="undefined") t = this;
	else t = new bbcjs.win.Window(url,width,height);

	//temporarily allows changing of popup url (doesn't change object);
	if (typeof(url)=="undefined") {url = t.url; bbcjs.trace("set url to: "+url,4);}

	//Our features string (eg toolbar=yes etc)...
	featstr = "";

	//Build up args from all "feature" object elements
	for (var i in t.features)
	{
		featstr += i+"="+t.features[i]+",";
	}
	featstr = featstr.substring(0,featstr.length-1);

	//Trace statements...
	bbcjs.trace("Feature String is: <br /><b>"+featstr+"</b>",4);
	bbcjs.trace("Opening new window for:<br />&nbsp;&nbsp;&nbsp;"+t.url,3);
	bbcjs.trace("&nbsp;&nbsp;&nbsp;Window name is: <b>"+t.name+"</b>",4);
	bbcjs.trace("Full window.open command:<br />window.open('"+t.url+"', '"+t.name+"', '"+featstr+"', "+t.replace+")",5);

	//Open the window, and bring to front.
	win = window.open(url, t.name, featstr, t.replace);
	win.focus();

	//Set a reference to be the window we just opened. Useful for reusing windows...
	t.openWindow = win;

	return win;
}