/* Javascript para funcionalidades do template do INFO */
var INFO = {
	isIE: function() {
		/*@cc_on return true; @*/
		return false;
	},
	isIE6: function() {
		/*@cc_on @if (@_jscript_version <= 5.6) return true; @end @*/
		return false;
	},
	isIE7: function() {
		/*@cc_on @if (@_jscript_version > 5.6) return true; @end @*/
		return false;
	}
};
INFO.DESTAQUE = {
	totalChannels: null,
	currentChannel: null,
	currentOpacity: null,
	opacityIncrement: null,
	rotatePaused: false,
	opacitySteps: 10,


	init: function(total, start) {
		//jslog.info("total: "+total+", start: "+start);
		this.totalChannels = total;
		this.currentChannel = start;
		this.changeChannel(start);
	},

    hiddenObjectUno: function(){
        document.getElementById("btTV0").style.display="none";
        document.getElementById("bt-esq").style.display="none";
        document.getElementById("bt-dir").style.display="none";
    },
    
    changeOpacity: function(element, opacity) {
		try {
			if (INFO.isIE6()) {
				element.style.filter = "alpha(opacity="+opacity+")";
			} else if (INFO.isIE7()) {
				element.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+")";
			} else {
				var floatOpacity = (opacity/100);
				element.style.opacity = floatOpacity;
				element.style.MozOpacity = floatOpacity;
				element.style.KhtmlOpacity = floatOpacity;
			}
		} catch (e) {
		}
	},

	calculateOpacity: function(id, start, end, opacity) {
		try {
			if (opacity == undefined) {
				INFO.DESTAQUE.currentOpacity = start;
			} else {
				INFO.DESTAQUE.currentOpacity = opacity;
			}
			if (INFO.DESTAQUE.opacityIncrement == null) {
				INFO.DESTAQUE.opacityIncrement = Math.round((end-start)/INFO.DESTAQUE.opacitySteps);
			}
			INFO.DESTAQUE.changeOpacity(document.getElementById(id), INFO.DESTAQUE.currentOpacity);
			INFO.DESTAQUE.currentOpacity += INFO.DESTAQUE.opacityIncrement;
			if (INFO.DESTAQUE.currentOpacity <= end) {
				setTimeout("INFO.DESTAQUE.calculateOpacity('"+id+"', "+start+", "+end+", "+INFO.DESTAQUE.currentOpacity+")", 50);
			}
		} catch (e) {
		}
	},

	rotateChannel: function(time) {
		tTV = window.setInterval("INFO.DESTAQUE.changeChannel('rotate')", time * 1000);
	},
	
	clearRotateChannel: function() {
		clearInterval(tTV);
		INFO.DESTAQUE.rotateChannel(tempoCanais);
	},	

	pauseRotate: function(pause) {
		if (pause == true) {
			INFO.DESTAQUE.rotatePaused = true;
		} else {
			INFO.DESTAQUE.rotatePaused = false;
		}
	},

	changeChannel: function(ch) {
		if(!isNaN(ch)){
			this.currentChannel = ch;
		} else {
			if(ch == "previous") {
				//jslog.info("user clicked on number");
				this.currentChannel--;
				if(this.currentChannel < 0) this.currentChannel = (this.totalChannels-1);
			} else if(ch == "next") {
				//jslog.info("user clicked next");
				this.currentChannel++;
				if(this.currentChannel >= this.totalChannels) this.currentChannel = 0;
			} else if(ch == "rotate" && !this.rotatePaused) {
				//jslog.info("rotate mode");
				this.currentChannel++;
				if(this.currentChannel >= this.totalChannels) this.currentChannel = 0;
			} else {
				return false;
			}
		}

		//jslog.info("changing channel to "+this.currentChannel);

		for(i=0;i<this.totalChannels;i++){
			if(i == this.currentChannel){
				if(document.getElementById("scrTV"+i).className == "oas"){
					document.getElementById("modTV").style.display="none";
					if(document.getElementById("modOAS")) document.getElementById("modOAS").style.display="block";
					document.getElementById("controle").style.display="none";
				} else {
					if(document.getElementById("modOAS")) document.getElementById("modOAS").style.display="none";
					document.getElementById("modTV").style.display="block";
					document.getElementById("controle").style.display="block";
				}
				document.getElementById("scrTV"+i).style.display="block";
        document.getElementById("txt"+i).style.display="block";
        document.getElementById("fundo"+i).style.display="block";
        document.getElementById("bt"+i).className="marcSelecionado";
				this.calculateOpacity("imgTV"+i, 0, 100);
				this.calculateOpacity("txt"+i, 0, 100);
        this.calculateOpacity("fundo"+i, 0, 65);
			} else {
				document.getElementById("scrTV"+i).style.display="none";
				document.getElementById("txt"+i).style.display="none";
        document.getElementById("fundo"+i).style.display="none";
        document.getElementById("bt"+i).className="marcador";
        //document.getElementById("chTV"+i).style.display="none";
        //document.getElementById("btTV"+i).className="";
			}
		}
		return false;
	}

};
//Carrossel materias
	jQuery(function() {
		var step = 3; 
		var current = 0; 
		var maximum = jQuery('#my_carousel ul li').size(); 
		var visible = 3; 
		var speed = 800; 
		var liSize = 217;
		var carousel_height = 195;
		var ulSize = liSize * maximum;   
		var divSize = liSize * visible;  
 
    
		jQuery('#my_carousel ul').css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");
    jQuery('#my_carousel').css("height", carousel_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
    //Remove borda do carrossel
    jQuery('#my_carousel > ul > li:eq(2)').css('border', 'none');
    jQuery('#my_carousel > ul > li:eq(5)').css('border', 'none');
    jQuery('#my_carousel > ul > li:eq(8)').css('border', 'none');
    jQuery('.btnnext').click(function() { 
		  if(current + step < 0 || current + step > maximum - visible){
        return; 
      } else {
		    current = current + step;
        jQuery('#my_carousel ul').animate({left: -(liSize * current)}, speed, null);
			}
			return false;
  	});
		jQuery('.btnprev').click(function() { 
      if(current - step < 0 || current - step > maximum - visible) {
        return; 
        } else {
				  current = current - step;
				  jQuery('#my_carousel ul').animate({left: -(liSize * current)}, speed, null);
        }
        return false;
		  });
  	});
/* Carrossel whitepapers */  	
function whitepapers_initCallback(carousel){
	carousel.clip.hover(function() {carousel.stopAuto();}, function() {carousel.startAuto();});
};
  jQuery(document).ready(function() {
    jQuery('#whitepapers-mycarousel').jcarousel({
		  auto: 6,
		  wrap: 'last',
  		initCallback: whitepapers_initCallback
	});
});







