Carrousel = function(e,q,s){

  var qt = $('.'+e+' ul li').length;
  var l = ($('.'+e+' ul li').width());
  var p = 0;
  //setando a largura do ul
	$('.'+e+' ul').width( qt * l );
  //desativando o botÃ£o esquerdo
  $('.'+e+' .prev').css("opacity","0.5");
	
	// botao direito
  $('.'+e+' .next').click(function(){
    $('.'+e+' ul').stop();
    if ( p < qt - q){ p += s; }
    var left = - (p * l);
    if ( (p + ( q - 1 )) >= qt ){ left = -( ( qt * l ) - ( l * q)  ) }
    $('.'+e+' ul').animate({ left: left+"px" }, 500 ,
      function(){
        $('.'+e+' .prev').removeAttr("style");
        if ( (p + q ) >= qt ) { $('.'+e+' .next').css("opacity","0.5"); }
        else { $('.'+e+' .next').removeAttr("style"); }
      }
    );
  });
  // botao esquerdo
  $('.'+e+' .prev').click(function(){
    $('.'+e+' ul').stop();
    if ( p >= 1 ){ p -= s ; }
    var left = - (p * l);
    $('.'+e+' ul').animate({ left: left+"px" }, 500 ,
      function(){
        $('.'+e+' .next').removeAttr("style");
        if ( p + 1 == 1 ){ $('.'+e+' .prev').css("opacity","0.5"); }
        else { $('.'+e+' .prev').removeAttr("style"); }
      }
    );
  });
};

CarrouselVertical = function(e,quantidade,s){
  var quantidade = 3;
  var s = 1;
    
  var position = 0;
  
  var alturaTotal = $('.'+e+' ul').height();
  var altura = $('.'+e+' .crop').height();
  var largura = (altura / 3);
  var quantidadeLI = (alturaTotal / largura);
  
  $('.'+e+' .prev').css("opacity","0.5");
  
  // botao sobe
  $('.'+e+' .prev').click(function(){
    $('.'+e+' ul').stop();
    if ( position >= 1 ){ position -= s ; }
    var top = - (position * largura);
    $('.'+e+' ul').animate({ top: top+"px" }, 500 ,
      function(){
        $('.'+e+' .next').removeAttr("style");
        if ( position + 1 == 1 ){ $('.'+e+' .prev').css("opacity","0.5"); }
        else { $('.'+e+' .prev').removeAttr("style"); }
      }
    );
  });
	
	// botao desce
  $('.'+e+' .next').click(function(){
    $('.'+e+' ul').stop();
    if ( position < quantidadeLI - quantidade){ position += s; }
    var top = - (position * largura);
    if ( top > (position * largura) ){
      top = (altura - 500);
    }
    $('.'+e+' ul').animate({ top: top+"px" }, 500 ,
      function(){
        $('.'+e+' .prev').removeAttr("style");
        if ( (position + quantidade ) >= quantidadeLI ) { $('.'+e+' .next').css("opacity","0.5"); }
        else { $('.'+e+' .next').removeAttr("style"); }
      }
    );
  });
  
};

$(document).ready(function(){

	Carrousel('fnUltimasEdicoes',6,3);
	CarrouselVertical('fnCalendario',1,1);
	
	//Acessibilidade - tamanho de texto
	var originalFontSize = $('#cnt').css('font-size');
		// Aumenta texto
		$(".increaseFont").click(function(){
			var currentFontSize = $('.cnt').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('.cnt').css('font-size', newFontSize);
			return false;
		});
		// Diminui texto
		$(".decreaseFont").click(function(){
			var currentFontSize = $('.cnt').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('.cnt').css('font-size', newFontSize);
			return false;
		});
  
	$('.creditos').find('span:first').addClass('first');
  
	$('.breadcrumbs dd:last').addClass('last');

});


wpCaption = {
	anyCase: function(){
		
		
		$('.cnt').find('.wp-caption:not(.alignleft,.aligncenter,.alignright)').each(function(){
			$(this)
				.addClass('wp-caption_anyCase')
				.removeAttr('style')
				.height($(this).find('img').height())
				.children('p')
					.width( ($(this).width() ) - ($(this).find('img').width() ) - 10  );
		});
		
		$('.cnt').find('.wp-caption.alignleft, .wp-caption.alignright').each(function(){
			$(this)
				.removeAttr('style')
				.width( $(this).find('img').width() );
		});
		
		$('.cnt').find('.wp-caption.aligncenter').each(function(){
			$(this)
				.removeAttr('style');
				//alert('achei?');
		});
		
	
	},
	hallOfFrames: function() {
		$('.cnt').find('.wp-caption:not(.alignleft,.aligncenter,.alignright)').each(function(){
			$(this)
				.addClass('wp-caption_hallOfFrames')
				.removeAttr('style')
				.height($(this).find('img').height())
				.children('p')
					.width( ($(this).width() ) - ($(this).find('img').width() ) - 20  );
		});
		$('.cnt .wp-caption:last').addClass('wp-caption_last')
	}
	
}
