/**
 * Inicio Jquery menus
 */
$(document).ready(function(){
	
	// Submenu
	$('.menuPrincipal .sub').hover(function(){
		$(this).find(".submenu").show();
	}, function(){
		$(this).find(".submenu").stop().hide();
	});
	
	// Secretarias
	$('.maisSecretaria li.sub').find('a:eq(0)').click(function(event){
		event.preventDefault();
		element = $(this).parent();
		$('.maisSecretaria li.sub').not(element).removeClass('ativo');
		$('.maisSecretaria li.sub').not(element).children('ul').slideUp();
		$(element).children('ul').slideToggle();
		$(element).toggleClass('ativo');
	});
	$('.maisSecretaria').find('a').click(function(event){
		if($(this).attr('href') == '#' || $(this).attr('href') == '')
		{
			event.preventDefault();
		}
	});
	
	// Atividades
	$('.atividades .anterior').hide();
	$('.atividades .proximo').click(function(event){
		event.preventDefault();
		var img = $('.atividades .paginador a.ativo').next('a');
		$('.atividades .paginador a.ativo').removeClass('ativo').next('a').addClass('ativo');
		$('.atividades .anterior').show();
		$('.atividades img').attr('src', img.attr('rel'));
		$('.atividades a.mainLink').attr('href', img.attr('href'));
		$('.atividades img').attr('title', img.attr('title'));
		if($('.atividades .paginador a.ativo').is(':last-child')){
			$(this).hide();
		}		
	});
	$('.atividades .anterior').click(function(event){
		event.preventDefault();
		var img = $('.atividades .paginador a.ativo').prev('a');
		$('.atividades .paginador a.ativo').removeClass('ativo').prev('a').addClass('ativo');
		$('.atividades .proximo').show();
		$('.atividades img').attr('src', img.attr('rel'));
		$('.atividades a.mainLink').attr('href', img.attr('href'));
		$('.atividades img').attr('title', img.attr('title'));
		if($('.atividades .paginador a.ativo').is(':first-child')){
			$(this).hide();
		}		
	});
	$('.atividades .paginador a').click(function(event){
		event.preventDefault();
		var linkimg = $(this).attr('rel');
		$('.atividades .paginador a').removeClass('ativo');
		$(this).addClass('ativo');
		$('.atividades img').attr('src', linkimg);
		$('.atividades a.mainLink').attr('href', linkimg);
		if($('.atividades .paginador a.ativo').is(':last-child')){
			$('.atividades .proximo').hide();
			$('.atividades .anterior').show();
		}
		if($('.atividades .paginador a.ativo').is(':first-child')){
			$('.atividades .anterior').hide();
			$('.atividades .proximo').show();
		}		
	});
	$('.atividades .paginador a:first').attr('class', 'ativo');
	$('.atividades .paginador a:first').trigger('click');
	
	// Fotos not�cias
	$('.fotosNoticias .anterior').hide();
	$('.fotosNoticias .proximo').click(function(event){
		event.preventDefault();
		var li = $('.fotosNoticias').find('li.ativo').next('li');
		$('.fotosNoticias').find('li').hide();
		$('.fotosNoticias').find('li.ativo').removeClass('ativo').next('li').addClass('ativo').show();
		$('.fotosNoticias .anterior').show();
		if($('.fotosNoticias').find('li.ativo').is(':last-child')){
			$(this).hide();
		}		
	});
	$('.fotosNoticias .anterior').click(function(event){
		event.preventDefault();
		var li = $('.fotosNoticias').find('li.ativo').prev('li');
		$('.fotosNoticias').find('li').hide();
		$('.fotosNoticias').find('li.ativo').removeClass('ativo').prev('li').addClass('ativo').show();
		$('.fotosNoticias .proximo').show();
		if($('.fotosNoticias').find('li.ativo').is(':first-child')){
			$(this).hide();
		}		
	});
	$('.fotosNoticias').find('li:first').attr('class', 'ativo');
	$('.fotosNoticias').find('li:first').trigger('click');
	
	// marca d'agua
	$('.mdagua').click(function(){
		$(this).attr('value', '');
	});
	// Soluções Alternativas
	$('.servicos li, .telefones').click(function(){
		window.location = $(this).children('a').attr("url");
	});
	    // Tooltip
    $('.tooltip').hover(function(){
        var texto = $(this).attr('desc');
        $("<div class='tp'><span class='tp-top'></span><span class='tp-center'>" + texto + "</span><span class='tp-bottom'></span></div>").insertBefore($(this));
        $('.tp').fadeIn(200);
    }, function(){
        $('.tp').remove();
    });
    
    // Pretty Photo
	$("[rel^='prettyPhoto']").prettyPhoto();
});

/**
 * Inicio slider destaques
 */
$(document).ready(function() {
	
	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
	$('.paging > h3').html($('.paging a.active').attr('title'));
	
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){
		$('.paging > h3').html($active.attr('title'));
		
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
	
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 4000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
});

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
