/* remove class name from a list of elements */
var site_loc = "http://www.burobakeliet.be/klanten/apachi/";
var picture_huidig = 1;
var picture_max = 10;
var picture_locatie = '';
var root_position = 0;

function removeClassNameFrom(list, className) {
	for(var i = 0; element = list[i]; i++) element.removeClassName(className);
}

var execution = false ;

function trigger_big_picture_replace_crossfade( picture_url, trigger )
{

	// set this method to busy
	if( execution ){ return; }
	execution = true ;
	
	// gather actors
	var container	= $('center_picture') ;
	var image		= $('center_picture_img') ;
	// remove border arround previous element and add it to the new
	removeClassNameFrom($$('.link_img'), 'current');
	trigger.addClassName('current');
	
	// fix container element dimensions
	Element.setStyle( container, { height: Element.getHeight( image ) + 'px' } ) ;
	Element.setStyle( container, { width: Element.getDimensions( image ).width + 'px' } ) ;

		
	var fade_in = .3 ; var previous_bgnd = '' ;

	Element.setStyle( container, { background: 'url(' + picture_url + ') no-repeat'} ) ;
	fade_in = .6 ;
	
	// fade current image
	new Effect.Fade( image, { duration: fade_in,
		afterFinish: function(e)
		{
			// load the image
			image.src = picture_url ; 
			image.style.display = 'block' ;
			// fade in
			new Effect.Appear( image, { duration: .3, afterFinish: function(e){ Element.setStyle( container, { background: 'no-repeat center center url(../assets/img/progress_indicator.gif)'} ) } }) ; // end of appear effect
			
			execution = false;
		}
	} ) ;
}

/*function replaceFive (naam){
	for (var i = 1; i<=5; i++){
		picture_huidig = Math.floor(Math.random()*11);
		if(picture_huidig == 0){picture_huidig=1;}	
		if (picture_huidig > picture_max){ picture_huidig = 1;}
		naamNumber = naam + i;
		big_picture_replace_crossfade( picture_huidig, naamNumber);
	}
}*/

function big_picture_replace_crossfade( picture_loc, naam, nummer)
{
	//alert( picture_loc+" "+ naam+" "+ nummer);
	//alert(root_position);
	//alert (naam);
	if (root_position  == 1){
		picture_url = '../images/' + picture_locatie + '/' + picture_loc +'.jpg';
	}else{
		picture_url = 'images/' + picture_locatie + '/' + picture_loc +'.jpg';
	}
	//alert(picture_url);
	// set this method to busy
	if( execution ){ return; }
	execution = true ;
	
	// gather actors
	basisnaam = naam;
	naam = naam + nummer;
	naamimg = naam + '_img';
	nextNummer = nummer + 1;
	var container	= $(naam);
	var image		= $(naamimg);
	// remove border arround previous element and add it to the new
	//removeClassNameFrom($$('.link_img'), 'current');
	//trigger.addClassName('current');
	
	// fix container element dimensions
	Element.setStyle( container, { height: Element.getHeight( image ) + 'px' } ) ;
	Element.setStyle( container, { width: Element.getDimensions( image ).width + 'px' } ) ;

		
	var fade_in = .3 ; var previous_bgnd = '' ;

	Element.setStyle( container, { background: 'url(' + picture_url + ') no-repeat'} ) ;
	fade_in = .7 ;
	
	// fade current image
	new Effect.Fade( image, { duration: fade_in,
		afterFinish: function(e)
		{
			// load the image
			image.src = picture_url ; image.style.display = 'block' ;
			// fade in
			new Effect.Appear( image, { duration: .3, afterFinish: function(e){ 
					Element.setStyle( container, { background: 'no-repeat center center url(../assets/img/progress_indicator.gif)'} );
					//call on next image
					if(nummer<5){	
						picture_huidig = Math.floor(Math.random()*11);
						if(picture_huidig == 0){picture_huidig=1;}						
						big_picture_replace_crossfade(picture_huidig, basisnaam, nextNummer);
					}else{
						automatic_picture_replace(picture_locatie, picture_max);
					}
			} }) ; // end of appear effect
			
			execution = false;
		}
	} ) ;
	
	
	
}

function picture_preload (locatie, max){
	for (var i = 1; i<=max; i++)
   {
  		picture_url = site_loc + 'images/' + locatie + '/' + i +'.jpg';
  		pic = new Image(425,425); 
  		pic.src= picture_url;
   }
 }
 
function start_picture_replace (locatie, max, level){
	for (var i = 1; i<=max; i++)
   {
  		picture_url = site_loc + 'images/' + locatie + '/' + i +'.jpg';
  		pic = new Image(901,142); 
  		pic.src= picture_url;
   }
    
	root_position = level;
	automatic_picture_replace(locatie, max)
}
function google_picture_replace (locatie, max){
	googleMap();
	start_picture_replace(locatie, max);
}
function h_start_picture_replace (locatie, max){
	for (var i = 1; i<=max; i++)
   {
  		picture_url = site_loc + 'images/' + locatie + '/' + i +'.jpg';
  		pic = new Image(901,142); 
  		pic.src= picture_url;
   }
	root_position = 1;
	automatic_picture_replace(locatie, max)
}

function automatic_picture_replace(locatie, max){

	picture_locatie = locatie;
	picture_max = max;	
	
	picture_huidig = Math.floor(Math.random()*11);
	if(picture_huidig == 0){picture_huidig=1;}	
	if (picture_huidig > picture_max){ picture_huidig = 1;}
	window.setTimeout("big_picture_replace_crossfade(picture_huidig, 'big_picture', 1)",1700);
	//window.setTimeout("replaceFive('big_picture')",1500);
	/*picture_huidig = Math.floor(Math.random()*11);
	if(picture_huidig == 0){picture_huidig=1;}	
	if (picture_huidig > picture_max){ picture_huidig = 1;}
	window.setTimeout("big_picture_replace_crossfade(picture_huidig, 'big_picture1')",1700);
	
	
	picture_huidig = Math.floor(Math.random()*11);
	if(picture_huidig == 0){picture_huidig=1;}	
	if (picture_huidig > picture_max){ picture_huidig = 1;}
	window.setTimeout("big_picture_replace_crossfade(picture_huidig, 'big_picture3')",1600);
	
	picture_huidig = Math.floor(Math.random()*11);
	if(picture_huidig == 0){picture_huidig=1;}	
	if (picture_huidig > picture_max){ picture_huidig = 1;}
	window.setTimeout("big_picture_replace_crossfade(picture_huidig, 'big_picture4')",1300);
	
	picture_huidig = Math.floor(Math.random()*11);
	if(picture_huidig == 0){picture_huidig=1;}	
	if (picture_huidig > picture_max){ picture_huidig = 1;}
	window.setTimeout("big_picture_replace_crossfade(picture_huidig, 'big_picture2')",1200);*/
}

function big_picture_replace_crossfade_home( picture_loc) //, trigger )
{
	picture_url = 'images/footer/' + picture_loc +'.jpg';
	// set this method to busy
	if( execution ){ return; }
	execution = true ;
	
	// gather actors
	var container	= $('big_picture') ;
	var image		= $('big_picture_img') ;
	// remove border arround previous element and add it to the new
	//removeClassNameFrom($$('.link_img'), 'current');
	//trigger.addClassName('current');
	
	// fix container element dimensions
	Element.setStyle( container, { height: Element.getHeight( image ) + 'px' } ) ;
	Element.setStyle( container, { width: Element.getDimensions( image ).width + 'px' } ) ;

		
	var fade_in = .3 ; var previous_bgnd = '' ;

	Element.setStyle( container, { background: 'url(' + picture_url + ') no-repeat'} ) ;
	fade_in = .7 ;
	
	// fade current image
	new Effect.Fade( image, { duration: fade_in,
		afterFinish: function(e)
		{
			// load the image
			image.src = picture_url ; image.style.display = 'block' ;
			// fade in
			new Effect.Appear( image, { duration: .3, afterFinish: function(e){ 
					Element.setStyle( container, { background: 'no-repeat center center url(assets/img/progress_indicator.gif)'} );
					//call on next image
					automatic_picture_replace_home();
			} }) ; // end of appear effect
			
			execution = false;
		}
	} ) ;
	
	
	
}

function automatic_picture_replace_home(){
	picture_huidig += 1;	
	if (picture_huidig > picture_max){ picture_huidig = 1;}
	//alert(picture_huidig);
	setTimeout("big_picture_replace_crossfade_home(picture_huidig)",3000);
	
}

/*window.onload = function() {
	automatic_picture_replace();
}*/

