/* Javascript para funcionalidades do template do PWA */
var PWA = {
	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;
	}
};
PWA.Home = {
	toggleAba: function(obj) {  
		var tab = obj.parentNode;
		var tabId = tab.id.substr((tab.id.length-1), 1);	
	  	var box = document.getElementById('box-mais-populares');
		var getTag = box.getElementsByTagName('h4');
		var quant = getTag.length;
		for(x=0;x<quant;x++) {
  			getTag[x].className = getTag[x].className.replace("selected", "");
			noc = document.getElementById("boxAba" + (x+1))
			noc.className = noc.className.replace("selected", "");  		
		}
		document.getElementById("boxAba" + tabId).className = document.getElementById("boxAba" + tabId).className + " selected"
		getTag[(tabId-1)].className = getTag[(tabId-1)].className + "selected" ;  
		    
		return false;
	}
};
PWA.Home.TV = {
	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 (PWA.isIE6()) {
				element.style.filter = "alpha(opacity="+opacity+")";
			} else if (PWA.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) {
				PWA.Home.TV.currentOpacity = start;
			} else {
				PWA.Home.TV.currentOpacity = opacity;
			}
			if (PWA.Home.TV.opacityIncrement == null) {
				PWA.Home.TV.opacityIncrement = Math.round((end-start)/PWA.Home.TV.opacitySteps);
			}
			PWA.Home.TV.changeOpacity(document.getElementById(id), PWA.Home.TV.currentOpacity);
			PWA.Home.TV.currentOpacity += PWA.Home.TV.opacityIncrement;
			if (PWA.Home.TV.currentOpacity <= end) {
				setTimeout("PWA.Home.TV.calculateOpacity('"+id+"', "+start+", "+end+", "+PWA.Home.TV.currentOpacity+")", 50);
			}
		} catch (e) {
		}
	},

	rotateChannel: function(time) {
		tTV = window.setInterval("PWA.Home.TV.changeChannel('rotate')", time * 1000);
	},
  
  clearRotateChannel: function() {
		clearInterval(tTV);
		PWA.Home.TV.rotateChannel(tempoCanais);
	},

	pauseRotate: function(pause) {
		if (pause == true) {
			PWA.Home.TV.rotatePaused = true;
		} else {
			PWA.Home.TV.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";
				} else {
					if(document.getElementById("modOAS")) document.getElementById("modOAS").style.display="none";
					document.getElementById("modTV").style.display="block";
				}
				document.getElementById("scrTV"+i).style.display="block";
				document.getElementById("chTV"+i).style.display="block";
				document.getElementById("btTV"+i).className="on";
				this.calculateOpacity("imgTV"+i, 0, 100);
			} else {
				document.getElementById("scrTV"+i).style.display="none";
				document.getElementById("chTV"+i).style.display="none";
				document.getElementById("btTV"+i).className="";
			}
		}
		return false;
	}

};
