function excluir(url,id){
	if(id){
		if(confirm("Tem certeza que deseja excluir esse item?")){
			window.open(url+"?opcao=excluir&id="+id,"_self");
		}
	}
}

$().ajaxStop($.unblockUI);

$(document).ready(function(){
	var ciclo = {
		fx: 'fade',
		timeout: 15000
	};
	
	var ciclo2 = {
		fx: 'fade',
		timeout: 10000
	};
	
	$(".link_hover").hover(
		function(){
			$('body').css('cursor', 'pointer');
		},
		function(){
			$('body').css('cursor', 'default'); 
		}
	);
	
	if($("#galeria_span").html() == 'galeria'){
		galeria();
	}
	
	$(".telefone").mask("(99) 9999-9999");
	$(".data_form").mask("99/99/9999");
	$(".cep").mask("99.999-999");
	
	$("#cycle_image").cycle(ciclo);
	$("#cycle_title").cycle(ciclo);
	$("#cycle_link").cycle(ciclo);
	
	$("#cycle_trabalhos_image").cycle(ciclo2);
	$("#cycle_trabalhos_legenda").cycle(ciclo2);
	
	$('textarea.tinymce').tinymce({
		// Location of TinyMCE script
		script_url : 'includes/js/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "paste,xhtmlxtras",
		//plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		//theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		//theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "none",
		theme_advanced_resizing : false,

		// Example content CSS (should be your site CSS)
		content_css : "includes/css/textos.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		},
		
		// Language
		
		language : "pt"
	});
	
	$("#form_pesquisar").submit(function() {
		if(!$("#pesquisa").val()){							alert("É obrigatório definir a pesquisa!");	return false;}
	});

	$("#formulario").submit(function() {
		if(!$("#nome").val()){							alert("É obrigatório preencher o Nome!");	return false;}
		if(!$("#email").val()){							alert("É obrigatório preencher o e-Mail!");	return false;}
		//if(!$("#telefone").val()){						alert("É obrigatório preencher o Telefone!");	return false;}
		if(!$("#mensagem").val()){						alert("É obrigatório preencher a Mensagem!");	return false;}
		if(!checkMail($("#email").val())){				alert("E-mail inválido!");	return false;}
		
	});
	
	$("#formulario2").submit(function() {
		if(!$("#nome").val()){							alert("É obrigatório preencher o Nome!");	return false;}
		if(!$("#data_nascimento").val()){				alert("É obrigatório preencher a Data de Nascimento!");	return false;}
		if(!$(".sexo:checked").val()){					alert("É obrigatório preencher o Sexo!");	return false;}
		if(!$("#email").val()){							alert("É obrigatório preencher o e-Mail!");	return false;}
		if(!$("#endereco").val()){						alert("É obrigatório preencher o Endereço Completo!");	return false;}
		if(!$("#cep").val()){							alert("É obrigatório preencher o CEP!");	return false;}
		if(!$("#bairro").val()){						alert("É obrigatório preencher o Bairro!");	return false;}
		if(!$("#cidade").val()){						alert("É obrigatório preencher a Cidade!");	return false;}
		if(!$("#telefone").val()){						alert("É obrigatório preencher o Telefone Principal!");	return false;}
		if(!checkMail($("#email").val())){				alert("E-mail inválido!");	return false;}
		
	});
	
	$("#newsletter").submit(function() {
		if(!$("#news_nome").val()){						alert("É obrigatório preencher o Nome!");	return false;}
		if(!$("#news_email").val()){					alert("É obrigatório preencher o e-Mail!");	return false;}
		if(!checkMail($("#news_email").val())){			alert("E-mail inválido!");	return false;}
		
	});
	
	$("#pesquisar_ir").click(function() {
		$("#form_pesquisar").submit();
	});
	
	$("#bot_news_1").click(function() {
		$("#newsletter").submit();
	});
	
	$("#bot_news_2").click(function() {
		$("#newsletter").submit();
	});
	
	function url_name(){
		var url_aux = location.pathname;
		var url_parts;
		
		url_parts = url_aux.split('/');
		
		return url_parts[url_parts.length-1];
	}

	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 galeria(){
		// We only want these styles applied when javascript is enabled
		$('div.navigation').css({'width' : '1000px', 'clear' : 'left', 'position' : 'relative', 'top' : '-60px'});
		$('div.content').css('display', 'block');

		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		$('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#thumbs').galleriffic({
			delay:                     10000,
			numThumbs:                 6,
			preloadAhead:              10,
			enableTopPager:            false,
			enableBottomPager:         true,
			maxPagesToShow:            7,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          false,
			renderNavControls:         false,
			playLinkText:              'Começar Slideshow',
			pauseLinkText:             'Pausar Slideshow',
			prevLinkText:              '&lsaquo; Previous Photo',
			nextLinkText:              'Next Photo &rsaquo;',
			nextPageLinkText:          'Próxima &rsaquo;',
			prevPageLinkText:          '&lsaquo; Anterior',
			enableHistory:             false,
			autoStart:                 true,
			syncTransitions:           true,
			defaultTransitionDuration: 400,
			onSlideChange:             function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});
	}

});