/** 
 * Popup
 ****************************************************************************
 * Popup is opened with chosen width + 20px and chosen height + 25px. If
 * scrolling is possible change this to width + 40px and height + 45px. If
 * popup is opened without width and/or height default size is 150px.
 *
 * The popup is positioned in the exact middle of the screen.
 ***************************************************************************/
var pop = null;

function popdown() {
	if (pop && !pop.closed) pop.close();
}

function popup(obj, w, h, sb)
{
	var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
	if (!url) return true;
	
	w = (w) ? w += 20 : 150;
  h = (h) ? h += 25 : 150;
	
	px = (screen.width - w) / 2;
	py = (screen.height - h) / 2;
	
	if (!sb) sb = 'no';
	
  var args = 'status=no, scrollbars=' + sb + ', scrolling=0, resizable=yes, width=' + w + ', height=' + h + ', top=' + py + ', left=' + px + ', locationbar=no, statusbar=no';
	
  popdown();
	
	pop = window.open(url, '', args);
	pop.focus();
  return (pop) ? false : true;
}

window.onunload = popdown;
window.onfocus = popdown;

/** 
 * Find positions
 ****************************************************************************
 * Find x and y position of an element.
 ***************************************************************************/
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	
	return curtop;
}

/** 
 * Scroll to top/bottom
 ****************************************************************************
 * tbd...
 ***************************************************************************/
var scroll = {
	top: function(event) { new Effect.ScrollTo('body'); },
	bottom: function(event) { new Effect.ScrollTo('footer'); }
}