/**
 * @author allanos | tallerdelsoho
 */

var startStop, Ajax=false;
var curHot=0, curRss=0, hotInterval, rssInterval, pauseHot;
var testObj;

var arr = new Array();

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]);
	}
}

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

var d=document;
var imgs = new Array(), zInterval = null, pause=false, cOpacity=1.00, nOpacity=0.00;
var current=0, nIndex, fadeInterval, backCourse=false;

function so_init() {
	
	if (!document.getElementById || !document.createElement) return;	
	imgs = document.getElementById("imginicio").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0.01;
	imgs[current].style.display = "block";
	imgs[current].xOpacity = 0.01;
	
	nIndex = current;

	zInterval =setTimeout("so_xfade()", 50);
}

function so_xfade() {
		
	if(!backCourse) {
		nIndex = imgs[current+1]?current+1:0;
	}
	
	cOpacity-=0.005; 
	nOpacity+=0.005;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	ImgOpacity(imgs[current]); 
	ImgOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";		
		current = nIndex;
		cOpacity = 1.00;
		nOpacity = 0;
		backCourse = false;
		clearInterval(fadeInterval);
		//Loop continuo!! descomentar para activar pase diapos
		//iniCross('Next');
	} else {
		fadeInterval = setTimeout(so_xfade,50);	
	}	
	
}

function ImgOpacity(IMGobj) {
		if(IMGobj.xOpacity>.995) {
			IMGobj.xOpacity = .995;
			return;
		}
		IMGobj.style.opacity = IMGobj.xOpacity;
		IMGobj.style.MozOpacity = IMGobj.xOpacity;
		IMGobj.style.filter = "alpha(opacity=" + (IMGobj.xOpacity*100) + ")";
}

function iniCross(prev_next){
	if(!pause){
		clearInterval(zInterval);
	 	//zInterval =setTimeout("so_xfade()", 50);
	}
	if(prev_next=='Next'){		
		so_xfade();
	}
	else if(prev_next=='Previous') {																			
		nIndex--;								
		if(nIndex<0){
			nIndex = (imgs.length)-1;
		}
		backCourse = true;
		//so_xfade();		
	}
}

function transStart(){	
	pause = false;	
	iniCross('Next');
}

function transStop(){
	pause = true;
	clearTimeout(zInterval);
	//iniCross('Previous');
}

//Locate

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}	
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}		
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function boxLocate() {
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	var mytop = ((myHeight-496)-36)/32;
	if (mytop <= 0) {
	document.getElementById('topbanner').style.height = "3.5em";
	} else {
	document.getElementById('topbanner').style.height = mytop + "em";
	}
}

// Layer operations.

var fadein=0, fadeout=100, opac;
var callFunc, Value;
var callFadeout;

function showIn(showObj) {
	myShowObj = document.getElementById(showObj);
	myShowObj.style.display = 'block';
}

function showOut(showObj){
	myShowObj = document.getElementById(showObj);
	myShowObj.style.display = 'none';
}

function fadeIn(fadeObj) {
	//alert(fadeObj);	
	testObj = document.getElementById(fadeObj);
	Value=0;
	fadeout=100;					
	callFunc = setInterval('setOpacity()', 50);	
}

function fadeOut(fadeObj){
	testObj = document.getElementById(fadeObj);
	Value=100;					
	callFadeout = setInterval('setOpacity()', 50);
}

function setOpacity()
{		
	//alert(Value);	
	if(Value==0 && fadein<100){		
		fadein+=2;		
		opac = fadein*0.04;
		if(fadein<100){
			testObj.style.opacity = opac;
			testObj.style.filter = 'alpha(opacity=' + (fadein-10) + ')';
		}
		else{
			clearInterval(callFunc);
			fadein=0;
		}							
	}
	else if(Value==100 && fadeout>0){		
			fadeout-=15;		
			opac = fadeout*0.01;
			//alert(opac);
			if(fadeout>0){
				//alert(opac);
				testObj.style.opacity = opac;
				testObj.style.filter = 'alpha(opacity=' + (fadeout-10) + ')';
			} else {
				//alert(fadeout);
				clearInterval(callFadeout);
				fadeout=100;
				testObj.style.display = 'none';
			}
		}
}
