function LeadSlider(arg){
	this.width = arg.width;
	this.height = arg.height;
	if(typeof(arg.target) != 'object')
		this.target = document.getElementById(arg.target);	
	else 
		this.target = arg.target;	
	this.stepDelay = arg.stepDelay;
	if (arg.stallDelay == null)
		this.stallDelay = this.stepDelay * 2;
	else
		this.stallDelay = arg.stallDelay;
	if (arg.data != null)
		this.data = arg.data;
	else
		this.data = null;
	this.fadeSpeed = (parseInt(arg.fadeSpeed) / 1000);	
	this.target.style.width = this.width + 'px';
	this.target.style.height = this.height + 'px';	
	this.target.style.overflow = 'hidden';	
	this.cards = new Array();
	this.currentCard = 0;
	this.paused = false;
	this.fader;
	this.ticker;
	this.selector = arg.selector;
	try{
		this.titleCont = document.getElementById(arg.titleCont);
	} catch (e){
		;
	}
	that = this;	
	
}
LeadSlider.prototype = {
	constructor : LeadSlider,		
	loadCards : function(){
		if (that.data == null){
			/* TEST DATA */
			var _c = new Array();		
			_c[0] = "<img src=\"images/test/1.jpg\" alt=\"\"/>";
			_c[1] = "<img src=\"images/test/2.jpg\" alt=\"\"/>";
			_c[2] = "<img src=\"images/test/3.jpg\" alt=\"\"/>";
			_c[3] = "<img src=\"images/test/1.jpg\" alt=\"\"/>";
			/* END TEST DATA*/ 
		} else _c = that.data;
		
		that.target.innerHTML = '';		
		for (i = 0; i < _c.length; i++){	
			that.addCard(_c[i][0]);		
		}
		that.setTitle(that.data[0][1]);
		that.selector(0);
		//that.addCard(_c[0]);
	},
	fade : function (d, m, s){		
		if(typeof(d) != 'object')
			d = document.getElementById(d);
		if(s == null)
			s = that.fadeSpeed;		
		if (m == "in"){
			that.fader = new YAHOO.util.Anim(d, { opacity: {to: 1} }, s );
		} else if(m == "out") {
			that.fader = new YAHOO.util.Anim(d, { opacity: {to: 0} }, s );
		}
		that.fader.animate();	
	},
	start : function(){		
		setTimeout("that.next();", that.stepDelay);
	},
	next : function(){		
		if (!that.paused){
			if (that.currentCard == (that.cards.length - 1)){
				YAHOO.util.Dom.setStyle(that.cards[0], 'opacity', 1);
				that.resetCards();
				that.currentCard = -1;
				that.next();
				that.selector(0);
			} else	{						
				that.fade(that.cards[that.currentCard], "out");			
				that.currentCard += 1;
				that.ticker = setTimeout("that.next();", that.stepDelay);
				that.selector(that.currentCard);
				
			}
			that.setTitle(that.data[that.currentCard][1]);			
		} else 
			that.ticker = setTimeout("that.next();", that.stepDelay);
		
	},
	resetCards : function(c){
		if (c == null) 
			c = 0;
		else 
			c = c + 1;		
		for (i = c; i < (that.cards.length - 1); i++){				
			YAHOO.util.Dom.setStyle(that.cards[i], 'opacity', 1); 
		}
	},
	addCard : function(d){
		var card = document.createElement("div");
		card.style.width = that.width + 'px';
		card.style.height = that.height + 'px';		
		card.style.position = "absolute";
		card.style.zIndex = 100 - that.cards.length;
		card.id = YAHOO.util.Dom.generateId();
		card.onmouseover = that.togglePaused;
		card.onmouseout = that.togglePaused;
		card.innerHTML = d;
		that.target.appendChild(card);
		that.cards[that.cards.length] = card.id;
	},
	togglePaused : function() {		
		if (that.paused)
			that.paused = false;
		else 
			that.paused = true;		
	},	
	jumpTo : function(c){		
		c = c - 1;
		that.paused = true;
		if (that.currentCard > c){			
			j = (c + 1);
			YAHOO.util.Dom.setStyle(that.cards[c], 'opacity', 1);
			for(i = j; i <= (that.cards.length - 2); i++){
				YAHOO.util.Dom.setStyle(that.cards[i], 'opacity', 0);				
			}			
		}
		if (that.currentCard < c){			
			YAHOO.util.Dom.setStyle(that.cards[c], 'opacity', 1);			
			for(i = that.currentCard; i < c; i++){				
				YAHOO.util.Dom.setStyle(that.cards[i], 'opacity', 0);				
			}			
		}
		that.currentCard = c;
		that.resetCards(c);
		clearTimeout(that.ticker);
		that.paused = false;
		that.ticker = setTimeout("that.next();", that.stallDelay);
		that.setTitle(that.data[c][1]);
		that.selector(c);
	},
	setTitle : function(t){
		that.titleCont.innerHTML = t;		
	}
}

/*
function doHover(id){
	o = document.getElementById(id);
	o.className = o.className.replace("_hover", "");
	o.className += "_hover";
}
function delHover(id){
	o = document.getElementById(id);
	o.className = o.className.replace("_hover", "");
}
*/
function doHover(id){
	dho = document.getElementById(id);
	dho.style.backgroundPosition = "120px 0px";
}
function delHover(id){	
	o = document.getElementById(id);
	o.style.backgroundPosition = "0px 0px";	
}

function show(id){
	
	//if (typeof(o) == "undefined")
		o = document.getElementById(id);	
	//if (o.style.display != 'block')
		o.style.display = 'block';
	
}
function hide(id){
	//if (typeof(o) == "undefined")
		o = document.getElementById(id);	
	//if (o.style.display != 'none')
		o.style.display = 'none';
	
}
function doChiliHover(){
	dho = document.getElementById("chililogo");
	dho.style.backgroundPosition = "60px 0px";
}
function delChiliHover(id){	
	o = document.getElementById("chililogo");
	o.style.backgroundPosition = "0px 0px";	
}