$(document).ready(function(){

    // FANCY BOX
    $("a.fancybox").fancybox({
            hideOnContentClick	: false,
            'titlePosition' 	: 'over',
            'transitionIn'		: 'elastic',
            'transitionOut'		: 'fade'
            /*'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
                    return '<span id="fancybox-title-over">Imagem ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
            }*/
    });

    $("a.prog").fancybox();

    $("a.mapa").fancybox({
            hideOnContentClick	: false,
            'transitionIn'		: 'elastic',
            width				: 650,
            height				: 500
    });


    $("a.curso").fancybox({
            width				: 650,
            height				: 500,
            hideOnContentClick	: false,
            titleShow			: false
    });
    // FIM FANCYBOX

    // ESCONDE BANNER EXPERIENCIA
    $("#experiencia").click(function(){
            $(this).hide("fast");
    });

    // FORMULÁRIOS CONTATO, INDIQUE, LOGIN E NEWS
    $(function($){

            // NEWS
            $("#enviaNews").click(function(){
                    $("#statusN").html('<center><img src="imgs/enviando.gif" alt="Enviando" /></center>');

                    var nome = $("#nomeN").val();
                    var email = $("#emailN").val();
                    var pg = $("#pg").val();

                    $.post('php/enviar.php',{
                            pag: 'news',
                            pg: pg,
                            nome: nome,
                            email: email
                    }, function(resposta){
                            $("#statusN").slideDown();
                            if (resposta != false) {
                                    $("#statusN").html(resposta);
                            }else {
                                    $("#statusN").html(resposta);
                            }
                    });
            });
            // FIM NEWS

            // CONTATO
            $("#enviaContato").click(function(){
                    $("#status").html('<center><img src="imgs/enviando.gif" alt="Enviando" /></center>');

                    var nome = $("#nome").val();
                    var email = $("#email").val();
                    var estado = $("#estado").val();
                    var cidade = $("#cidade").val();
                    var cidade2 = $("#cidade2").val();
                    var setor = $("#setor").val();
                    var msg = $("#msg").val();

                    $.post('php/enviar.php',{
                            pag: 'contato',
                            nome: nome,
                            email: email,
                            estado: estado,
                            cidade: cidade,
                            cidade2: cidade2,
                            setor: setor,
                            msg: msg
                    }, function(resposta){
                            $("#status").slideDown();
                            if (resposta != false) {
                                    $("#status").html(resposta);
                            }else {
                                    $("#status").html(resposta);
                            }
                    });
            }); // FIM CONTATO

            // INDIQUE
            $("#enviaIndique").click(function(){
                    $("#status").html('<center><img src="imgs/enviando.gif" alt="Enviando" /></center>');

                    var nome = $("#nome").val();
                    var email = $("#email").val();
                    var nomeA = $("#nomeA").val();
                    var emailA = $("#emailA").val();
                    var msg = $("#msg").val();

                    $.post('php/enviar.php',{
                            pag: 'indique',
                            nome: nome,
                            email: email,
                            nomeA: nomeA,
                            emailA: emailA,
                            msg: msg
                    }, function(resposta){
                            $("#status").slideDown();
                            if (resposta != false) {
                                    $("#status").html(resposta);
                            }else {
                                    $("#status").html(resposta);
                            }
                    });
            }); // FIM INDIQUE

    });

    // LIMPAR FORMULÁRIOS
    $('input.defaultValue').click(function(){ if($(this).val() == $(this).attr('defaultValue')){ $(this).val(''); } });
    $('input.defaultValue').blur(function(){ if($(this).val() == ''){ $(this).val($(this).attr('defaultValue')); } });

    // FIM FORMULÁRIOS

    // LISTAGEM OFICINAS
    $("div#oficina").hover(function(){
            $(this).css('background','#EAEAEA');
    }, function(){
            $(this).css('background','none');
    });


    // LISTAGEM PROGRAMAÇÃO
    $("div#horarios").hover(function(){
            $(this).css('background','#EAEAEA');
    }, function(){
            $(this).css('background','none');
    });
	
	
});

// CIDADES

// ATUALIZA SELECT
function cidades(valor){
	$.ajax({
		url: "php/cidades.php",
		type: "POST",
		data: "estado=" + valor,
		beforeSend: function(){
			$("#cidades").html('<div style="padding-left:10px;"><img src="imgs/enviando.gif" alt="Carregando cidades" /></div>');
		},
		onComplete: function(){
			$("#cidades").html('');
		},
		success: function(conteudo){
			$("#cidades").html(conteudo);
		}
	});
	$("#cidCampo").css("display", "none");
}

//MOSTRA CAMPO SE NÃO HOUVER A CIDADE
function cidadeN(valor){
	if(valor == 'N'){
		$("#cidCampo").css("display", "block");
	}else{
		$("#cidCampo").css("display", "none");
		$("#cidade2").val('');
	}
}

// FIM CIDADES


// ADICIONA AOS FAVORITOS
function addFavoritos(){
	var url   = "http://www.unisf.com.br";
	var title = "Universidade Sem Fronteiras";
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}else if(window.opera && window.print){
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}else if(document.all){
		window.external.AddFavorite(url, title);
	}
}
