
// Shorthand
function getElm(id) { return document.getElementById(id); }

//      addEvent(object, eventType, function, useCapture);
function addEvent(obj, evType, fn, uc)
{
	if ((typeof obj == "undefined") || (obj == null)) throw "addEvent: null object not allowed";
	var rv = false;
	if (obj.attachEvent) { // IE
		rv = obj.attachEvent("on"+evType, fn);
	}
	else if (obj.addEventListener) { // DOM/Mozilla
		if (typeof uc == "undefined") uc = false;
		obj.addEventListener(evType, fn, uc);
		rv = true;
	}
	return rv;
};

//      removeEvent(object, eventType, function, useCapture);
function removeEvent(obj, evType, fn, uc) 
{
	if ((typeof obj == "undefined") || (obj == null)) throw "removeEvent: null object not allowed";
	var rv = false;
	if (obj.detachEvent) {
		rv = obj.detachEvent("on"+evType, fn);
	} else if (obj.removeEventListener) {
		if (typeof uc == "undefined") uc = false;
		obj.removeEventListener(evType, fn, uc);
		rv = true;
	}
	return rv;
};


function Arguments(queryString)
{
/**
	Usage:
	// get the part of the url behind the '?' (querystring)
	var query = document.location.search.substring(1);
	// create the Arguments object using the query
	var args = new Arguments(query);
*/
	if (typeof queryString == "undefined") queryString = document.location.search.substring(1);

	var args = queryString.split("&");
	for (var i=0; i<args.length; i++) {
		var arg = args[i].split("=");
		if (arg.length < 2) continue; //no delimiter found
		this[arg[0]] = unescape(arg[1]);
	}
	return this;
}//End: Arguments


function openWindow(url, name, width, height, options)
{
	if (!name ) name = "outsideSiteWindow";
	if (!width) width = 480;
	if (!height) height = 360;
	if (!options ) options = "scrollbars=yes,menubar=no,toolbar=no,location=no,status=no,resizable=yes";
	var win = window.open(url, name, "width=" + width + ",height=" + height + "," + options);
	if (!win.opener) win.opener = self;
	return win;
}

/**
	A popup window (satellite) that is managed by the main website window.
	The main window reconnects to the satellite everytime it is reloaded. 
	This allows the website window to remember the state of it's satellites 
	and to open/close them even if the current page didn't open them itself.

	The page loaded in the satellite should have an onunload handler like the example below
	to handle the case when it is closed manually by the user:
	window.onunload = function() {
		if (window.opener && window.controller)
			window.controller.onclose();
	};
 */
function SatelliteWindow(uri, width, height, name, options)
{
	this._uri = uri;
	this._width = width || 300;
	this._height = height || 300;
	this._name = name || "satellitewindow"+ SatelliteWindow.count;
	this._options = options || "scrollbars=no,menubar=no,toolbar=no,location=no,status=no,resizable=yes";
	this._key = "_satellite_"+ SatelliteWindow.count +"_open_";
	this._win = null;
	SatelliteWindow.count++;
}
SatelliteWindow.count = 0;
SatelliteWindow.prototype._open = function()
{
	var win = window.open("", this._name, "width="+ this._width +",height=" + this._height +","+ this._options);
	if (!win.opener) win.opener = self;
	return win;
};
SatelliteWindow.prototype.getReference = function() {
	if (this._win && !this._win.closed) return this._win;
	var win = this._open();
	if (win.document.location.pathname != this._uri) {
		// player wasn't open, load our page
		win.document.location.replace(this._uri)
	}
	return win;
};
SatelliteWindow.prototype.open = function() {
	this._win = this.getReference();
	this._win.focus();
	this._win.controller = this;
	window.name += this._key;
	return this._win;
};
SatelliteWindow.prototype.close = function() {
	this._win = this.getReference();
	if (!this._win.closed) {
		this._win.close();
	}
	this.onclose();
};
SatelliteWindow.prototype.onclose = function()
{
	window.name = window.name.replace(this._key, "");
	this._win = null;
};
SatelliteWindow.prototype.isOpen = function()
{
	return (window.name.indexOf(this._key) != -1)
};
SatelliteWindow.prototype.toggle = function()
{
	if (this.isOpen()) {
		this.close();
	}
	else {
		this.open();
	}
};

var player = new SatelliteWindow("/player.html");


/*	
// 20050223/sa: replaced with htc behaviours

// Fix IE's dumbness
function ieFixes()
{
	var ua = navigator.userAgent.toLowerCase();
	var isIE = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 
	var IEVersion = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );

	// Transparent PNG's for IE<6
	//alert("isIE: "+ isIE +"\n"+ "IEVersion: "+ IEVersion);
	if (isIE && IEVersion < 6) {
		// make png's transparent in old IE versions
		logo.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/logo.png', sizingMethod='scale')";
		logo.style.cursor = "pointer";
		logo.style.margin = "10px";
		logo.onclick = function() { document.location.href = '/'; };
		logo.title = "Phonosapiens Startseite: HOME";
		logo.innerHTML = "";
	}
};
function initialize()
{
	ieFixes();
};
*/
//addEvent(window, 'load', initialize);



