/**************************************************************************************************/
/***
/***	TERNSTYLE (TM) ELAPSOR JAVASCRIPT DOCUMENT (ternElapse (tm) version 2.0 for jQuery)
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2009 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	All Rights Reserved. Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*-----------------------
	ternElapse (tm) v2.0
-----------------------*/
jQuery.fn.extend({
	/*
		image : '',
		color : '#fff',
		opacity : 65,
		func : function,
		text : ''
		text_style : {
			color : '#fff'
			'font-size' : '16px'
		}
	*/
	elapsor :
	function (a) {
		this.w = [250,5];//[this.innerWidth(),this.innerHeight()];
		this.s =[210,4];// [this.scrollLeft(),this.scrollTop()];
		a.opacity = a.opacity ? '0.'+a.opacity.toString() : .55;
		a.color = a.color ? a.color : '#fff';
		a.image	= a.image ? a.image :'./lib/ternElapse/images/loader.gif';
		a.text = a.text ? a.text : 'Loading... ';
		a.text_style = a.text_style ? a.text_style : {
		'color' : '#f00',
		'font-size' : '12px',
		'font-weight': 'bold'
		}
		this.mask = this.find('.ternMask').get(0);
		if(!this.mask) {
			this.mask = document.createElement('div');
			jQuery(this.mask).css({
				'display'	: 'none',
				'position'	: 'absolute',
				'clear'		: 'both',
				'overflow'	: 'hidden',
				'text-align': 'center',				
				'z-index'	: 50,
				'top'		: 1,
				'left'		: 220,
				'width'		: 230, //this.innerWidth(), // +this.get(0).scrollWidth,
				'height'	: 26 //this.innerHeight() //+this.get(0).scrollHeight
			});
			if(jQuery.browser.msie && jQuery.browser.version == '6.0') {
				jQuery(this.mask).css({'position':'absolute'});
			}
			this.prepend(this.mask);
			jQuery(this.mask).addClass('ternMask');
		}
		if(a.image || a.text) {
			this.createElapsor(a);
		}
		else if(this.elap) {
			jQuery(this.elap).css('display','none');
		}
		jQuery(this.mask).css({
			'opacity'			: a.opacity,
			'background-color'	: a.color,
			'display'			: 'block'
		});
		if(a.func) { a.func(); }
	},
	createElapsor :
	function (a) {
		this.elap = this.find('.ternElapsor').get(0);
		if(this.elap) {
			var i = $(this.elap).find('img').get(0);
			if(i) {
				i.src = a.image;
			}
			if(a.text) {
				this.elapsorText(a.text);
			}
		}
		else {
			this.elap = document.createElement('div');
			
			if(a.text) {
				this.text = document.createElement('span');
				this.text.appendChild(document.createTextNode(a.text));
				this.elap.appendChild(this.text);
			}
			if(a.image) {
				this.image = document.createElement('img');
				this.image.src = a.image;
				this.elap.appendChild(this.image);
				// this.elap.appendChild(document.createElement('br'));
			}
			this.mask.appendChild(this.elap);
			jQuery(this.elap).addClass('ternElapsor').css({
				'position' : 'absolute',
				'width' : 230,
				'height': 26,
				'z-index' : 50,
				'text-align' : 'center'
			}).css(a.text_style);
		}
		jQuery(this.elap).css({
			'top' : 1,//(this.s[1]+((this.w[1])/2)),
			'left' : 1,//(this.s[0]+((this.w[0]-200)/2)),
			'display' : 'block'
		});
		return this.elap;
	},
	elapsorText :
	function (t) {
		$(this.elap).find('span').html = t;
	},
	hideElapsor :
	function () {
		this.mask = this.find('.ternMask').get();
		if(this.mask) {
			jQuery(this.mask).css({
				'display' : 'none'
			})
		}
	}
});