$(document).ready(function(){
	
	/* PLACEHOLDER PARA IE's */
	if($.browser.msie){
		$('input[type=text], input[type=password]').each(function(){
			
			var $value = $(this).attr('value');
			var $defaultValue = $(this).attr('placeholder');
			var $defaultColor = $(this).css('color');
			var $defaultType = $(this).attr('type');
			var $color = "#A9A9A9";
			
			if($defaultValue){
				$(this).css('color', $color);
				$(this).val($defaultValue).focus(function(){
					if($(this).val() == $defaultValue){
						$(this).val('');
						$(this).css('color', $defaultColor);
					}
				}).blur(function(){
					if($(this).val() == ""){
						$(this).val($defaultValue);
						$(this).css('color', $color);
						$(this).attr('type', $defaultType);
					};
				});
			};
			
		});
	};
	
	/* LINK NO H1, TOPO */
	$('h1#logo').click(function(){ location.href = "http://www.fme.org.br/"; }).attr('title', 'Voltar para a página inicial');
	
	/* LINK PARA FANCY */
	$('.fancy_video').fancybox({
		'padding'		: 5,
		'autoScale'		: true,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		overlayColor	: '#FFF',
		type			: 'swf',
		'swf'			: {
			 'wmode'			: 'transparent',
			 'allowfullscreen'	: 'true'
		}
	});
	$('.fancy').fancybox({
		'padding'		: 5,
		'autoScale'		: true,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		overlayColor	: '#FFF'
	});
	$('.galeria .overlay').mouseover(function(){
		$(this).animate({'opacity':0}, {queue: false});
	}).mouseout(function(){
		$(this).animate({'opacity':0.5}, {queue: false});
	})
	
	/* FORMULÁRIO AJAX */
	$('form#ajax').submit(function(e){								  
	var url = $(this).attr('action');
	var serializeDados = $(this).serialize();
	e.preventDefault();
	$.ajax({
			url: url, 
			dataType: 'html',
			type: 'POST',
			timeout: 50000,
			data: serializeDados,
			beforeSend: function(){
				$.fancybox.showActivity();
			},
			complete: function() {
				$.fancybox.hideActivity();
			},
			success: function(data) {
				$('head').append(data);
			},
			error: function(xhr,er) {
				Alert('Algum erro aconteceu, tente novamente mais tarde.');
			}		
		});
	});
	
	$('#fonte_aumentar').live('click', function(){
		$('div#conteudo').each(function(){
			var $tamFonte = $(this).css('font-size');
			if(parseInt($tamFonte.replace("px","")) < 18){
				$(this).css('font-size', parseInt($tamFonte.replace("px","")) + 1);
			}
		})
	});
	
	$('#fonte_diminuir').live('click', function(){
		$('div#conteudo').each(function(){
			var $tamFonte = $(this).css('font-size');
			if(parseInt($tamFonte.replace("px","")) > 9){
				$(this).css('font-size', parseInt($tamFonte.replace("px","")) - 1);
			}
		})
	});
	
	if($('#telefone')) $('#telefone').mask('(99) 9999-9999');
	
	$('#sobre_a_fundacao, .subsobre_a_fundacao').mouseenter(function(){
		$('.subsobre_a_fundacao').stop(true, true).fadeIn();
	}).mouseleave(function(){
		$('.subsobre_a_fundacao').stop(true, true).fadeOut();
	})
	
});

//FUNÇÕES
function Alert(msg){
	$.fancybox(
		'<p id="modal">' + msg + '</p>',
		{
        	'autoDimensions'	: false,
			'width'         	: 350,
			'height'        	: 'auto',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'overlayColor'		: '#FFFFFF'
		}
	);
}

function openCenteredWindow(url) {
    var width = 400;
    var height = 350;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}
