// JavaScript Document

$(function(){
	
	$("#slideshow").easySlider({
		auto: true,
		continuous: true,
		prevText: 	'',
		nextText: 	'',
		pause: 6000
	});
	
	$(".produto img").live('hover',function(){
			$(this).next('span').css({'color':'#F00'});
	});
	
	$(".produto img").live('mouseout',function(){
			$(this).next('span').css({'color':'#523C85'});
	});
	
	$(".listaCategorias li").live('hover',function(){
			$(this).css({'color':'#F00'});
	});
	
	$(".listaCategorias li").live('mouseout',function(){
			$(this).css({'color':'#523C85'});
	});
	
	
	$('.menu li.blog').click(function(){
		window.open("http://laurinacrafts.wordpress.com/");
	});
	
	$('.menu li.contato').click(function(){
		$('#conteudo').html("").load('contato.php', {}, 
			function(){
				$('input.nome').Watermark("Nome:");
				$('input.email').Watermark("E-mail:");
				$('input.assunto').Watermark("Assunto:");
				$('textarea.mensagem').Watermark("Mensagem:");
			}).html('<center><img src="imgs/ajax-loader.gif"></center>');
	});
	
	$('.menu li.home').click(function(){
		window.location = "index.php";
	});
	
	$('.menu li.atelier').click(function(){
		$('#conteudo').html("").load('atelier.php').html('<center><img src="imgs/ajax-loader.gif"></center>');
	});
	
	$('.menu li.produtos').click(function(){
		$('#conteudo').html("").load('produtos.php').html('<center><img src="imgs/ajax-loader.gif"></center>');
	});
	
	$('.btnNews').click(function(){
		
		var email = $('.inputNews').val();
		if (IsEmail(email)) {
				$.ajax({
					url: 'admin/acao.php',
					dataType: 'json',
					data: {acao: 'emailNews', email: $('.inputNews').val()},
			});
				$('.inputNews').val('');
				alert('Email cadastrado com sucesso!');
				
		} else {
                alert('Informe um e-mail válido.');
        };
		
	});
	
	$('.enviarFormulario').live("click",function(){
		
		var email = $('.email').val();
		if (IsEmail(email)) {
				$.ajax({
					url: 'admin/acao.php',
					dataType: 'json',
					data: {acao: 'emailContato', nome: $('.nome').val(), assunto: $('.assunto').val(), email: email, mensagem: $('.mensagem').val()}
			});
				$('input, textarea').val('');
				alert('Email enviado com sucesso!');
		} else {
                alert('Informe um e-mail válido.');
        };
		
	});
	
});

function IsEmail(email) {
            var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (regex.test(email)) return true;
            else return false;
}

function ajustaFundoRodape() {
	page = getPageSize();
	
	var header = document.getElementById('header').clientHeight;
	
	$('.fundoHeader').css(
		{ 'height' :  header,
		  'top'    : 0
		}
	);
	
	$('.fundoHeader').width($('body').width()).css('left', -($('body').width()-945)/2);	
}

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	return {pageWidth : pageWidth, pageHeight : pageHeight, windowWidth : windowWidth, windowHeight : windowHeight}
}
