﻿window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var d=document, imgs = new Array(), imgs1 = new Array(), zInterval = null, current=0, pause=false;

function so_init(){

Image1= new Image();
Image1.src = "/home/images/homepage/china.jpg";
Image2= new Image();
Image2.src = "/home/images/homepage/france.jpg";
Image3= new Image();
Image3.src = "/home/images/homepage/singapore.jpg";
Image4= new Image();
Image4.src = "/home/images/homepage/brazil.jpg";
Image5= new Image();
Image5.src = "/home/images/homepage/australia.jpg";



	if(!d.getElementById || !d.createElement){return;}
	if(d.getElementById('xfade')){
		//imgs = d.getElementById('xfade').getElementsByTagName('img');
		imgs1 = d.getElementById('xfade').getElementsByTagName('div');
		//imgs = d.getElementsByName("fadez");
	x = 0;
	for(i=0;i<imgs1.length;i++) { 
		var s=imgs1[i].id;
		var idslice = s.charAt(0)+s.charAt(1)+s.charAt(2)+s.charAt(3)+s.charAt(4)+s.charAt(5)+s.charAt(6);
		if(idslice === "fadediv"){
			imgs[x]=imgs1[i];
			x++;
		}
	}



		//startpic(0);

startpic(0);

		t=setTimeout(xfadecycle,4000);
	}
}

function startpic(z){
	z = z*1;
	for(i=0;i<imgs.length;i++) { 
		imgs[i].xOpacity = 0; 
	}
	imgs[z].style.display = 'block';
	imgs[z].xOpacity = 1;
}

function pausepic(z){
	current = z*1;
	clearTimeout(t);
	startpic(current);
	for(i=0;i<imgs.length;i++) { 
		setOpacity(imgs[i]);
		imgs[i].style.display = 'none';
	}
	imgs[current].style.display = 'block';
}

function rotatestart(){
	startpic(current);
	t=setTimeout(xfadecycle,100);
}

function rotatepause(){
	pausepic(current);
}



function xfadecycle(){
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;

	cOpacity-=.1;
	nOpacity+=.1;

	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;

	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		t=setTimeout(xfadecycle,4000);
	}
	else
	{
		t=setTimeout(xfadecycle,50);
	}
}


function setOpacity(obj){
	if(obj.xOpacity>1){
		obj.xOpacity = 1;
	}
	else {
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}

}
