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;
var urls = [
	'http://www.dmehosting.com/openvz-linux-vps.php',
	'http://www.dmehosting.com/dedicated-specials.php',
	'http://www.dmehosting.com/vps-offers-windows.php',
	'http://www.dmehosting.com/shared.php',
];

function initAnimation() {
	var h = $('fla_head');
	imgs = h.getElementsByTagName('img');
	for(var i=0; i<imgs.length; i++) {
		if(urls[i]!='') {
			imgs[i].url = urls[i]
			imgs[i].onclick = function() {
				location.href = this.url;
				
			}
			imgs[i].style.cursor = 'pointer';
		}
	}
	
	pgs = $('fla_pages').getElementsByTagName('a');
	for(var i=0; i<pgs.length; i++) {
		pgs[i].i = i;
		pgs[i].onclick = function(){
			nextScene(this.i);
		}
	}
	$('prev_scene').onclick = function() {
		if(currScene!=0)
		nextScene(currScene-1);
	}
	$('next_scene').onclick = function() {
		nextScene(currScene+1);
	}
	$('pause_scene').onclick = function() {
		togglePlaySlideShow(this);
	}

	startSlideShow();
}

var step = 10;
var timeID = null;
function animate(el, id) {
	if(!timeID) {
//		alert(el.src);
		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);
	}
	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;
		pgs[currScene].className = '';
		pgs[id].className = 'active';
		el.style.opacity = 1;
		if(IE) {
			el.style.filter = "alpha(opacity=100)";
		}
		currScene = id;
//		startSlideShow();
	}
}

function nextScene(id) {
	if(id==imgs.length) {
		id=0;
	}
//	debug('ID:' + id);
//	debug('currScene:' + currScene);
	animate(imgs[currScene], id);
	
}
function togglePlaySlideShow(el) {
	if(slideID) {
		clearInterval(slideID);
		slideID = null;
		el.innerHTML = 'play';
	}else {
		startSlideShow();
		el.innerHTML = 'pause';
	}
}

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



function $(id) {
	return document.getElementById(id);
}

