$(function() {
	
	// Nav
	$('.nav li').not('.nav li ul li').prepend('<img class="nav-left" src="'+baseUrl+'/public-default/images/nav-left.png" alt="">');
	$('.nav li').not('.nav li ul li').append('<img class="nav-right" src="'+baseUrl+'/public-default/images/nav-right.png" alt="">');
	
	$('.nav li.active').find('.nav-left').attr('src', baseUrl+'/public-default/images/nav-left-hover.png');
	$('.nav li.active').find('.nav-right').attr('src', baseUrl+'/public-default/images/nav-right-hover.png');
	$('.nav li.active a').not('.nav li ul li a').css({background: 'url("'+baseUrl+'/public-default/images/nav-cont-hover.png")', color: '#c5262b'});
	
	$('.nav li').not('.active').hover(
			function() {
				$(this).find('.nav-left').attr('src', baseUrl+'/public-default/images/nav-left-hover.png');
				$(this).find('.nav-right').attr('src', baseUrl+'/public-default/images/nav-right-hover.png');
				$('a', this).not('.nav li ul li a').css({background: 'url("'+baseUrl+'/public-default/images/nav-cont-hover.png")', color: '#c5262b'});
			},
			function() {
				$(this).find('.nav-left').attr('src', baseUrl+'/public-default/images/nav-left.png');
				$(this).find('.nav-right').attr('src', baseUrl+'/public-default/images/nav-right.png');
				$('a', this).not('.nav li ul li a').css({background: 'url("'+baseUrl+'/public-default/images/nav-cont.png")', color: '#006837'});
			}
	);
	
	$('.nav li').hover(
		function() {
			$(this).find('ul').show();
		},
		function() {
			$(this).find('ul').hide();
		}
	);	
	
	$.each($('.nav li ul'), function(k, v) {		
		var w = $(this).width();
		var h = $(this).height();
		$(this).prepend('<li class="masc-submenu" style="width: '+w+'px; height: '+h+'px;"><img style="width: '+w+'px; height: '+h+'px;" src="'+baseUrl+'/public-default/images/subnav.png" alt=""></li>');
	});
	// Fim nav
	
	$('#slide').nivoSlider({
		directionNav: false
	});
	
	/*
	$('#slide ul').cycle({
		pager: '#slide-pager'
	});
	*/
	
	// Form com placeholder
	$.each($('.placeholder input[type="text"], .placeholder input[type="password"]'), function(k, v) {
		var dt = $(this).parent('dd').prev('dt');
		$(this).parent('dd').prev('dt').remove();
		
		$(this).val(dt.find('label').text());
		
		$(this).focusin(function() {
			if ($(this).val() == dt.find('label').text()) {
				$(this).val('');
			}
		});
		$(this).focusout(function() {
			if ($(this).val() == '') {
				$(this).val(dt.find('label').text());
			}
		});		
	});
	// Fim form com placeholder
	
	$('#busca-sidebar fieldset input[type="text"]').focusin(function() {
		if ($(this).val() == 'O que você procura?') {
			$(this).val('');
		}
	});
	$('#busca-sidebar fieldset input[type="text"]').focusout(function() {
		if ($(this).val() == '') {
			$(this).val('O que você procura?');
		}
	});
	
	$('#busca-sidebar').submit(function(e) {
		if ( $(this).find('input[type="text"]').val() == '' || $(this).find('input[type="text"]').val() == 'O que você procura?') {
			e.preventDefault();
			$('#dialogs').html('O campo de pesquisa não pode estar vazio!').dialog({
				title: 'Erro de validação',
				modal: true,
				resizable: false,
				draggable: false,
				buttons: {
					OK: function() {
						$(this).dialog('close');
						$('#busca-sidebar fieldset input[type="text"]').focus();
					}
				}
			});
		}
	});
	
	// Egresso login
	/*$('#form-egresso').submit(function(e) {
		e.preventDefault();
		
		var $this = $(this);
		e.preventDefault();
		$.ajax({
			url: $this.attr('action'),
			dataType: 'json',
			type: $this.attr('method'),
			data: $this.serialize(),
			
			success: function(data) {
				if (data['status'] === true) {
					$('#dialogs').text('E-mail cadastrado com sucesso!').dialog({
						title: 'Sucesso',
						modal: true,
						buttons	: {
							'OK': function() {
								$(this).dialog("close");
								//$('#sidebar-news form input[type="text"]').val('Digite aqui seu e-mail');
							}
					
						}
					});
				} else {
					$('ul.errors').remove();
					$.each(data, function(k, v) {
						$('#dialogs').append('<ul class="errors"></ul>');
						$.each(v, function(key, val) {
							$('#dialogs ul.errors').append('<li>'+val+'</li>');
						});
					});
					$('#dialogs').dialog({
						title: 'Erro',
						modal: true,
						buttons	: {
							'OK': function() {
								$(this).dialog("close");
								//$('#sidebar-news form input[type="text"]').focus();
							}
					
						}
					});
				}
			},
			error: function(xhr, er) {
				alert('Error ' + xhr.status + ' - ' + xhr.statusText);
			}
		});
		
	});*/
	//
	
	// Egresso login
	$.each($('#form-egresso .errors li'), function(k, v) {
		var valid = $(this).text();		
		var label = $(this).parents('dd').prev().find('label').text();
		$(this).remove();
		$('#dialogs').append('<h2><b>'+label+'</b></h2>'+valid+'<br /><br />').dialog({
			title: 'Erro de validação',
			modal: true,
			resizable: false,
			draggable: false,
			buttons: {
				OK: function() {
					$(this).dialog('close');
				}
			}
		});
	});
	// Fim egresso login
	
	// Newsletter
	$('#sidebar-news form').submit(function(e) {
		e.preventDefault();
		
		var $this = $(this);
		e.preventDefault();
		$.ajax({
			url: $this.attr('action'),
			dataType: 'json',
			type: $this.attr('method'),
			data: $this.serialize(),
			
			success: function(data) {
				if (data['status'] === true) {
					$('#dialogs').empty().text('E-mail cadastrado com sucesso!').dialog({
						title: 'Sucesso',
						modal: true,
						buttons	: {
							'OK': function() {
								$(this).dialog("close");
								$('#sidebar-news form input[type="text"]').val('Digite aqui seu e-mail');
							}
					
						}
					});
				} else {					
					$('#dialogs').empty();
					$('ul.errors').remove();
					$.each(data, function(k, v) {
						$('#dialogs').append('<ul class="errors"></ul>');
						$.each(v, function(key, val) {
							$('#dialogs ul.errors').append('<li>'+val+'</li>');
						});
					});
					$('#dialogs').dialog({
						title: 'Erro',
						modal: true,
						buttons	: {
							'OK': function() {
								$(this).dialog("close");
								$('#sidebar-news form input[type="text"]').focus();
							}
					
						}
					});
				}
			},
			error: function(xhr, er) {
				alert('Error ' + xhr.status + ' - ' + xhr.statusText);
			}
		});
		
	});
	// Fim newsletter
	
	
	// Depoimentos
	$('#sidebar-egressos form').submit(function(e) {
		e.preventDefault();
		
		var $this = $(this);
		e.preventDefault();
		$.ajax({
			url: $this.attr('action'),
			dataType: 'json',
			type: $this.attr('method'),
			data: $this.serialize(),
			
			success: function(data) {
				if (data['status'] === true) {
					$('#dialogs').empty().html('Depoimento cadastrado com sucesso!<br />Aguarde até liberarmos seu depoimento.').dialog({
						title: 'Sucesso',
						modal: true,
						buttons	: {
							'OK': function() {
								$(this).dialog("close");
								$('#sidebar-egressos form textarea').val('');
							}
							
						}
					});
				} else {
					$('#dialogs').empty();
					$('ul.errors').remove();
					$.each(data, function(k, v) {
						$('#dialogs').append('<ul class="errors"></ul>');
						$.each(v, function(key, val) {
							$('#dialogs ul.errors').append('<li>'+val+'</li>');
			        	});
		        	});
					$('#dialogs').dialog({
						title: 'Erro',
						modal: true,
						buttons	: {
							'OK': function() {
								$(this).dialog("close");
								$('#sidebar-egressos form textarea').focus();
							}
							
						}
					});
				}
			},
			error: function(xhr, er) {
				alert('Error ' + xhr.status + ' - ' + xhr.statusText);
			}
		});
		
	});
	// Fim newsletter
	
	// Form geral
	$('.form-geral').addClass('ui-corner-all');
	$('.form-geral dl dd input[type="text"], .form-geral dl dd input[type="password"], .form-geral dl dd textarea, .form-geral dl dd select').addClass('ui-corner-all');
	// Fim form geral
	
	// jcarousel
	$('.ev-dias, .lista-galeria ul').jcarousel();
	
	$('#brasil-mundo ul').jcarousel({
        vertical: true,
        scroll: 3,        
    });
	//Fim jcarousel
	
	$("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',theme:'facebook'});
	
	// Tables
	$('.table1 tbody tr:even, .table2 tbody tr:even, .aprovados li ul li table tbody tr:even').css('background', '#acebf2');
	$('.table1 tbody tr:odd, .table2 tbody tr:odd, .aprovados li ul li table tbody tr:odd').css('background', '#daf6f7');
	
	// Maps
	$('#mapa').projeteMap({
		lat:	'-19.75293',
		lng:	'-47.931499'
	});
	
	// Rádios
	$('#form-radio select').change(function(e) {
		if ($(this).val() != '') {
			//window.open($(this).val());
                        popUp($(this).val(),$(this).text(),'450','450','yes');
		}
	});
	
	
	// Mascaras
	$('.maskdate').mask('99/99/9999');
	$('.maskcpf').mask('999.999.999-99');
	$('.maskcep').mask('99999-999');
	
	
	
}); //Fim do ready

function popUp(pagina,nome,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(pagina,nome,settings);
}
