/*
// JoomlaWorks "Simple Image Rotator" Module for Joomla! 1.5.x - Version 1.2
// License: http://www.gnu.org/copyleft/gpl.html
// Copyright (c) 2006 - 2008 JoomlaWorks, a Komrade LLC company.
// More info at http://www.joomlaworks.gr
// Developers: Fotis Evangelou
// ***Last update: May 20th, 2008***
*/

var stop = true;
var repeated = false;

var delay = 2000;
var transition = 40;
var imageContainer = 'jw-sir';
var d=document, imgs = new Array(), zInterval = null, current=0, nIndex=0; pause=false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	imgs = d.getElementById(imageContainer).getElementsByTagName("img");
	for(i=1;i<imgs.length;i++){
		imgs[i].xOpacity = 0;
	}
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;

	if (stop == false){
		setTimeout(so_xfade, delay);
	}
}

function startFading(){
	if (document.getElementById('startingLink')){
		var link = document.getElementById('startingLink');
		link.removeAttribute('onClick');
	}
	setTimeout(so_xfade, 100);
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;

	if (nIndex == 0 && current-1 == imgs.length){
	}else if (imgs[current+1]){
		nIndex = current+1;
	}else if (nIndex+1 == imgs.length && current+1 == imgs.length){
		if (document.getElementById('startingLink')){
			var link = document.getElementById('startingLink');
			link.setAttribute('onClick','startFading();');
		}
		nIndex = 0;
		return;
	}

	nOpacity = imgs[nIndex].xOpacity;
	cOpacity-=.05;
	nOpacity+=.05;
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,delay);
	} else {
		setTimeout(so_xfade,transition);
	}
}

function 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 hideLoading() {document.getElementById(preLoader).style.display = 'none';}

// Load everything up
function init_ahr(){
    if (arguments.callee.done)
    	return;

    arguments.callee.done = true;
	so_init();
	hideLoading();
};
// DOM2
if ( typeof window.addEventListener != "undefined" )
	{ window.addEventListener( "load", init_ahr, false );
}
// IE
else if ( typeof window.attachEvent != "undefined" )
	{ window.attachEvent( "onload", init_ahr );
}
else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			init_ahr();
		};
	}
	else
		window.onload = init_ahr;
}
