// JavaScript Document
// From http://www.brainerror.net/scripts_js_blendtrans.php

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++){
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	/*var object = document.getElementById(id).style; */
	var object = returnObject(id, 1);
	
	//cancelar efecto para IE
	if(!explorer4 && !explorer5){
		object.opacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
		object.MozOpacity = (opacity / 100);

}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


/***************************************************/
// dynamicImages  http://www.businessandmedia.net/
//
// arguments: id, period, image0, image1, image2,...imageN-1
//
// don't forget to preload the images previous to this script.
var speed=20;
function dynamicImages(){
	var args = dynamicImages.arguments;
	var images = new Array;
	var id = args[0];
	var period = args[1];
	var i;
	/*var millisec = 2000;
	var speed = Math.round(millisec / 100);*/
	
	//Create Image array (actual image goes last
	for(i=3;i<args.length;i++)
		images[i-3] = args[i];

	images[args.length-3] = args[2];
	
	//Fadeout Actual Image:
	//time: speed/10 sec
	fadeOut(id);

	//Change Image + Fade In
	//time: 1 sec (change image) + 1 sec start fade in + speed/10 sec
	setTimeout("changeImage(\'"+id+"\', \'"+images[0]+"\');", 2500);
	
	//Create new Image Array
	param='';
	for (i=0; i<images.length; i++){
		if(i==0)
			param = "\'"+images[i]+"\'";
		else
			param = param+", \'"+images[i]+"\'";
	}
	
	//Start Again, with next iteration
	//time: N/1000 sec
	setTimeout("dynamicImages(\'"+id+"\',\'"+period+"\', "+param+");", 10000);
}

function changeImage(id, image){
	x=returnObject(id,0);
	x.src=image;
	
	//Fade In
	setTimeout("fadeIn(\'"+id+"\');",1000);
}

function fadeIn(id){
	timer=0;
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
		timer++;
	}
}

function fadeOut(id){
	x=returnObject(id,0);

	opacity(id, 100, 0, speed*100);
}