var menu=function(){
	var t=15,z=50,s=18,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

var menuPaginas=function(){
	var t=15,z=50,s=18,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */

	/* Changing thedefault easing effect - will affect the slideUp/slideDown methods: */
	$.easing.def = "easeOutBounce";

	/* Binding a click event handler to the links: */
	$('li.button a').click(function(e){
	
		/* Finding the drop down list that corresponds to the current section: */
		var dropDown = $(this).parent().next();
		
		/* Closing all other drop down sections, except the current one */
		$('.dropdown').not(dropDown).slideUp('slow');
		dropDown.stop(false,true).slideToggle('slow');
		
		/* Preventing the default event (which would be to navigate the browser to the link's address) */
		e.preventDefault();
	});
	
	
		//Apanha o numero total de imagens
			totalItens = $(".sliderItens > div").size();
			
			i = 0;
			
			check();
		
		//Apanha o width das imagens dentro do container
			imgWidth = 150; //$("#sliderCursos img").attr("width");
			imgHeight = 35; //$("#sliderCursos img").attr("height");
		
		//Define o width e height da div container de todas as imagens
			$(".sliderItens").css("width",(totalItens * (imgWidth+4)));
			$(".sliderItens").css("height", imgHeight);
		
		//Define o width e height de cada div individual de imagem
			$(".sliderItem").css("width", imgWidth);
			$(".sliderItem img").css("width", imgWidth);
			
			$(".sliderItem").css("height", imgHeight);
			$(".sliderItem img").css("height", imgHeight);
			
		//Função ao clicar no botao esquerdo
			$(".botaoLeft").click(function(){
				if(i != 0) {
					$(".sliderItem").animate({"left": "+=" + (imgWidth+4)}, "slow");
					
					i -= 1;
					
					$(".botaoRight").css("display","inline");
					
					check();
				}
				else {
					$(".botaoLeft").css("display","none");
				}
			});
		
		//Função ao clicar no botão direito
			$(".botaoRight").click(function(index) {
				if(i + 1 != totalItens) {
					$(".sliderItem").animate({"left": "-=" + (imgWidth+4)}, "slow");
					
					i += 1;
					
					$(".botaoLeft").css("display","inline");
					
					check();
				}
				else {
					$(".botaoRight").css("display","none");
				}
			});
			
			function check() {
				if(totalItens == 0) {
					$(".botaoRight").css("display","none");
					$(".botaoLeft").css("display","none");
				}
				
				if(i == 0) {
					$(".botaoLeft").css("display","none");
				}
				
				if(i + 1 == totalItens) {
					$(".botaoRight").css("display","none");
				}
			}

			
			hs.graphicsDir = '/imagens/';
			hs.align = 'center';
			hs.transitions = ['expand', 'crossfade'];
			hs.outlineType = 'rounded-white';
			hs.fadeInOut = true;
			//hs.dimmingOpacity = 0.75;
			
			// Add the controlbar
			hs.addSlideshow({
				slideshowGroup: '1',
				interval: 5000,
				repeat: false,
				useControls: true,
				fixedControls: 'fit',
				overlayOptions: {
					opacity: .75,
					position: 'bottom center',
					hideOnMouseOut: true
				}
			});
			
			hs.addSlideshow({
				slideshowGroup: '2',
				interval: 5000,
				repeat: false,
				useControls: false,
				fixedControls: 'fit',
				overlayOptions: {
					opacity: .75,
					position: 'bottom center',
					hideOnMouseOut: true
				}
			});

			$('#destaqueImagemTopo').cycle({
				fx: 'fade'
			});

});

		$(function() {
			$("#tree").treeview({
				collapsed: true,
				animated: "medium",
				control:"#sidetreecontrol",
				persist: "location"
			});	
		})
		$(function() {
			$("#treeTop").treeview({
				collapsed: true,
				animated: "medium",
				control:"#sidetreecontrol",
				persist: "location"
			});	
		})
		$(function() {
		  $('div.titulo').click(function() {
				var id = this.id.replace(/^.*_(\d)$/, '$1');
				$('#categoria_' + id).slideToggle();
		  });
		});
		
		function changeSliding(from, speed, to) {
			$(from).slideToggle(speed).queue(function() {
				$(to).slideToggle(speed).dequeue();
			});
		}
		
function highlightParent(parent) {
	$("#" + parent).addClass("activo");
}

function decision(message, url){if(confirm(message)) location.href = url;}
