// JavaScript Document
	var $imgs = new Array('bg-1.jpg','bg-2.jpg','bg-3.jpg','bg-4.jpg','bg-5.jpg','bg-6.jpg','bg-7.jpg','bg-8.jpg','bg-9.jpg','bg-10.jpg','bg-11.jpg','bg-12.jpg','bg-13.jpg'); //quantas fotos tem
	var $time = 4; //tempo em segundos
	var $bgativo = 1;
	var $divativa = 1;
	
	//documentos totais
	$(document).ready(function(){
			$int = setInterval("mudaFundo()",$time*1000);
			$('#animafundo1, #animafundo2').css('height', window.screen.height);
			$('#animafundo2').fadeOut();
			
			//transparencias
			$('#video').fadeTo(0,.7);
			$('#related').fadeTo(0,.7);
			$('#links').fadeTo(0,.7);
			
			$('#related-videos li a').each(function(){
					$(this).click(function(){
							$urlvideo = $(this).attr('href').replace('http://www.youtube.com/watch?v=','').replace('&feature=youtube_gdata','').replace('_player','');
							$('#video h2').html($(this).parent().find('.related-title').html());
							$('#container-video').html('<iframe title="YouTube video player" width="640" height="390" id="youtubeplayer" src="http://www.youtube.com/embed/'+$urlvideo+'" frameborder="0" allowfullscreen></iframe>');
							return false;
					});
			});
	});
	
	//animação fundo
	function mudaFundo(){
		//alert('go');
		$bgativo++;
		if($bgativo>$imgs.length){ $bgativo=1; } ;
			
		if($divativa==1){
			//alert('1 '+$imgs[$bgativo-1]);
			$('#animafundo2').css('zIndex','2').css('backgroundImage','url(\'shared/images/anima/'+$imgs[$bgativo-1]+'\')').fadeIn('slow');
			$('#animafundo1').css('zIndex','1').fadeOut('slow');
			$divativa=2;
		}else{
			//alert('2 '+$imgs[$bgativo-1]);
			$('#animafundo1').css('zIndex','2').css('backgroundImage','url(\'shared/images/anima/'+$imgs[$bgativo-1]+'\')').fadeIn('slow');
			$('#animafundo2').css('zIndex','1').fadeOut('slow');
			$divativa=1;
		}
		
		jQuery.preLoadImages("shared/images/anima/"+$imgs[$bgativo]);		
	}
	
	(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
