var browser=navigator.userAgent.toLowerCase();
var IE = false;
if (browser.indexOf("msie") != -1) {
	IE = true;
}
function debug(v) {
	var b = document.getElementsByTagName('body')[0];
	var d = document.createElement('div');
	d.style.color="#fff";
	d.innerHTML = v;
	b.insertBefore(d, b.firstChild);
}
var imgs = Array();
var currScene = 0;
var pgs = Array();
var slideID = null;

function initAnimation() {
	var h = $('nice-header');
	imgs = h.getElementsByTagName('img');	
	pgs = $('slide_pages').getElementsByTagName('a');
	for(var i=0; i<pgs.length; i++) {
		pgs[i].i = i;
		pgs[i].onclick = function(){
			
			nextScene(this.i);
			return false;
		}
	}
	startSlideShow();
}

var step = 5;
var timeID = null;
function animate(el, id) {
	if(!timeID) {
		el.style.zIndex = 20;
		imgs[id].style.zIndex = 19;
		
		el.style.opacity = 1;
		
		if(IE) {
			el.style.filter = "alpha(opacity=100)";
		}
		
		timeID = setInterval(function(){animate(el, id)}, 1);
		pgs[currScene].className = '';
		pgs[id].className = 'active';
	}
	el.style.opacity = parseFloat(el.style.opacity) - (step/100);
	if(IE) {
		el.style.filter = "alpha(opacity="+ parseFloat(el.style.opacity)*100 +")";
	}
	
	if(parseFloat(el.style.opacity) < 0.01) {
		clearInterval(timeID);
		timeID = null;
		el.style.zIndex = 1;
		imgs[id].style.zIndex = 20;
		
		el.style.opacity = 1;
		if(IE) {
			el.style.filter = "alpha(opacity=100)";
		}
		currScene = id;
	}
}

function nextScene(id) {
	if(id==imgs.length) {
		id=0;
	}
	animate(imgs[currScene], id);	
}

function startSlideShow() {
	if(!slideID) {
		slideID = setInterval(startSlideShow, 8000);
	}else {
		id = currScene+1;
		nextScene(id);
	}
}