//////////////////// EXIBE / ESCONDE DIV ////////////////////
function displayDiv(div) {
	$("div#"+div).animate({"height": "toggle"}, { duration: 200 });
}

//////////////////// GOPAGE ////////////////////
function goPage(pag, div){
	$.ajax({
		type: "GET",
		url: pag,
		beforeSend: function() {
			$("#"+div).html('Carregando...');
		},
		success: function(texto){
			$("#"+div).html(texto);
		},
		error: function(txt) {
			$("#"+div).html('Erro');
		}
	});
}

//////////////////// LIMPA FORM ////////////////////
$.fn.clearForm = function() {
	// iterate each matching form
	return this.each(function() {
	// iterate the elements within the form
		$(':input', this).each(function() {
			var type = this.type, tag = this.tagName.toLowerCase();
			if (type == 'text' || type == 'password' || tag == 'textarea')
				this.value = '';
			else if (type == 'checkbox' || type == 'radio')
				this.checked = false;
			else if (tag == 'select')
				this.selectedIndex = -1;
		});
	});
};

$(document).ready(function() {
	//////////////////// FANCY ////////////////////
	$("a.imagem").fancybox();
	
	$("a[rel=foto_galeria]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Imagem ' +  (currentIndex + 1) + ' de ' + currentArray.length + ' ' + title + '<\/span>';
		}
	});
	
	//////////////////// ENVIA CONTATO ////////////////////
	$("form#contato").submit(function() {
		var fnome = $('#fnome').attr('value');
		var fempresa = $('#fempresa').attr('value');
		var ftelefone = $('#ftelefone').attr('value');
		var femail = $('#femail').attr('value');
		var fassunto = $('#fassunto').attr('value');
		var fmsgm = $('#fmensagem').attr('value');
		$.ajax({
			type: "POST",
			url: "submit/contato.php",
			data: "fnome="+fnome+"&fempresa="+fempresa+"&ftelefone="+ftelefone+"&femail="+femail+"&fassunto="+fassunto+"&fmsgm="+fmsgm,
			beforeSend: function() {
				$('div#retorno_contato').html('<img src="imgs/layout/ajax-loader.gif" \/>');
			},
			error: function(txt) {
				$('div#retorno_contato').html('Erro ao enviar');
			},
			success: function(data){
				$('div#retorno_contato').html(data);
			}
		});
		return false;
	});
});

