// funcoes que depende do jquery.js
$(function() {
	// corrige o bug de imagens de background no ie6
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	
	// tabela zebrada
	$('table.zebra tbody tr:odd').addClass('odd');
	$('table.zebra tbody tr:even').addClass('even');
	
	// link na linha inteira
	$('table.zebra tbody tr td').hover(function(){
		$(this).addClass('zebraOver');
		$(this).find('a').addClass('over');
	}, function(){
		$(this).removeClass('zebraOver');
		$(this).find('a').removeClass('over');
	});
	$('table.zebra tbody tr td').click(function(){
		$(this).find('a').each(function(){
			location.href = $(this).attr('href');
			return false;
		});
	});
	
	// link de zoom da capa do livro
	$('#detalhes a.zoom').click(function(){
		$('#detalhesContent').find('div[@class!=fotoThumb]').addClass('alpha');
		$('#zoom').show('slow');
		return false;												 
	});
	
	// link fechar do zoom
	$('#zoom a').click(function(){
		$('#zoom').hide('slow');
		$('#detalhesContent').find('div[@class!=fotoThumb]').removeClass('alpha');
		return false;												 
	});
	
	// link na linha inteira
	$('div.item').click(function(){
		pag = $(this).find('a').attr('href');
		location.href = pag;
	});
	$('div.item').hover(function(){
		$(this).addClass('itemOver');
	}, function(){
		$(this).removeClass('itemOver');
	});
	
	// busca
	$('a.submit').click(function(){
		val = $('input[@name=keyword]').val();
		if (val=='' || val=='Busca por livro') {
			alert('Digite o nome do livro');
			$('input[@name=keyword]').focus();
		} else {
			$(this).parent('form').submit();
		}
		return false;
	});
	$('input[@name=keyword]').focus(function(){
		if ($(this).val()=='Busca por livro') {
			$(this).val('');
		}
	});
});


// abre zoom para fotos
function zoom(pImg) {
	window.open('../img/_zoom.php?foto='+pImg, 'zoom', 'top=160, left=252, width=510, height=410, status=yes');
}

// valida endereco de e-mail
function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){
			return true;
		}
	}else{
		return false;
	}
}

function showBanner() {
	// anima o skybanner
	$('#skybanner').show('slow');
}
