/*
Image Rotator module for Elxis 2008.x/2009.x
Author: Ioannis Sannos (Is Open Source)
Author URL: http://www.isopensource.com
License: Creative Commons 3.0 Share Alike
Copyright (c) 2008-2010 Ioannis Sannos - http://www.isopensource.com
Module IOS Image Rotator and Elxis CMS are free software
*/

function iosrotator_setOpacity(obj) {
	if(obj.xOpacity>.99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

function iosrotator(delay, transition, idsfx) {
    this.delay = delay;
    this.transition = transition;
    this.imageContainer = 'ios-imgrot'+idsfx;
    this.preLoader = 'ios-imgrot-loading'+idsfx;
    this.idsfx = idsfx;
    this.imgs = new Array();
    this.zInterval = null;
    this.current = 0;
	this.pause = false;

	this.so_init = function() {
		if(!document.getElementById || !document.createElement) { return; }
		this.imgs = document.getElementById(this.imageContainer).getElementsByTagName("img");
		for(i=1;i<this.imgs.length;i++) { this.imgs[i].xOpacity = 0; }
		this.imgs[0].style.display = "block";
		this.imgs[0].xOpacity = .99;
		var self = this;
		setTimeout(function(){ self.so_xfade(); }, self.delay);
	}

	this.so_xfade = function() {
		cOpacity = this.imgs[this.current].xOpacity;
		nIndex = this.imgs[this.current+1]?this.current+1:0;
		nOpacity = this.imgs[nIndex].xOpacity;
		cOpacity-=.05; 
		nOpacity+=.05;
		this.imgs[nIndex].style.display = "block";
		this.imgs[this.current].xOpacity = cOpacity;
		this.imgs[nIndex].xOpacity = nOpacity;
		iosrotator_setOpacity(this.imgs[this.current]); 
		iosrotator_setOpacity(this.imgs[nIndex]);
		var self = this;
		if(cOpacity<=0) {
			this.imgs[this.current].style.display = "none";
			this.current = nIndex;
			setTimeout(function(){ self.so_xfade(); }, this.delay); 
		} else {
			setTimeout(function(){ self.so_xfade(); }, this.transition); 
		}
	}


	this.hideLoading = function () {
		document.getElementById(this.preLoader).style.display = 'none';
	}


	this.init_ahr = function() {
		if (arguments.callee.done) { return; }
    	arguments.callee.done = true;
		this.so_init();
		this.hideLoading();
	}
}

