
//inicializados JQuery
$(document).ready(function(){
	animateAtividades();
	countTds();
	$("#td0").animate({opacity:1.0}, 850);
	td_to_textbox(document.getElementById("td20"));
});


var ntds;
function animateAtividades(){
	
	var lf = -2;
	var i = 0
	
	$("#ant").click(function(){
		if (i>=1 || i!=0){
			i--;
			lf = lf+(362);
			$("#atividades").animate({left: lf+"px"}, 450);
			$("#td"+i).animate({opacity:1.0}, 850);
			$("#td"+(i+1)).animate({opacity:0.2}, 250);
			td_to_textbox(document.getElementById("td2"+i));
		}
	});
	
	$("#prox").click(function(){

		if (i<(ntds-1)){
			
			i++;
			lf = lf-(362);
			$("#atividades").animate({left: lf+"px"}, 450);
			$("#td"+i).animate({opacity:1.0}, 850);
			$("#td"+(i-1)).animate({opacity:0.2}, 250);
			td_to_textbox(document.getElementById("td2"+i));
		}
	});
}

function countTds(){
	var tb = document.getElementById("atividades");
	
	var tr2 = tb.getElementsByTagName("tr")[1];
	var tds2 = tr2.getElementsByTagName("td");
	for(var i=0; i<tds2.length; i++){
		tds2[i].id = "td2"+i;
	}
	
	var tr = tb.getElementsByTagName("tr")[0];
	var tds = tr.getElementsByTagName("td");
	for(var i=0; i<tds.length; i++){
		tds[i].i = i;
		tds[i].id = "td"+i;
		tds[i].onmouseover = function(){
			this.style.border = "3px solid #FFF1C4";
			this.style.cursor = "pointer";
		}
		tds[i].onmouseout = function(){
			this.style.border = "3px solid #FEE07A";
		}
		
		tds[i].onclick = function(){
			var op = 0;
			if (this.style.opacity){
				if (this.style.opacity == 1){
					op = 1;
				}
			} else if (this.style.filter){
				if (this.style.filter == "alpha(opacity=100)"){
					op = 1;
				}
			}
			
			if (op == 1){
				var lnk = document.getElementById("td2"+this.i).getElementsByTagName("a")[0];
				document.location.href = lnk.href;
			}
		}
	}
	
	ntds = tds.length;

}

function td_to_textbox(td){
	var txt = document.getElementById("texto");
	txt.innerHTML = td.innerHTML
}

function findPos(obj){
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}
