// JavaScript Document
$(document).ready(function() {
	
	var totalImg=0;
	$('#slider').find('img').each(function() {
		totalImg++
	});
	/* com slider
	$('#slider').css('width', totalImg*800);	
	if(totalImg==2) {
		$('#slider img:first-child').clone();
		$('#slider').css('width', 3*800);
	}

	function slider() {
		if(totalImg!=1) {
			$('#slider').animate({
				marginLeft: '-=800px'
			}, 1000, 'linear', function() {
				$('#slider img:first-child').appendTo('#slider');
				$('#slider').css('margin-left', '0');
			});
		}
	}
	var intervalo = setInterval(slider, 3000);*/
	$('#slider').css('overflow', 'hidden');
	$('#slider img').css({
		position: 'absolute',
		left: "0",
		top: "0"
	});
	function trocaBaner() {
		if(totalImg!=1) {
			$('#slider img:last-child').animate({
				opacity: "0"
			}, 5000, function(){
				$('#slider img:last-child').prependTo($('#slider'));
				$('#slider img:first-child').css('opacity', '1');
			})
		}
	}
	var intervalo = setInterval(trocaBaner, 10000);
	
	// setas
/*	$('.arrowLeft, .arrowRight').css('margin-top',($(window).height()-70-200)/2);
	$(window).resize(function() {
		$('.arrowLeft, .arrowRight').css('margin-top',($(window).height()-36-200)/2);
	});
	*/
	// hover lista posts
	$('#postList li').find('.postListHover').each(function() {
		$(this).hover(function() {
			$(this).children('a').stop(true).fadeTo('fast', 0.25);
			$(this).children('.postListTitles').stop(true).fadeTo('fast', 1);
		},function(){
			$(this).children('a').stop(true).fadeTo('fast', 1);
			$(this).children('.postListTitles').stop(true).fadeTo('fast', 0);
		});
	});
	
	// habilita clics nos titulos a lista de posts
	$('#postList li').find('.postListTitles').each(function() {
		$(this).click(function(){
			var post = $(this).parent('.postListHover').children('a').attr('href');
			//alert(post);
			window.location.href=post;
		});
	});
	
	// selecionar imagens post interna
	$('#postGallery').find('li').each(function() {
		$(this).children('a').click(function() {
			//alert($(this).children('img').attr('src'));
			$('#thePostImg div').css('background-image', 'url(' +$(this).children('img').attr('src') + ')');
			$('html, body').animate({
				scrollTop: $("#thePost").offset().top
			}, 1000);
		});
	});
	
});
