// Title: Tigra Fader
// URL: http://www.softcomplex.com/products/tigra_fader/
// Version: 1.0 (compressed)
// Date: 07/23/2007
// Notes: This script is free. Visit official site for further details.

function tFader(a_items,a_tpl)
{
	if (!a_items)						 return alert("items structure is missing");
	if (typeof(a_items)!='object')		 return alert("format of the items structure is incorrect");
	if (a_items[a_items.length-1]==null) return alert("last element of the items structure is undefined");
	
	if (!a_tpl) a_tpl = [];
	for ( var i=0; i < A.length; i+=2 ) if(a_tpl[A[i]]==null) a_tpl[A[i]] = A[i+1];
	this.a_tpl = a_tpl;
	this.a_items = a_tpl.random ? P(a_items) : a_items;
	this.n_currentSlide = 0;
	this.f_goto = O;
	
	this.f_run = function()
	{
		this.b_running=1;
		this.f_goto();
	};
	
	this.f_stop = function()
	{
		this.b_running = 0;
		clearTimeout(this.I);
	};
	
	this.f_fadeIn = M;
	this.f_fadeOut = N;
	this.f_slideOp = R;
	if (!window.A_SLIDES) window.A_SLIDES = [];
	this.n_id = window.A_SLIDES.length;
	window.A_SLIDES[this.n_id] = this;
	
	var K = ' ' + (a_tpl['css'] ? ' class="'+a_tpl['css']+'"' : '')
				+ (a_tpl['width'] ? ' width="'+a_tpl['width']+'"' : '')
				+ (a_tpl['height'] ? ' height="'+a_tpl['height']+'"' : '')
				+ (a_tpl['alt'] ? ' title="'+a_tpl['alt']+'" alt='+a_tpl['alt']+'"' : '');
	
	this.a_imgRefs=[];
	document.write('<img src="',this.a_items[0],'"',K,' name="tslide',this.n_id,'_0" />');
	this.a_imgRefs[0]=document.images['tslide'+this.n_id+'_0'];
	this.n_currentSlide=0;
	if (!this.a_imgRefs[0] || !this.a_imgRefs[0].style || this.a_imgRefs[0].style.marginLeft==null) return;
	for (var i=1; i < this.a_items.length; i++) {
		document.write('<img src="', this.a_items[i], '"', K, ' name="tslide', this.n_id, '_', i,
			'" style="position:relative; z-index:-1; filter:alpha(opacity=100); " />');
		this.a_imgRefs[i]=document.images['tslide'+this.n_id+'_'+i];
		this.a_imgRefs[i].style.marginLeft='-'+this.a_tpl.width+'px';
		this.f_slideOp(i,0);
		this.a_imgRefs[i].style.zIndex=i;
	}
	
	this.H = Math.round(this.a_tpl['transtime'] * 1e3 / this.a_tpl['steps']);
	this.D = Math.round(100/this.a_tpl['steps']);
	this.f_run();
}

function O(G,C)
{
	if (this.I) {
		clearTimeout(this.I);
		this.I = null;
		if(this.n_nextSlide) {
			this.f_slideOp(this.n_nextSlide,0);
			this.n_nextSlide = null;
		}
	}
	
	this.n_nextSlide = (G==null ? this.n_currentSlide+1 : G) % this.a_items.length;
	if (this.n_nextSlide == this.n_currentSlide) return;
	this.I = setTimeout('A_SLIDES['+this.n_id+'].f_fade'
			+ (this.n_nextSlide>this.n_currentSlide?'In':'Out')
			+ '()',(C ? 0 : this.a_tpl['slidetime']*1e3));
}

function M(F)
{
	if(F==null) F=0;
	F += this.D;
	if(F > 99) {
		this.f_slideOp(this.n_nextSlide,99);
		this.f_slideOp(this.n_currentSlide,0);
		this.n_currentSlide=this.n_nextSlide;
		this.n_nextSlide=null;
		return this.f_run();
		}
	this.f_slideOp(this.n_nextSlide,F);
	this.J = setTimeout('A_SLIDES['+this.n_id+'].f_fadeIn('+F+')',this.H);
}

function N(F)
{
	if (F == null) {
		F = 99;
		this.f_slideOp(this.n_nextSlide,99); 
	}
	F -= this.D;
	if (F < 0) {
		this.f_slideOp(this.n_currentSlide,0);
		this.n_currentSlide = this.n_nextSlide;
		this.n_nextSlide = null;
		return this.f_run();
	}
	
	this.f_slideOp(this.n_currentSlide,F);
	this.J = setTimeout('A_SLIDES['+this.n_id+'].f_fadeOut('+F+')',this.H);
}

function R(G,F)
{
	if (!G) return;
	var e_slide = this.a_imgRefs[G];
	Q(e_slide,F);
}

function P(B)
{
	var n_index, a_items=[];
	while (B.length) {
		n_index = Math.ceil(Math.random()*B.length)-1;
		a_items[a_items.length] = B[n_index];
		B[n_index] = B[B.length-1];
		B.length = B.length-1;
	}
	
	return a_items;
}

var L = navigator.userAgent.toLowerCase();
if (L.indexOf('opera') != -1 || L.indexOf('safari') != -1)
	window.Q = function(e_element,F) { e_element.style.opacity = F/100; };
else if (L.indexOf('gecko') != -1)
	window.Q = function(e_element,F) { e_element.style.MozOpacity = F/100; };
else if(L.indexOf('msie') != -1)
	window.Q = function(e_element,F) {try { e_element.filters.alpha.opacity=F } catch(e) {}; };
else window.Q = null; 
	
var A = ['steps',40,'css','','transtime',0.5,'slidetime',2];