/**************************************************************************************************/
/***
/***	TERNSTYLE (TM) JAVASCRIPT DOCUMENT (ternStyle tm version 2.0 with jQuery)
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2007 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	All Rights Reserved. Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*-----------------------
	ternStyle (tm) v2.0
-----------------------*/
jQuery.fn.extend({
	/*
		image : '',
		color : '#fff',
		opacity : 65,
		func : function,
		text : ''
	*/
	elapsor :
	function (a) {
		//var i = this.tern[0];
		//this.w = i == document.body ? this.getWindowSize() : this.getDimensions();
		//this.s = i == document.body ? this.getScroll() : this.itemScroll();
		this.w = [this.innerWidth(),this.innerHeight()];
		this.s = [this.scrollLeft(),this.scrollTop()];
		//
		a.opacity = a.opacity ? a.opacity : 65;
		//mask
		if(!this.mask) {
			this.mask = document.createElement('div');
			//ternStyle(this.mask).setStyle({ display : 'none',position : 'absolute',overflow : 'hidden','z-index' : 50,top : 0,left : 0 });
			jQuery(this.mask).css({
				'display'	: 'none',
				'position'	: 'fixed',
				'clear'		: 'both',
				'overflow'	: 'hidden',
				'z-index'	: 50,
				'top'		: 0,
				'left'		: 0,
				'width'		: '100%',
				'height'	: '100%'
			});
			//
			/*
			if(i.hasChildNodes()) {
				i.insertBefore(this.mask,i.childNodes[0]);
			}
			else {
				i.appendChild(this.mask);
			}
			*/
			this.prepend(this.mask);
			//
			//ternStyle(this.mask).addClass('ternMask');
			jQuery(this.mask).addClass('ternMask');
		}
		//elapsor
		if(a.image || a.text) {
			this.createElapsor(a);
		}
		else if(this.elap) {
			//ternStyle(this.elap).setStyle({ display : 'none' });
			jQuery(this.elap).css('display','none');
		}
		//
		//ternStyle(this.mask).setOpacity(a.opacity).setStyle({ 'background-color' : a.color,height : parseInt(this.w[0]+(this.s[3]-this.w[0])),width : parseInt(this.w[1]+(this.s[2]-this.w[1])),display : 'block' });
		jQuery(this.mask).css({
			'opacity'			: a.opacity,
			'background-color'	: a.color,
			'display'			: 'block'
		});
		if(a.func) { a.func(); }
		//
		return this;
	},
	createElapsor :
	function (a) {
		if(this.elap) {
			this.image.src = a.image;
			if(a.text) {
				this.elapsorText(a.text);
			}
		}
		else {
			this.elap = document.createElement('div');
			if(a.image) {
				this.image = document.createElement('img');
				this.image.src = a.image;
				this.elap.appendChild(this.image);
				this.elap.appendChild(document.createElement('br'));
			}
			//
			if(a.text) {
				this.text = document.createElement('span');
				this.text.appendChild(document.createTextNode(a.text));
				this.elap.appendChild(this.text);
			}
			//
			this.mask.appendChild(this.elap);
			/*
			ternStyle(this.elap).addClass('ternElapsor').setStyle({
				position : 'absolute',
				'width' : 300,
				'z-index' : 50,
				'text-align' : 'center',
				'font-size' : 11
			});
			*/
			jQuery(this.elap).addClass('ternElapsor').css({
				'position' : 'absolute',
				'width' : 300,
				'z-index' : 50,
				'text-align' : 'center',
				'font-size' : 11
			});
		}
		//ternStyle(this.elap).setStyle({ 'top' : (this.s[1]+((this.w[1])/2)),'left' : (this.s[0]+((this.w[0]-300)/2)),display : 'block' });
		jQuery(this.elap).css({
			'top' : (this.s[1]+((this.w[1])/2)),
			'left' : (this.s[0]+((this.w[0]-300)/2)),
			'display' : 'block'
		});
		//
		return this.elap;
	},
	elapsorText :
	function (t) {
		this.text.innerHTML = t;
	},
	hideElapsor :
	function () {
		this.mask = this.find('.ternMask').get(0);
		if(this.mask) {
			//ternStyle(this.mask).setStyle({ display : 'none',width : 1,height : 1 });
			jQuery(this.mask).css({
				'display'	: 'none',
				'width'		: 1,
				'height'	: 1
			})
		}
	}
});