$(document).ready(function() {
	
	$(".btn-abrir-footer a").click(function () {
		if($(".btn-abrir-footer").hasClass('current')){
			$(".btn-abrir-footer").removeClass('current');
		}else{
			$(".btn-abrir-footer").addClass('current');
		}
	  $("#footer-content").slideToggle("slow");
    });
	
	$(".thumbnail").stop().fadeTo(0.1, 0.2); // This sets the opacity of the thumbs to fade down to 90% when the page loads  
	$(".thumbnail").hover(function(){  
		$(this).stop().fadeTo(200, 1.0); // This should set the opacity to 100% on hover  
	},function(){  
		$(this).stop().fadeTo(500, 0.2); // This should set the opacity back to 90% on mouseout  
	});
	
	$("#port1 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port1").slideUp(function() { 
			$("#port1").load(urlLoad, function() {
				document.getElementById("port1-container").style.height = "auto";
				document.getElementById("port1-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port1").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port2 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port2").slideUp(function() { 
			$("#port2").load(urlLoad, function() {
				document.getElementById("port2-container").style.height = "auto";
				document.getElementById("port2-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port2").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port3 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port3").slideUp(function() { 
			$("#port3").load(urlLoad, function() {
				document.getElementById("port3-container").style.height = "auto";
				document.getElementById("port3-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port3").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port4 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port4").slideUp(function() { 
			$("#port4").load(urlLoad, function() {
				document.getElementById("port4-container").style.height = "auto";
				document.getElementById("port4-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port4").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port5 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port5").slideUp(function() { 
			$("#port5").load(urlLoad, function() {
				document.getElementById("port5-container").style.height = "auto";
				document.getElementById("port5-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port5").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port6 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port6").slideUp(function() { 
			$("#port6").load(urlLoad, function() {
				document.getElementById("port6-container").style.height = "auto";
				document.getElementById("port6-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port6").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port7 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port7").slideUp(function() { 
			$("#port7").load(urlLoad, function() {
				document.getElementById("port7-container").style.height = "auto";
				document.getElementById("port7-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port7").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port8 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port8").slideUp(function() { 
			$("#port8").load(urlLoad, function() {
				document.getElementById("port8-container").style.height = "auto";
				document.getElementById("port8-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port8").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port9 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port9").slideUp(function() { 
			$("#port9").load(urlLoad, function() {
				document.getElementById("port9-container").style.height = "auto";
				document.getElementById("port9-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port9").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port10 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port10").slideUp(function() { 
			$("#port10").load(urlLoad, function() {
				document.getElementById("port10-container").style.height = "auto";
				document.getElementById("port10-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port10").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port11 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port11").slideUp(function() { 
			$("#port11").load(urlLoad, function() {
				document.getElementById("port11-container").style.height = "auto";
				document.getElementById("port11-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port11").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port12 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port12").slideUp(function() { 
			$("#port12").load(urlLoad, function() {
				document.getElementById("port12-container").style.height = "auto";
				document.getElementById("port12-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port12").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port13 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port13").slideUp(function() { 
			$("#port13").load(urlLoad, function() {
				document.getElementById("port13-container").style.height = "auto";
				document.getElementById("port13-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port13").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port14 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port14").slideUp(function() { 
			$("#port14").load(urlLoad, function() {
				document.getElementById("port14-container").style.height = "auto";
				document.getElementById("port14-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port14").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port15 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port15").slideUp(function() { 
			$("#port15").load(urlLoad, function() {
				document.getElementById("port15-container").style.height = "auto";
				document.getElementById("port15-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port15").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port16 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port16").slideUp(function() { 
			$("#port16").load(urlLoad, function() {
				document.getElementById("port16-container").style.height = "auto";
				document.getElementById("port16-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port16").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port17 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port17").slideUp(function() { 
			$("#port17").load(urlLoad, function() {
				document.getElementById("port17-container").style.height = "auto";
				document.getElementById("port17-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port17").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port18 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port18").slideUp(function() { 
			$("#port18").load(urlLoad, function() {
				document.getElementById("port18-container").style.height = "auto";
				document.getElementById("port18-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port18").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port19 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port19").slideUp(function() { 
			$("#port19").load(urlLoad, function() {
				document.getElementById("port19-container").style.height = "auto";
				document.getElementById("port19-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port19").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port20 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port20").slideUp(function() { 
			$("#port20").load(urlLoad, function() {
				document.getElementById("port20-container").style.height = "auto";
				document.getElementById("port20-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port20").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});
	
	$("#port21 a").click(function(){
		var urlLoad = $(this).attr("href");
		$("#port21").slideUp(function() { 
			$("#port21").load(urlLoad, function() {
				document.getElementById("port21-container").style.height = "auto";
				document.getElementById("port21-container").style.width = "748px";
				currentSlide=0; theSlider(); outboundLinks();
				$("#port21").slideDown({ 
					duration: 1800,
					easing: "easeOutQuint"
				});
			});
		});    
		return false;
	});

});

var currentSlide = 0;
$(document).ready(function() {
  theSlider();
  outboundLinks();
  smoothScroll();
});

function theSlider () {
  $("ul.controls li a").click(function(){
    var widthToMove = 465; var changeLeft = "+=0"; var action = ($(this).attr('class')); 
    var numSlides = $("ul.slides").children().size(); var currentLeft = 0 - (currentSlide * widthToMove);
    var totalWidth = 0 - (numSlides * widthToMove);
    if ('previous' == action && 0 >= (currentLeft + widthToMove)) { 
      changeLeft = currentLeft + widthToMove; currentSlide --;
    } else if ('previous' == action && 0 < (currentLeft + widthToMove)) { 
      changeLeft = totalWidth + widthToMove; currentSlide = numSlides;
    } else if ('next' == action && totalWidth < (currentLeft - widthToMove)) {
      changeLeft = currentLeft - widthToMove; currentSlide ++;
    } else if ('next' == action && totalWidth >= (currentLeft - widthToMove)) {
      changeLeft = "0"; currentSlide = 0;
    }
    $("ul.slides").animate( {left:changeLeft}, { queue: false,duration:1000,easing:'easeOutQuint' } );
    return false;
  });  
}

function outboundLinks () {
  $('a').each(function() {
    var $a = $(this);
    var href = $a.attr('href');
     // see if the link is external
    if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
      // if so, add the GA tracking code
      $(this).addClass("external-link");
      $a.click(function() {
        pageTracker._trackPageview('/outgoing/' + href);
      });
    }
  });
}

function smoothScroll() {
  $('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset},  1000);
	   return false;
	  }
	}
  });
}

function slideSwitch() {
	var $active = $('.destaque-pre IMG.active');

	if ( $active.length == 0 ) $active = $('.destaque-pre IMG:last');

	var $next =  $active.next().length ? $active.next()
		: $('.destaque-pre IMG:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 2.0}, 2000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 5000 );
});
