/************************************************************************************************************



************************************************************************************************************/	
var imgFadeInterval = 0;	// Amount of time between each image(1000 = 1 second)  5000
var imgFadeSpeed = 20;	// Speed of fading	(Lower value = faster)
var foffset = 0;

var imgIndex = new Array();	// Index of current image shown
var imgIndexNext = new Array();	// Index of next image shown
var imgDivs = new Array();	// Array of image divs(Created dynamically)
var slideshow2_currentOpacity = new Array();	// Initial opacity
var imgCount = new Array();	// Number of images in gallery

var isOP = navigator.userAgent.indexOf('Opera')>=0?true:false;
var isIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;

function createParentDivs(imageIndex,divId)
{
	if(imageIndex==imgCount[divId]){	
		showGallery(divId);
	}else{
		var imgObj = document.getElementById(divId + '_' + imageIndex);	
		if(isOP)imgObj.style.position = 'static';
		if(!imgDivs[divId])imgDivs[divId] = new Array();
		imgDivs[divId][imgDivs[divId].length] =  imgObj;

		imgObj.style.visibility = 'hidden';	
		imageIndex++;
		createParentDivs(imageIndex,divId);	
	}		
}

function showGallery(divId)
{
	if(imgIndex[divId]==-1)imgIndex[divId]=0; else imgIndex[divId]++;	// Index of next image to show
	if(imgIndex[divId]==imgDivs[divId].length)imgIndex[divId]=0;
	imgIndexNext[divId] = imgIndex[divId]+1;	// Index of the next next image
	if(imgIndexNext[divId]==imgDivs[divId].length)imgIndexNext[divId] = 0;

	
	slideshow2_currentOpacity[divId]=100;	// Reset current opacity

	// Displaying image divs
	imgDivs[divId][imgIndex[divId]].style.visibility = 'visible';
	
	if(isOP) {
	   imgDivs[divId][imgIndex[divId]].style.display = 'inline';
	} //else {
	//	imgDivs[divId][imgIndexNext[divId]].style.visibility = 'visible';
	//}
	
	if(isIE){
	   imgDivs[divId][imgIndex[divId]].style.filter = 'alpha(opacity=100)';
		imgDivs[divId][imgIndexNext[divId]].style.filter = 'alpha(opacity=1)';
	} else {
		imgDivs[divId][imgIndex[divId]].style.opacity = 0.99;	
		imgDivs[divId][imgIndexNext[divId]].style.opacity = 0.01;
	}		
	
   var imgTimeout = imgFadeInterval + foffset;
 
	setTimeout('revealImage("' + divId + '")',imgTimeout);		
}

function revealImage(divId)
{
   imgDivs[divId][imgIndexNext[divId]].style.visibility = 'visible';
   
	slideshow2_currentOpacity[divId]--;
   if(isIE) {
		imgDivs[divId][imgIndex[divId]].style.filter = 'alpha(opacity='+slideshow2_currentOpacity[divId]+')';
		imgDivs[divId][imgIndexNext[divId]].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity[divId])+')';
	}else{
		imgDivs[divId][imgIndex[divId]].style.opacity = Math.max(0.01,slideshow2_currentOpacity[divId]/100);	// Can't use 1 and 0 because of screen flickering in FF
		imgDivs[divId][imgIndexNext[divId]].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity[divId]/100)));
	}
	if(slideshow2_currentOpacity[divId]>0){
		setTimeout('revealImage("' + divId + '")', imgFadeSpeed);
	}else{
		imgDivs[divId][imgIndex[divId]].style.visibility = 'hidden';	
		if(isOP)imgDivs[divId][imgIndex[divId]].style.display = 'none';		
		showGallery(divId);
	}
}

function initImageFade(divId, imgFadeOffset, fadeInterval)
{

	var slideshow2_galleryContainer = document.getElementById(divId);
	foffset = imgFadeOffset;
   imgFadeInterval = fadeInterval;
   
	imgIndex[divId] = -1;
	imgIndexNext[divId] = false;
	
	var galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('img');
	for(var no=0;no<galleryImgArray.length;no++){
		galleryImgArray[no].id = divId + '_' + no;
	}
	
	imgCount[divId] = galleryImgArray.length;
	createParentDivs(0,divId);		

}

