$(document).ready(function(){
	
	ie6 = (($.browser.msie) && (parseInt($.browser.version.substr(0,1)) <= 6));
	
	$('div.scrollable').scrollable();
	$('a.lightbox').lightBox();
	$('a.blank').attr('target','_blank');
	$('#periodo').bind('change', function(){
		$.ajax({
			url: '/noticias/ajax/periodo/',
			data: $('#updateperiodo').serialize(),
			beforeSend: function() {
				$('#arquivo form fieldset #waiting').show(function(){
					if (ie6) {
						$('#bottom').hide();
					}
				});
			},
			success: function(txt) {
				if (ie6) {
					$('#listnews ul').hide(function(){
						$(this).html('').html(txt).show(function(){
							$('#content').css('background','transparent').css('background','url(/img/ie6/bg-full-white.png) no-repeat left top');
							$('#bottom').show(function(){
								$('#arquivo form fieldset #waiting').hide();
							});
						});
					});
				} else {
					$('#listnews ul').slideUp(function(){
						$(this).html('').html(txt).slideDown(function(){
							$('#arquivo form fieldset #waiting').hide();
						});
					});
				}
			},
			cache: false,
			type: 'GET'
		});
	});
	$('#letra').bind('change', function(){
		window.location.href = '/glossario/letra/' + $(this).find('option:selected').val().toLowerCase().toString() + '.html';
	});
	$('a.reset').bind('click', function(){
		$('#contato').each(function(){
			this.reset();
		});
	});
	$('#telefone').mask('(99) 9999-9999');
	$('#contato').bind('submit', function(e){
		e.preventDefault();
		var fields = new Array();
		$(this).find('input,textarea').each(function(){
			if ($(this).val() == '') {
				(typeof($(this).attr('alt')) != 'undefined') ? fields.push($(this).attr('alt')) : fields.push($(this).attr('title'));
			}
		});
		fields.pop();
		if (fields.length) {
			var msg = "Para enviar sua mensagem, preencha os campos:\n";
			for (var i=0; i<fields.length; i++) {
				msg += " - " + fields[i] + ";\n";
			}
			alert(msg);
		} else {
			$(this).each(function(){
				this.submit();
			});
		}
	});
	$('a.openwindow').bind('click', function(e){
		e.preventDefault();
		window.open($(this).attr('href'), 'folder', 'width=1000,height=600,toolbar=0,scrollbars=0,resizable=1,top=80,left=80');
	});
});

function preview(id,leg) {
	$('#galery').css('background','url(/img/noticias/galeria/'+ id +'d.jpg) no-repeat left top');
	$('#galery a').attr('title',leg).attr('href','/img/noticias/galeria/'+ id +'g.jpg');
	$('div.galeria div a img').removeClass('atual');
	$('#p' + id).addClass('atual');
}