﻿/**
 * @author Divonei
 */

var arrx = new Array();
var arr = new Array();
arrx[0] = "images/menu.png";
arrx[1] = "images/menu2.png";
arrx[2] = "images/menu3.png";
arrx[3] = "images/menu4.png";
var images = new Array;

for(var k=0; k<arrx.length; k++){
	images[k] = new Image();
	images[k].src = arrx[k];
	images.onload = function(){}	
}

function limpa(b){
	var kids = b.childNodes;
	var numkids = kids.length;		
	for(var i=numkids-1; i>=0; i--){
	b.removeChild(kids[i]);
	}		
}

$(function(){so_init();});

var d=document, imgs = new Array(), zInterval = null, pause=false, cOpacity=1.00, nOpacity=0,current=0;
var menu, nIndex, fadeInterval, backCourse=false, aLinks= new Array();

function so_init() {	
	if(!d.getElementById || !d.createElement)return;	
	imgs = d.getElementById("splash").getElementsByTagName("img");
	aLinks = d.getElementById("splash").getElementsByTagName("area");
	for(i=1; i<aLinks.length; i++)
		aLinks[i].setAttribute('href',"#");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[current].style.display = "block";
	imgs[current].xOpacity = .99;
	imgs[current].src = 'css/images/splash.png';
	var images = new Array();
	makeImg();
	pause = true;
	
	menu = document.getElementById("menu");
	nIndex = current;
}


function makeImg(){
	for(var i = 1; i<4; i++){
		imgs[i].src = 'css/images/splash'+(i+1)+'.png';
		imgs[i].onload = function(){			
				aLinks[0].href = "javascript:iniCross('Previous');";
				aLinks[1].href = "javascript:iniCross('Next');";
		}
	}
	
	pause = false;
	setTimeout('iniCross()', 10000);
}

function so_xfade() {
		
	if(!backCourse)
		nIndex = imgs[current+1]?current+1:0;	
		
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	ImgOpacity(imgs[current]); 
	ImgOpacity(imgs[nIndex]);
	menu.className = "menu"+(nIndex>0 ? nIndex : "");	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";		
		current = nIndex;
		cOpacity = 1.00;
		nOpacity = 0;
		backCourse = false;
		clearInterval(fadeInterval);
		iniCross('');
	} else {
		fadeInterval = setTimeout(so_xfade,50);	
	}	
	
}

function ImgOpacity(IMGobj) {
		if(IMGobj.xOpacity>.99) {
			IMGobj.xOpacity = .99;
			return;
		}
		IMGobj.style.opacity = IMGobj.xOpacity;
		IMGobj.style.MozOpacity = IMGobj.xOpacity;
		IMGobj.style.filter = "alpha(opacity=" + (IMGobj.xOpacity*100) + ")";
}

function Start(){	
	pause = false;
}

function Stop(){
	clearTimeout(zInterval);
	pause = true;
}

function iniCross(prev_next){
	if(!pause){
		clearInterval(zInterval);
	 	zInterval =setTimeout("so_xfade()", 1000*8);
	}
	if(prev_next=='Next'){		
		so_xfade();
	}
	else if(prev_next=='Previous'){																			
				nIndex--;								
				if(nIndex<0){
					nIndex = (imgs.length)-1;
				}
				backCourse = true;
		
			so_xfade();
		}	
}



