// JavaScript Document

// (c) Alexandre Brillant 2008 

var img = new Array();
img[0] = "melun/halage/images/p1000082.jpg";
img[1]= "foret-fontainebleau1/images/p1000296.jpg";
img[2] = "foret-fontainebleau1/images/p1000315.jpg"
img[3] = "Melun-lemee/images/p1000276.jpg";
img[4] = "samois/images/p1000229.jpg";
img[5] = "samois/images/p1000242.jpg";
img[6] = "moret/images/p1000386.jpg";
img[7] = "moret/images/p1000380.jpg";
img[8] = "moret/images/p1000381.jpg";
img[9] = "moret/images/p1000357.jpg";
img[10] = "melun/halage/images/p1000086.jpg";

var indice = 1;
var im;

function cache() {
	var cacheDiv = document.getElementById( "cache" );
	for ( i = 0; i < img.length; i++ ) {
		var rim = document.createElement( "img" );
		rim.setAttribute( "src", img[ i ] );
		rim.setAttribute( "width", "1" );
		rim.setAttribute( "height", "1" );		
//		rim.setAttribute( "onLoad", "waitForCacheOk()" );
		cacheDiv.appendChild( rim );
		waitForCacheOk();
	}
}

var cacheCount = 0;

function waitForCacheOk() {
	cacheCount++;
	if ( cacheCount == img.length )
		runAll();
}

var mp3 = "canon_in_d.mp3"

function prepareAll() {
	prepareAll( null );	
}

function prepareAll(pmp3) {
	if ( pmp3 != null ) {
			mp3 = pmp3;
	}
	cache();	
}

function runAll() {
			im = document.getElementById( "diapo" );			
			document.getElementById( "embedded" ).innerHTML = "<embed src='" + mp3 + "' loop='true' autostart='true' hidden='true' mastersound>";
			setInterval( disparait,  10000 );
}

var opacity = 1;

function disparait() {
	if ( opacity <= 0 ) {
		apparaitre();
	} else {
		opacity -= 0.1;
		im.style.opacity = opacity;		
		im.style.filter = "alpha(opacity=" + ( opacity * 100 ) + ")";
		setTimeout( disparait, 100 );
	}
}

function apparaitre() {
	if ( opacity <= 0 ) {
		im.style.visibility = "hidden";
		im.style.display = "none";
		im.src = img[ ( ( indice++ ) % img.length ) ];
		im.style.opacity = opacity;
		im.style.filter = "alpha(opacity=" + ( opacity * 100 ) + ")";		
		im.style.display = "block";
		im.style.visibility = "visible";
		opacity = 0.01;
		setTimeout( apparaitre, 100 );
	} else
	if ( opacity < 1 ) {
		opacity += 0.1;
		im.style.opacity = opacity;
		im.style.filter = "alpha(opacity=" + ( opacity * 100 ) + ")";
		setTimeout( apparaitre, 100 );
	}
}
