/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/


//window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false, timerduration = 5000,myOpacity = 1.0;

var nofi_g4_partCount = 5;
var nofi_g4_imgCount = 8;
var nofi_g4_index = nofi_g4_imgCount;
var	nofi_g4_mozTransparenz1 = 1.0;
var	nofi_g4_mozTransparenz2 = 0.0;
var	nofi_g4_speed = 0.3;
var	nofi_g4_motion = 0.1;
var	nofi_g4_duration = 6000;
var	nofi_g4_autoplay = true;

function nofi_g4_test() {
	alert(nofi_g4_duration);
}
function nofi_g4_init(partCount,imgCount,s,motion,d,autoplay) {
	nofi_g4_partCount = partCount;
	nofi_g4_imgCount = imgCount;
	nofi_g4_index = imgCount;
	nofi_g4_index_before = 0;
	nofi_g4_speed = s;
	nofi_g4_motion = motion;
	nofi_g4_duration = d;
	nofi_g4_autoplay = autoplay;
	if(nofi_g4_autoplay){
		setTimeout(nofi_g4,1);
	}
}

function nofi_g4() {
	var ind = 1;
	if(nofi_g4_index != 1){
		ind= nofi_g4_index - 1;
	}else{
		ind = nofi_g4_imgCount;
	}
	
	var speed = nofi_g4_speed;
	for(x=nofi_g4_partCount;x>0;x--){
//	for(x=1;x<=nofi_g4_partCount;x++){
		speed = speed + nofi_g4_motion;
		var objAktuell= document.getElementById("i" + ind + "_" + x);
		new Effect.Opacity(objAktuell,{duration: speed, from: nofi_g4_mozTransparenz2, to: nofi_g4_mozTransparenz1, queue: { position: 'end', scope: "testQueueAktuell"+ind } });
		var objReset= document.getElementById("i" + nofi_g4_index + "_" + x);
		new Effect.Opacity(objReset,{duration: speed, from: nofi_g4_mozTransparenz1, to: nofi_g4_mozTransparenz2, queue: { position: 'end', scope: "testQueueReset"+nofi_g4_index } });
	}

	if(nofi_g4_index==1){
		nofi_g4_index = nofi_g4_imgCount;
	}else{
		nofi_g4_index--;
	}
	setTimeout(nofi_g4,nofi_g4_duration);
	
}

function nofi_g4_reset() {
	for(i=nofi_g4_imgCount;i>1;i--){
		for(x=nofi_g4_partCount;x>0;x--){
			var objReset= document.getElementById("i" + i + "_" + x);
			if(i!=nofi_g4_index && i!=nofi_g4_index_before){
				new Effect.Opacity(objReset,{duration: 0.0, from: nofi_g4_mozTransparenz1, to: nofi_g4_mozTransparenz2, queue: { position: 'end', scope: "queueAllReset"+i+x } });
			}
		}
	}
}
function nofi_g4_manuell(ind) {

	if(nofi_g4_index == ind || nofi_g4_index_before == ind){
		return;
	}

	var queue1 = Effect.Queues.get("testQueueReset" + nofi_g4_index);
	queue1.each(function(effect) { effect.cancel(); });
	var queue2 = Effect.Queues.get("testQueueReset" + nofi_g4_index_before);
	queue2.each(function(effect) { effect.cancel(); });
	var queue3 = Effect.Queues.get("testQueueReset" + ind);
	queue3.each(function(effect) { effect.cancel(); });

	nofi_g4_index_before = ind;
	nofi_g4_reset();

	
	var speed = nofi_g4_speed;
	for(x=nofi_g4_partCount;x>0;x--){

		speed = speed + nofi_g4_motion;
		var objAktuell= document.getElementById("i" + ind + "_" + x);
		new Effect.Opacity(objAktuell,{duration: speed, from: nofi_g4_mozTransparenz2, to: nofi_g4_mozTransparenz1, queue: { position: 'end', scope: "testQueueReset"+ind } });
		var objReset= document.getElementById("i" + nofi_g4_index + "_" + x);
		if(nofi_g4_index != 1){
			new Effect.Opacity(objReset,{duration: speed, from: nofi_g4_mozTransparenz1, to: nofi_g4_mozTransparenz2, queue: { position: 'end', scope: "testQueueReset"+nofi_g4_index } });
		}
	}
	nofi_g4_index = ind;
}


function so_init() {
	if(!d.getElementById || !d.createElement)return;	
	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	css = d.createElement("link");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	imgs = d.getElementById("imageContainerSlide").getElementsByTagName("div");
	for(i=1;i<imgs.length;i++){
        new Effect.Opacity(imgs[i],{duration: 1, from: 1.0, to: 0.0, queue: { position: 'end', scope: "nofiEventQueue" + i } });
	} 
	setTimeout(so_xfade,timerduration);
}

function so_init2(dur,opa) {
	if(!d.getElementById || !d.createElement)return;
	timerduration = dur;
	if(opa){
		myOpacity = opa;
	}
	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	css = d.createElement("link");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	imgs = d.getElementById("imageContainerSlide").getElementsByTagName("div");
	for(i=1;i<imgs.length;i++){
        new Effect.Opacity(imgs[i],{duration: 1, from: 1.0, to: 0.0, queue: { position: 'end', scope: "nofiEventQueue" + i } });
	} 
	setTimeout(so_xfade,1);
}

function so_xfade() {
	nIndex = imgs[current+1]?current+1:0;
    new Effect.Opacity(imgs[current],{duration: 1, from: myOpacity, to: 0.0, queue: { position: 'end', scope: "nofiEventQueueCurrent" } });
    new Effect.Opacity(imgs[nIndex],{duration: 1, from: 0.0, to: myOpacity, queue: { position: 'end', scope: "nofiEventQueueIndex" + i } });
	current = nIndex;
	setTimeout(so_xfade,timerduration);
}
