/**
 * @author Divonei
 */

var menu, splash, startStop, Ajax=false;
var curHot=0, hotInterval, pauseHot;


var arrx = new Array();
var arr = new Array();
//arrx[0] = "banner_site/Banner_CFO.jpg";
//arrx[1] = "images/menu2.png";
//arrx[2] = "images/menu3.png";
//arrx[3] = "images/menu4.png";
//arrx[4] = "images/menu5.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 ajaxRequest(){
	Ajax = false;
	try{
       Ajax = new XMLHttpRequest();
	}catch(ee){
       try{
               Ajax = new ActiveXObject("Msxml.XMLHTTP");        
       }catch(e){
	   		try{
               Ajax = new ActiveXObject("Msxml.XMLHTTP");        
       		}catch(e){
               try{
                       Ajax = new ActiveXObject("Microsoft.XMLHTTP");                
               }catch(E){
			   	Ajax = false;
               }
       		}
	   }
	 }		
}




function teste(str){
	
	var p = document.getElementById('q');
	if(p){
		if(str=="show"){		
			p.style.display = "block";			
			//p.setAttribute("type", "search");			
			p.style.backgroundColor = "#000";
		}
		else
			p.style.display = "none";
	}
	
}
function data(){
	var data = new Date;
	document.write(data.getFullYear());
}

function web_kit(){	
	 var version = get_webkit_version();		
      if(version){
	  	var p = document.getElementById('q');
		//p.setAttribute("type", "search");
		}
}

function limpa(b){
	var kids = b.childNodes;
	var numkids = kids.length;		
	for(var i=numkids-1; i>=0; i--){
	b.removeChild(kids[i]);
	}		
}

function hotStop(){	
	clearInterval(hotInterval);
}

function hotStart(){
	montaHot();
}

function Animation(){	
	var hotNews = document.getElementById('hotnews');	
	if(curHot<arr.Link.length){
		limpa(hotNews);
		var phot = document.createElement('p');			
		var titleText = document.createTextNode(arr.Date[curHot]+ ' - '+arr.Title[curHot]);
		var hotLink = document.createElement('a');
		//hotLink.onmouseover = "hotStop();";
		//phot.onmouseout = "hotStart()";
		//phot.setAttribute('onmouseover', 'hotStop();');
		//phot.setAttribute('onmouseout', 'hotStart();');
		phot.className = "photnews";
		hotLink.setAttribute('href', arr.Link[curHot]);
		hotLink.appendChild(titleText);
		phot.appendChild(hotLink);
		hotNews.appendChild(phot);
		curHot++;	
	}
	else
		curHot = 0;
				
			
	
	
	
}

function montaHot(){
	//Cria elements do hotnews
	
	
	//define a classe do elemento paragrafo correcao para o internet
	
	//chama funcao animation
	hotInterval = setInterval('Animation()', 4000);
}

function showHot(){
	arr.Title = new Array();
	arr.Link = new Array();
	arr.Date = new Array();
	if(Ajax.readyState==4){
		if(Ajax.status==200){
			var xml = Ajax.responseXML;
			if(xml.hasChildNodes()){
				var nod = xml.getElementsByTagName("blog");				
				for(var i =0; i<nod.length; i++){					
					var nd = nod[i];					
					arr.Title[i] = nd.getElementsByTagName("title")[0].firstChild.nodeValue;
					arr.Link[i] = nd.getElementsByTagName("link")[0].firstChild.nodeValue;														
					arr.Date[i] = nd.getElementsByTagName("date")[0].firstChild.nodeValue;
				}
				montaHot();
			}	
		}
	}
	else{
		
	}
}

function hotnews(){	
	ajaxRequest();
	if(!Ajax){
		alert('Ajax its not working');
		return;
	}
	Ajax.open('GET', 'xmlphp.php')
	Ajax.onreadystatechange = showHot;
	Ajax.send(null);
}


window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgs = new Array(), zInterval = null, pause=false, cOpacity=1.00, nOpacity=0;//current=2,
var menu, nIndex, fadeInterval, backCourse=false;

function so_init() {	
	if(!d.getElementById || !d.createElement)return;	
	imgs = d.getElementById("splash").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[current].style.display = "block";
	imgs[current].xOpacity = .99;
	
	var images = new Array();
	
	
	setTimeout(so_xfade,10000);
	menu = document.getElementById("menu");
	var hotNews = document.getElementById('hotnews');
	var phot = document.createElement('p');
	phot.className = "photnews";			
	var titleText = document.createTextNode('Loading Hotnews...');
	phot.appendChild(titleText);
	hotNews.appendChild(phot);
	nIndex = current;
	iniCross();
	hotnews();
}

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;	
	iniCross('');
}

function Stop(){
	clearTimeout(zInterval);
	pause = true;
	iniCross('');
}

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();
		
					
		}	
}



