links = {
	home: [ 'bulb.png', 'crescent.png', 'smoke.png', 'industrial.png', 'houserow.png', 'flames.png', 'lake.png', 'conference.png'],
	about: ['oldbooks.png', 'house1.png', 'conference.png', 'bulb.png', 'lake.png'],
	commercial: ['pencils.png', 'conference.png', 'unit.png', 'shopfront.png', 'oldbooks.png'],
	residential: ['house5.png', 'house6.png', 'house4.png', 'house3.png'],
	faq: ['crescent.png', 'industrial.png', 'houserow.png', 'flames.png', 'bulb.png', 'lake.png', 'conference.png'],
	contact: ['crescent.png', 'industrial.png', 'smoke.png', 'houserow.png', 'flames.png', 'bulb.png', 'lake.png', 'conference.png']
}

window.onload = function(){
	script = document.getElementsByTagName("head").item(0).getElementsByTagName("script").item(8).src;
	name = script.substr(script.indexOf("?page=")+6, script.length);        // finds page= in script include
	headers = links[name];
	url = 'layout/header/';								        			// folder images are stored
	images = [];                            			                    // Array of image objects
	current = 0;                            			                    // Currently on image 0, increases during slideshow
	document.getElementById("image").src = url+headers[0];
	for(i=0;i<headers.length;i++){                                          // Cycle through all the header images and create them as Image objects in order to start downloading
		images[i] = new Image();
		images[i].src = url+headers[i];
	}
	Effect.Fade('image', { from: 0.01, to: 0.01, duration: 0.1 });
	setInterval("header()", 5000);                                          // 5 second timer, calling header() on each interval
}

function header(){
	current++;
	if(current >= headers.length){ current = 0; }                           // If current is more than the amount of header images specified then return to 0
	if(images[current].complete == true){                                   // If image has completed then change to it
		switch(Element.getOpacity('image')) {
			case 1:
				$('crossfade').src = images[current].src;
				Effect.Fade('image', { from: 1.0, to: 0.01, duration: 2.5 });
				Effect.Fade('crossfade', { from: 0.01, to: 1, duration: 2.5 });
			break;
			case 0.999999:
				$('crossfade').src = images[current].src;
				Effect.Fade('image', { from: 1.0, to: 0.01, duration: 2.5 });
				Effect.Fade('crossfade', { from: 0.01, to: 1, duration: 2.5 });
			break;
			default:
				$('image').src = images[current].src;
				Effect.Fade('image', { from: 0.01, to: 1, duration: 2.5 });
				Effect.Fade('crossfade', { from: 1, to: 0.01, duration: 2.5 });
			break;
		}
	}else{                                           // if it hasn't loaded yet, move onto the next and recall header() to load it
		current++;
		header();
	}
	return;
}



/*
links = {
	home: [ 'bulb.png', 'crescent.png', 'smoke.png', 'industrial.png', 'houserow.png', 'flames.png', 'lake.png', 'conference.png'],
	about: ['oldbooks.png', 'house1.png', 'conference.png', 'bulb.png', 'lake.png'],
	commercial: ['pencils.png', 'conference.png', 'unit.png', 'shopfront.png', 'oldbooks.png'],
	residential: ['house5.png', 'house6.png', 'house4.png', 'house3.png'],
	faq: ['crescent.png', 'industrial.png', 'houserow.png', 'flames.png', 'bulb.png', 'lake.png', 'conference.png'],
	contact: ['crescent.png', 'industrial.png', 'smoke.png', 'houserow.png', 'flames.png', 'bulb.png', 'lake.png', 'conference.png']
}

window.onload = function(){
	script = document.getElementsByTagName("head").item(0).getElementsByTagName("script").item(8).src;
	name = script.substr(script.indexOf("?page=")+6, script.length);        // finds page= in script include
	headers = links[name];
	url = 'layout/header/';								        			// folder images are stored
	images = [];                            			                    // Array of image objects
	current = 0;                            			                    // Currently on image 0, increases during slideshow
	$('header').getElementsByTagName("div").item(0).style.backgroundImage = 'url('+url+headers[0]+')';
	for(i=0;i<headers.length;i++){                                          // Cycle through all the header images and create them as Image objects in order to start downloading
		images[i] = new Image();
		images[i].src = url+headers[i];
	}	
	setInterval("header()", 5000);                                          // 5 second timer, calling header() on each interval


		$('header').innerHTML += "<div id='phone'><img src='layout/phone.png' alt='' /></div>";

}

function header(){
	current++;
	if(current >= headers.length){ current = 0 }                            // If current is more than the amount of header images specified then return to 0
	if(images[current].complete == true){                                   // If image has completed then change to it
		$('header').getElementsByTagName("div").item(0).style.backgroundImage = 'url('+images[current].src+')';
	}else{                                           // if it hasn't loaded yet, move onto the next and recall header() to load it
		current++;
		header();
	}
}
*/