
// $Id: scripts.js 395 2007-03-31 16:52:00Z cb $
// $HeadURL: file://localhost/usr/local/svnroot/kibuhaus/trunk/html/inc/scripts.js $
// $Author: cb $

var displaySubnav = false;
var hideSubnavTimeout = null;

function subnav(flag) {
	if (flag) {
		document.getElementById('progrsub').style.display = 'block';
		displaySubnav = true;
		document.getElementById('progr').className = 'active';
	} else {
		displaySubnav = false;
		hideSubnavTimeout = window.setTimeout('hideSubnav()', 1500)
	}
}

function hideSubnav() {
	if (displaySubnav) {
		return;
	}
	document.getElementById('progrsub').style.display = 'none';	
	document.getElementById('progr').className = null;
}

var bhvrRules = {
	'#progr': function(element) {
		element.onmouseover = function() {
			subnav(true);
		},
		element.onmouseout = function() {
			subnav(false);
		}
	},
	'#progrsub a': function(element) {
		element.onmouseover = function() {
			displaySubnav = true;
		},
		element.onmouseout = function() {
			subnav(false);
		}
	}
};


/**
 * Displays a centered popup window
 *
 * @param {String} path URL or path to display, or <a> element
 * @param {Number} width Popup window's width
 * @param {Number} height Popup window's height
 * @param {Boolean} fixed If set to true, the window will neither have a
                          statusbar or scrollbars nor will it be resizable,
                          otherwise both will be available
 * @return Returns the window object that was created
 * @type Object
 * @author CB
 * @version 2007-03-19
 */
function popup(path, width, height, fixed) {

	if (!height || !width) {
		// Width and/or height missing, set window width to
		// default value and set fixed to false
		width = 350;
		height = 250;
		fixed = false;
	}

	if (screen.availWidth) {
		position = 'left=' + (Math.floor(screen.availWidth / 2 - width / 2)) +
		           ',top=' + (Math.floor(screen.availHeight / 2 - height / 2));
	}
	else if (window.screenX) {
		position = 'screenX=' + (window.screenX + 50) + ',screenY=' + (window.screenY + 50);
	}
	else {
		position = 'left=120,top=120';
	}

	if (fixed) {
		attrs = 'status=no,resizable=no,scrollbars=no';
	}
	else {
		attrs = 'status=yes,resizable=yes,scrollbars=yes';
	}

	pp = window.open(path, 'Popup', 'width=' + width + ',height=' + height +
	                 ',' + position + attrs);

	pp.focus();
	
	return pp;

} // function popup(path, width, height, fixed)

Behaviour.register(bhvrRules);
