
var ScrollLinks = {
	currentHash: false,
	start: function(){
		this.scroll = new fx.Scroll({duration: 300, transition: fx.sineOut, onComplete: function(){this.end();}.bind(this)});
		this.allinks = $c(document.getElementsByTagName('a'));
		this.allinks.each(function(lnk){
			if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) 
				|| ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
				lnk.onclick = function(){
					ScrollLinks.scroll.clearTimer();
					this.initialHref = this.href;
					this.initialHash = this.hash;
					this.href = "javascript:void(0)";
					setTimeout(function(){this.href = this.initialHref;}.bind(this), 200);
					ScrollLinks.go(this);
				}
			}
		});
	},

	go: function(link){
		this.currentHash = link.initialHash.slice(1);
		if (this.currentHash) {
			this.allinks.each(function(lnk){
				if (lnk.id == ScrollLinks.currentHash){
					if (window.opera) lnk =  [lnk].find('parentNode');
					ScrollLinks.scroll.scrollTo(lnk);
					return;
				}
			});
		}
	},

	end: function(){
		if (!/Konqueror|Safari|KHTML/.test(navigator.userAgent)) window.location.hash = "#"+this.currentHash;
		this.currentHash = false;
	}
}

/*
function stopError()
{
	return true;
}

window.onerror = stopError;
*/

function myNewUrl(url, toAdd)
{
	var tmp = url.split("#");
	
	var hash = "";
	if( tmp.length > 1 )
	{
		hash = "#" + tmp.pop();
	}
	
	url = tmp.join("#");
	
	var parts = url.split("?");
	
	if( parts.length > 1 )
	{
		var vars = parts.pop().split("&");
		vars[vars.length] = toAdd;
	}
	else
	{
		var vars = new Array(1);
		vars[0] = toAdd;
	}
	parts[parts.length] = vars.join("&");
	
	return parts.join("?") + hash;
}

function myPopup(url, force)
{
	url = myNewUrl(url, "tpl=popup");
	var w = 500;
	if( arguments[2] )
	{
		w = arguments[2];
	}
	var h = 400;
	if( arguments[3] )
	{
		h = arguments[3];
	}
	var l = (screen.availWidth/2)-(w/2);
	var t = (screen.availHeight/2)-(h/2)-24;
	if( window.opener && !force )
	{
		if ( window.innerWidth )
		{
			window.innerWidth = w; 
			window.innerHeight = h;
		}
		else
		{
			window.resizeTo(w+20, h+40);
		}
		window.moveTo(l, t);
		window.location.href = url;
	}
	else
	{
		var name = "_blank";
		window.open(url, name, "width=" + w + ", height=" + h + ", left=" + l + ", top=" + t + ", toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no");
	}
	return false;
}

function myClose(url)
{
	if( window.opener )
	{
		if(url!=undefined)
		{
			window.opener.location.href = url;
		}
		window.close();
	}
	else
	{
		if(url!=undefined)
		{
			return true;
		}
		else
		{
			window.history.back();
		}
	}
	return false;
}

function toogleDisplay(obj)
{
	if ( obj.style.display == 'none' )
	{
		obj.style.display = ''
	}
	else
	{
		obj.style.display = 'none'
	}
}