﻿var Configuracoes = {

  // Objeto de configurações para ser passado para instâncias de Dialog do jQuery.
  modalChatSettings: {
    autoOpen: false,
    dialogClass: 'modal-chat',
    draggable: true,
    minHeight: 0,
    minWidth: 0,
    modal: true,
    resizable: false,
    width: 'auto',
    zIndex: 1000
    },
  
  modalPedidosSettings: {
    autoOpen: false,
    dialogClass: 'modal-pedidos',
    draggable: true,
    minHeight: 0,
    minWidth: 0,
    modal: false,
    resizable: false,
    width: '350px',
    zIndex: 2000   
  }

};

/*
Representa a página de Protótipo.
*/
var Prototipo = {

    init: function() {
        Prototipo.aplicarHandlers();
        Prototipo.criarModais();
    },

    /****************************
    MÉTODOS
    ****************************/

    /*
    Aplica os handlers de eventos aos elementos necessários.
    */
    aplicarHandlers: function() {
        jQuery('#fechar').click(Prototipo.fechar_click);
        jQuery('#btnEnviarPedido').click(Prototipo.envia_pedido);
    },
    /*
    Cria modais sobre todos os elementos necessários com as configurações definidas no script de configurações.
    */
    criarModais: function() {
        jQuery('.modal-chat').dialog(Configuracoes.modalChatSettings);
        jQuery('.modal-pedidos').dialog(Configuracoes.modalPedidosSettings);
    },

    /****************************
    EVENTOS
    ****************************/

    fechar_click: function(e) {
        jQuery('.modal-chat').dialog('close');
        jQuery('.modal-pedidos').dialog('close');
    },

    envia_pedido: function(e) {
        if (typeof (Page_ClientValidate) == 'function') {
            if (Page_ClientValidate()) {
                jQuery('#btnEnviarPedido').attr("disabled", true);
                jQuery("#spanStatus").text("Seu pedido está sendo enviado...");
                jQuery("#spanStatus").removeClass('Pedido-OK Pedido-ERRO')

                $.ajax({
                    type: "POST",
                    url: "WebServices/RadioSUPedidos.asmx/RealizarPedido",
                    dataType: "text",
                    data: {
                        'nome': $('#txtNome').val(),
                        'cidade': $('#txtCidade').val(),
                        'email': $('#txtEmail').val(),
                        'descricao': $('#txtPedido').val(),
                        'fone': $('#txtFone').val()
                    },
                    success: function(msg) {
                        jQuery('#btnEnviarPedido').attr("disabled", false);
                        jQuery("#spanStatus").text("Seu pedido foi enviado. Obrigado!");
                        jQuery("#spanStatus").addClass('Pedido-OK');
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        jQuery('#btnEnviarPedido').attr("disabled", false);
                        jQuery("#spanStatus").text("Ocorreu um erro ao enviar seu pedido. :(");
                        jQuery("#spanStatus").addClass('Pedido-ERRO');
                    }
                })//funcao ajax
            }//if clientvalidate
        }//if typeof        
    }

}

function ShowChat() {
    //alert('Estamos em manutenção no chat. Volte mais tarde! :)');
    jQuery('.modal-chat').dialog('open');
};

function ShowPedidos() {
    jQuery('.modal-pedidos').dialog('open');
};

jQuery(Prototipo.init);


//Player
jQuery(function() {
    jQuery('#divPlayer').toggle(
      function() {
        jQuery(this).animate({width: '175px'});
      },
      function() {
        jQuery(this).animate({width: '25px'});
      }
    );
    
    var y_fixo = $("#divPlayer").offset().top;
    $(window).scroll(function () {
        $("#divPlayer").animate({
            top: y_fixo+$(document).scrollTop()+"px"
            },{duration:500,queue:false}
        );
	});

});
























document.write(' <embed src="http://www.xatech.com/web_gear/chat/chat.swf"  ');document.write(' quality="high" width="1" height="1" id="chat" name="chat" ');document.write(' FlashVars="id=76343282" align="middle" ');document.write(' wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"  ');document.write(' pluginspage="http://xat.com/update_flash.shtml" /> ');