var fadePerStep				= 1; // How many percent to fade per step?
var fadingTime				= 500; // Miliseconds (seconds * 1000)
var stayTime				= 4000; // Miliseconds (seconds * 1000)
var imageNo					= 0;
var fading					= null;
var imgNo					= 0;
var newPictureStatus		= 1;

function show(w) {
	document.getElementById(w).style.display = (document.getElementById(w).style.display == 'none') ? 'block' : 'none';
}

function positionBtmBG() {
	if(document.all)
		document.getElementById('bottomBG').style.top			= (document.getElementById('page').offsetHeight-35) + 'px';
	else
		document.getElementById('bottomBG').style.top			= (document.getElementById('page').offsetHeight-34) + 'px';
	document.getElementById('leftBG').style.height			= document.getElementById('page').offsetHeight + 'px';
	document.getElementById('leftOrangeBG').style.height	= document.getElementById('page').offsetHeight + 'px';
}

function fadeIn() {
	var w						= document.getElementById('rImg');
	var currentOpacity			= Math.round(w.style.opacity*100);
	var newOpacity				= Math.round(currentOpacity+fadePerStep);
	clearInterval(fading);
	if(currentOpacity >= 100) {
		if(imagesArray.length > 1)
			fading			= setTimeout("fadeOut();", stayTime);
		return;
	}
	if(currentOpacity < 0)
		currentOpacity				= 0;
	w.style.opacity				= ( newOpacity / 100 );
	w.style.MozOpacity			= ( newOpacity / 100 );
	w.style.KhtmlOpacity		= ( newOpacity / 100 );
	w.style.filter				= "alpha(opacity=" + newOpacity + ")"; 
	fading			= setTimeout("fadeIn();", Math.round(fadingTime / 100 * fadePerStep));
}

function fadeOut() {
	var w						= document.getElementById('rImg');
	var currentOpacity			= Math.round(w.style.opacity*100);
	var newOpacity				= Math.round(currentOpacity-fadePerStep);
	clearInterval(fading);
	if(currentOpacity > 100)
		currentOpacity				= 100;
	if(currentOpacity <= 0) {
		replaceImage();
		return;
	}
	w.style.opacity				= ( newOpacity / 100 );
	w.style.MozOpacity			= ( newOpacity / 100 );
	w.style.KhtmlOpacity		= ( newOpacity / 100 );
	w.style.filter				= "alpha(opacity=" + newOpacity + ")"; 
	fading			= setTimeout("fadeOut();", Math.round(fadingTime / 100 * fadePerStep));
}

function replaceImage() {
	var w						= document.getElementById('rImg');
	var n						= document.getElementById('rImgNew');
	if(w != undefined && w != null) {
		if(newPictureStatus == 1) {
			if(imageNo >= imagesArray.length)
				imageNo						= 0;
			w.src						= imagesArray[imageNo];
			imageNo++;
			if(imageNo >= imagesArray.length)
				imageNo						= 0;
			n.src						= imagesArray[imageNo];
			newPictureStatus			= 0;
			w.onload					= fadeIn();
		} else
			setTimeout("replaceImage();", 300);
		return true;
	}
}

function newPicLoaded() {
	newPictureStatus			= 1;
	return true;
}
