var TP = new Object({
	
	/*
	 * Global TP Object works without Prototype
	 * and provides utility methods such as page size 
	 * things which cause cross browser issues
	 * 
	 * Author: Gareth Hughes
	 */
	
	/*
	 * Finds the location of an element, mainly for IE
	 */
	findLocation: function(obj){
		var posX = obj.offsetLeft;
		var posY = obj.offsetTop;
		
		while (obj.offsetParent) {
			if (obj == document.getElementsByTagName('body')[0]) {
				break;
			}
			else {
				posX = posX + obj.offsetParent.offsetLeft;
				posY = posY + obj.offsetParent.offsetTop;
				obj = obj.offsetParent;
			}
		}
		
		return {
			x: posX,
			y: posY
		}
	}, 
	
	/*
	 * Gets the size of the page including viewable size and actual size
	 */
	getSize: function(){
		var w = 0;
		var h = 0;
		
		var pw = 0;
		var ph = 0;
		
		if (document.documentElement.clientWidth == 0 ||
		document.body.clientHeight < document.documentElement.clientHeight) {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		else {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		
		if (window.innerHeight && window.scrollMaxY) {
			pw = document.body.scrollWidth;
			ph = window.innerHeight + window.scrollMaxY;
		}
		else {
			if (document.body.scrollHeight > document.body.offsetHeight) {
				pw = document.body.scrollWidth;
				ph = document.body.scrollHeight;
			}
			else {
				pw = document.body.offsetWidth;
				ph = document.body.offsetHeight;
			}
		}
		
		if (ph < h) 
			ph = h;
		
		if (pw < w) 
			pw = w;
		
		return {
			width: w,
			height: h,
			pwidth: pw,
			pheight: ph
		}
	},
	
	/*
	 * Gets the current scroll position of the page
	 */
	getScrollPosition: function(){			
		if(window.pageYOffset)
			return window.pageYOffset;
		
		if (document.documentElement) 
			return document.documentElement.scrollTop;
		else 
			return document.body.scrollTop;								
		
		return 0;
	},

	fadeOut: function(obj, callback, speed, _opacity){
		if(_opacity == null) 
			_opacity = 100;
			
		if(speed == null)
			speed = 40;
		
		if(_opacity > 0)
			_opacity = _opacity - 25;
			
		TP.setOpacity(obj, _opacity);
		
		if (_opacity > 0) {
			setTimeout(function(){TP.fadeOut(obj, callback, speed, _opacity)}, speed);
		} else {
			if(callback != null)
				setTimeout(callback, speed);
		}
	},
	
	fadeIn: function(obj, callback, speed, _opacity){
		if(_opacity == null)
			_opacity = 0;
			
		if(speed == null)
			speed = 40;
		
		if(_opacity < 100)
			_opacity = _opacity + 25;
	
		TP.setOpacity(obj, _opacity);
		
		if (_opacity < 100) {
			setTimeout(function(){TP.fadeIn(obj, callback, speed, _opacity)}, speed);
		} else {	
		
			TP.removeOpacity(obj);
			if(callback != null)
				setTimeout(callback, speed);
		}
	},
	
	setOpacity: function(obj, opacity){
		var _opac = new String(opacity/100);
		obj.style.opacity = _opac;
		obj.style.filter = new String('alpha(opacity:' + opacity + ')');
		obj.select('ol li.clearfix, ul').each(function(element){
			element.style.zoom = '1';
			element.style.filter = new String('alpha(opacity:' + opacity + ')');
		});		
		obj.style.KHTMLOpacity = _opac;
		obj.style.MozOpacity = _opac;	
	}, 
	
	removeOpacity: function(obj){
		obj.style.opacity = '';
		obj.style.filter = '';
	
		obj.select('ol li.clearfix, ul').each(function(element){
			element.style.filter = '';
		});			
		obj.style.KHTMLOpacity = '';
		obj.style.MozOpacity = '';	
	},
	
	logError: function(e) {		
		alert(print_r(e));
	}
	
});
	
function print_r(x, max, sep, l) {  
	l = l || 0;  
	max = max || 10;  
	sep = sep || ' ';  
 
    if (l > max) {  
        return "[WARNING: Too much recursion]\n";  
    }  
 
    var  
        i,  
        r = '',  
        t = typeof x,  
        tab = '';  
 
    if (x === null) {  
        r += "(null)\n";  
    } else if (t == 'object') {  
    	l++;  
 
        for (i = 0; i < l; i++) {  
            tab += sep;  
        }  
 
        if (x && x.length) {  
            t = 'array';  
        }  

        r += '(' + t + ") :\n";  
 
        for (i in x) {  
            try {  
            	r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));  
            } catch(e) {  
            	return "[ERROR: " + e + "]\n";  
            }  
        }  
 
    } else {  
 
        if (t == 'string') {  
        	if (x == '') {  
        		x = '(empty)';  
            }  
        }  
 
        r += '(' + t + ') ' + x + "\n";  
	 
    }  
	 
	    return r;  
	 
};  
