// JavaScript Document
var header_images= new Array(
"images/headers/eet_homebkpn01.jpg",
"images/headers/eet_homebkpn02.jpg",
"images/headers/eet_homebkpn03.jpg",
"images/headers/eet_homebkpn04.jpg",
"images/headers/eet_homebkpn05.jpg"
);
var busy = false, timer, loadedImages = [];	
var image = 5;
var show;
var pan;
var ie6 = false;
window.addEvent('domready',function(){
	show = new Fx.Morph('reveal',{duration: 1500, transition: Fx.Transitions.Expo.easeInOut, 'link' : 'cancel'});
	pan = new Fx.Morph($('scrolling_image'),{duration: 3500, transition: Fx.Transitions.Expo.easeOut, 'link' : 'cancel'});
	$('dots').setStyle('visibility', 'hidden');
	new Asset.images(header_images, {
		onProgress: function(i) {
			this.setStyles({
				'position': 'absolute'
			});
			loadedImages[i] = this;
		},
		onComplete: function() {
			$('dots').setStyle('visibility', 'visible');	
			setImage(image);
		}
	});
	setTimeout("autoscroll()", 5000);
});
function setImage(image){
	var currentImg = new Image();
	var next = new Image();
	var textFade = new Image();
	textFade.src = "images/headers/text/"+(image)+'.png';
	textFade.alt = "overlay text "+image;
	textFade.id = "reveal";
	$(textFade).setStyle('position', 'absolute');
	$(textFade).setStyle('top', '20px');
	$(textFade).setStyle('left', '20px');
	if(!ie6)
		$(textFade).setStyle('opacity', 0);
	//$(textFade).setStyle('z-index', '8');
	currentImg.src = header_images[(image-1)];
	currentImg.alt = "header" + image;
	currentImg.id = 'scrolling_image';
	$(currentImg).replaces($('scrolling_image'));
	currentImg=next;
	$('dot1').src = 'images/dot.png';
	$('dot2').src = 'images/dot.png';
	$('dot3').src = 'images/dot.png';
	$('dot4').src = 'images/dot.png';
	$('dot5').src = 'images/dot.png';
	$('dot'+image).src = 'images/dot_active.png';
	show.cancel();
	$(textFade).replaces($('reveal'));
	show = new Fx.Morph($(textFade),{duration: 1500, transition: Fx.Transitions.Expo.easeInOut, 'link' : 'cancel'});
	if(!ie6)
		$('reveal').setStyle('opacity', 0);
	$('reveal').setStyle('width', '700px');
	$('reveal').setStyle('height', '150px');
	$('scrolling_image').setStyle('position', 'absolute');
	$('scrolling_image').setStyle('right', '0');
	pan.cancel();
	pan = new Fx.Morph($('scrolling_image'),{duration: 3500, transition: Fx.Transitions.Quad.easeOut, 'link' : 'cancel'});
	var end =  $('scrolling_image').getStyle('width').split('px')[0]-924;
	pan.start({right : [0, -end]}).chain(function() {reveal()});
}

function reveal(){
	if(!ie6)
		show.start({'opacity' : 1});
		autoscroll();
}


function manual(val){
	clearTimeout(delay);
    image=val;
    setImage(image);
}

var delay;
function autoscroll(){
    delay = setTimeout("manual(image)", 5000);
	image<header_images.length ? image++: image=1;
}