/*
 * This code will correct a problem with ie in mootools' '$$' selector function 
 * that creates a bunch of temporary attributes that should not be printed. 
 */
if (window.ie) $$.unique = function(array){
	var elements = [];
	for (var i = 0, l = array.length; i < l; i++){
		if (array[i].$included) continue;
		var element = $(array[i]);
		if (element && !element.$included){
			element.$included = true;
			elements.push(element);
		}
	}
	for (var n = 0, d = elements.length; n < d; n++) elements[n].removeAttribute('$included');
	return new Elements(elements);
};





function centerHiddenElement(elmnt)
{
	elmnt.setStyle('display', 'block').setOpacity(0.0);
	centerElement(elmnt);
	elmnt.setOpacity(1.0);
}

function centerElement(elmnt) {
	centerElementVertically(elmnt);
	centerElementHorizontally(elmnt);
}

function centerElementHorizontally(elmnt) {
	elmnt.style.position = 'absolute';
	var left = parseInt(getWindowScrollWidth() + (getWindowWidth() / 2) - (elmnt.scrollWidth / 2));
	left = left > 0 ? left : 0;
	elmnt.setStyle('left', left + 'px');
}

function centerElementVertically(elmnt) {
	elmnt.style.position = 'absolute';
	var top = parseInt(getWindowScrollHeight() + (getWindowHeight() / 2) - (elmnt.scrollHeight / 2));
	top = top > 0 ? top : 0;
	elmnt.style.top = top + 'px';
}

function getWindowHeight() { return window.getHeight(); }
function getWindowScrollHeight() { return window.getScrollTop(); }
function getWindowScrollWidth() { return window.getScrollLeft(); }
function getWindowWidth() { return window.getWidth(); }
function getWindowFullHeight() { return window.getScrollHeight(); }
function getWindowFullWidth() { return window.getScrollWidth(); }

function scroll_to(el) {
    var offsetTop = 0;
    while(typeof(el) != "undefined" && el != null) {
        offsetTop += el.offsetTop;
        el = el.offsetParent;
    }
    window.scrollTo(0, offsetTop);
}


function redirect(url) {
    //  This version does NOT cause an entry in the browser's
    //  page view history.  Most browsers will always retrieve
    //  the document from the web-server whether it is already
    //  in the browsers page-cache or not.
 
    window.location.replace( url );
}


function addTooltips(obj)
{
	tips = new Tips(obj, {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
}


function linkEmail(email) {
	var replace = {at: '@', dot: '.'};
	email.substitute(replace);
}


