/**
 * Author: Sereno Mendes (http://www.serenomendes.com/)
 * e-mail: sereno@serenomendes.com
 * description: Arquivo de funções especificos para o site www.fabasa.com.br
 */
$(document).ready(
    function(){
        // try{
        $('div.post').corner('20px');
        $("a[rel='modal-hook']").colorbox({
            opacity:0.5,
            width:"50%",
            inline:true,
            arrowKey: false,
            previous: "anterior",
            next: "proximo",
            maxHeight: "350px",
            initialWidth: "500px"
        });

        $("area").colorbox({
            opacity:0.5,
            width:"50%",
            inline:true,
            arrowKey: false,
            previous: "anterior",
            next: "proximo",
            initialWidth: "500px"
        });

        $(".download").click(function(){
            return false
        });
        $(".download").click(function(){
            download_resource( $(this).attr('href') );
        });
        // }catch(e){
        //     alert(e);
        //  }
        // pagina de inscrição na newsletter
        $.ajax(
        {
            url: '/fabasa/site/index.php/newsletter',
            success: function (data){
                try{
                    _newsform           = $('#alo_easymail_widget_form', $(data)).clone();
                    // _newsform           = $('#alo_easymail_page', $(data)).html();
                    // _newsform           = ('#alo_easymail_widget_form', _newsform);
                    _new_newsform       = document.createElement('form');
                    _new_newsform       = $(_new_newsform);
                    _new_newsform.attr('name', _newsform.attr('name'));
                    _new_newsform.attr('id',_newsform.attr('id'));
                    _new_newsform.submit( function(){
                        alo_em_public_form();
                        return false;
                    });
                    _news_name_field = $('#opt_name', _newsform).clone(true);
                    _new_newsform.append( _news_name_field );
                    //$( '#newswrapper' ).html( _new_newsform );
                    //$('#newswrapper').html( _new_newsform );
                    //$('#newswrapper').html( _newsform );
                }catch(e){
                    alert(e);
                }
            }//success
        }
        )//ajax

        $(".newstrigger a").colorbox({
            opacity:0.5,
            width:300,
            height:200,
            inline:true,
            href:"#newswrapper",
            arrowKey: false,
            previous: "anterior",
            next: "proximo",
            maxHeight: "350px",
            initialWidth: "500px"
        });

        _strnews_default_text = 'Digite seu e-mail e assine nossa news';

        $('#opt_name').blur(function(){
            _f = $(this);

            if( _f.val() == '' )
                _f.val(_strnews_default_text);
        });

        $('#opt_name').focus(function(){
            _f = $(this);

            if( _f.val() == _strnews_default_text )
                _f.val('');
            else if( _f.val() == '')
                _f.val(_strnews_default_text);

        });
    }
    );

/**
 * Função que disponibiliza um recurso para download.
 *
 * Manda uma requisição ao arquivo download.php responsável por disponibilizar o recurso para download
 * alterando o cabeçalho da resposta HTTP de acordo com a extensão do recurso solicitado.
 *
 * @param string Nome do recurso que deve ser baixado.
 */
function download_resource(r) {
    window.location.href=host+'/wp-content/themes/simplixity/download.php?file='+r;
}

