$(document).ready(function() {
    
		Swap.init();
		
		forms.newsletter();
		forms.contato();
			
		$(".redesSociais").corner("3px");
		
});

Swap = {
	init: function()
	{
		swapValues = [];	
    $(".swap").each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });
	}
}

var forms = {
	newsletter:function(){
		
	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;
		}
	}
		$("#form-newsletter").submit(function(event) {
	    event.preventDefault(); 
        
		/* get some values from elements on the page: */
		var $form = $( this ),
			email = $form.find( 'input[name="emailNewsletter"]' ).val(),
			url = $form.attr( 'action' );

		/* Send the data using post and put the results in a div */
		if(checkMail(email)){
			$.post(url, { email: email },
				   //retorno
			  function(data) {
				  //var content = $( data ).find( '#content' );
				 // $( "#result" ).empty().append( content );
				  $("#emailNewsletter").val("Informe seu e-mail");
				  showNotification({
                      message: "E-mail cadastrado com sucesso!",
                      type: "success"
                  });
			  }
			);
		}//fim if
		else{
			showNotification({
            message: "Insira um e-mail válido!",
            type: "error"
        });	
		}
	  });
		
	},
	
	contato:function(){
	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;
		}
	}
	
		$("#form-contato").submit(function(event) {
	    event.preventDefault(); 
        
		/* get some values from elements on the page: */
		var $form = $( this ),
			nome = $form.find( 'input[name="nome"]' ).val(),
			email = $form.find( 'input[name="email"]' ).val(),
			telefone = $form.find( 'input[name="telefone"]' ).val(),
			mensagem = $form.find( 'textarea[name="mensagem"]' ).val(),
			url = $form.attr( 'action' );
			
		if(checkMail(email)){
			
		if(nome != '' && email != '' && mensagem != ''){
		/* Send the data using post and put the results in a div */
		$.post(url, { nome: nome, email: email, telefone: telefone, mensagem: mensagem },
			   //retorno
		  function(data) {
			  //var content = $( data ).find( '#content' );
			  //$( "#result" ).empty().append( content );
			  $.history.load("home");
			  //Alerts.write("Contato","Mensagem sucesso!");
			  showNotification({
                  message: "E-mail enviado com sucesso!",
                  type: "success"
              });
		  }
		);
		}else{
			showNotification({
                message: "Preencha corretamente todos os campos!",
                type: "error"
            });
		}
		}else{
			showNotification({
				message: "Insira um e-mail válido!",
				type: "error"
			});
		}
	  });	

	}
	
}

function openYouTube(opener) {
	var returnValue;
	
	// Safari Mobile doesn't have Flash, so we just let the device use the built-in 
	// YouTube viewer.
	if (/(iPhone|iPod|iPad)/.test(navigator.userAgent)) returnValue = true;

	else returnValue = hs.htmlExpand(opener, { 
		objectType: 'iframe', 
		objectWidth: 480, 
		objectHeight: 385, 
		transitions: ['fade'],
		width: 480, 
		outlineType: 'rounded-white',
		outlineWhileAnimating: true,
		allowSizeReduction: false,
		// always use this with flash, else the movie will be stopped on close:
		preserveContent: false,
		wrapperClassName: 'draggable-header no-footer',
		swfOptions: { 
			params: { 
				allowfullscreen: 'true' 
			}
		}, 
		maincontentText: 'You need to upgrade your Flash player' 
	});
	
	return returnValue;
}  


