/*--------------------------------------------------|
| ImageSlider 1.00 beta | InvariantBrowser package  |
|---------------------------------------------------|
| Author        Alexey Rymonin (x-phoen1x@mail.ru)  |
| Copyright (c) 2005-2007 SastaSoft                 |
|                                                   |
| This script process image slides  with fade.      |
|                                                   |
| Updated: 25.05.2007                               |
|--------------------------------------------------*/

function FadeItem(item) {
	var item = item;
	var step = 0.05;
	var time = 500;
	var direction = 1;
	var action = null;
	
	this.fade = function(actionFunc) {
		action = actionFunc;
		
		if(typeof(item.style.opacity) == "undefined" || item.style.opacity == "")
			item.style.opacity = 1;
		if(item.style.opacity > 0.5) direction = -1;
		else direction = 1;
		
		iteration();
	}
	
	iteration = function() {
		var curr = parseFloat(item.style.opacity);
		curr += direction*step;
		item.style.opacity = curr;
		item.style.filter = "alpha(opacity=" + curr*100 + ")";
		if(curr < 1 && curr > 0) 
			setTimeout("iteration()",time*step);
		else if(typeof(action) && action != null)
			action();
	}
}

function ImageSlider(item,items) {
	var item = item;
	var items = items;
	
	var isMSIE = /*@cc_on!@*/false;
	var delay = 2000;

	var i = 0;
	var ready = false;
	
	this.process = function(delayTime) {
		if(typeof(delayTime) != "undefined")
			delay = delayTime;
		preload();
	}
	
	preload = function() {
		if(++i >= items.length)
			i = 0;
		ready = false;
		var img = new Image();
		img.onload = function() {ready = true;}
		img.src = items[i];
		setTimeout("hide()",delay);
	}
	
	hide = function() {
		if(ready) new FadeItem(item).fade(show);
		else setTimeout("hide()",delay);
	}
	show = function() {
		if (isMSIE) {
			item.onload = function() {
				new FadeItem(item).fade(preload);
			}
			item.src = items[i];
		}
		else {
			item.src = items[i];
			new FadeItem(item).fade(preload);
		}
	}

}
