$(function() {
	
	// Slideshow
	$('#slideshow .photos').cycle({
		fx: 'shuffle',
		speed: 1000,
		timeout: 4000
	});
	
	// Promo
	var promoImg = $('<img src="http://www.laborphoto.com.br/liv/bg/promo.jpg" />');
	promoImg.load(function() {
		$('#promo a').animate({width:'576px',height:'340px'},function() {
			window.setTimeout("$('#promo a').animate({width:'220px',height:'180px'},'fast')",3000);
		});
	});
	
	$('#promo a').hover(function() {
		$(this).stop().animate({width:'576px',height:'412px'});
	},function() {
		$(this).stop().animate({width:'220px',height:'180px'});
	})
	
	// Busca, newsletter
	$('#tab-input').focus(function() {
		if($(this).val().match(/Pesquise no blog|Assine nossas newsletters/)) {
			$(this).val('');
		}
	});
	
	// Sombra da data no topo
	$('#top em').after('<em class="shadow">'+$('#top em').html()+'</em>');
	
	// Enquete
	$('#enquete ul label').each(function() {
		$(this).click(function() {
			$('#sidebar #s-enquete form label').css('font-weight','normal');
			$(this).css('font-weight','bold');
			$('#enquete ul label').css('background-position','-14px 4px');
			$(this).css('background-position','0px -38px');
		});
	});
	
	$('#enquete .submit').live('click',function() {
		$('#enquete').fadeOut('fast',function() {
			var vote = $('#enquete :checked').val();
			var pollId = $('#enquete :hidden').val();
			$.ajax({
				type: 'POST', url: 'liv/model/enquete',
				data: 'opt='+vote+'&id='+pollId, success: function(results) {
					$('#s-enquete').append(results);
					$('#enquete-votos').fadeIn('fast',function() {
						$(this).find('li').each(function() {
							var pos = parseFloat($(this).attr('class').replace('pos',''));
							$(this).animate({backgroundPosition:pos+'px 2px'},'slow');
						});
						$(this).find('.closeResults').click(function() {
							$(this).parent().remove();
							$('#enquete').fadeIn('fast');
							return false;
						});
					});
				}
			});
		});
		return false;
	});

	// Lista dos arquivos
	$('#sidebar #arquivos-month ul li strong').each(function() {
		$(this).click(function() {
			$(this).next('ul.months').slideToggle();
		});
	});
})