jQuery.fn.extend({
    tarja: function(variaveis) {

        var posLeft = $(this).position();

        if( posLeft ) {

            $(this).append("<span></span>");

            var imgHeight = $(this).children("img").height();
            var imgWidth = $(this).children("img").width();

            var pHeight,pWidth;

            if($.browser.version == 7 && $.browser.msie) {

                pHeight = imgHeight - 37;
                pWidth = imgWidth - 9;
            } else {
                
                pHeight = imgHeight - 47;
                pWidth = imgWidth - 9;
            }
            
            $(this).children("span").css({"top":posLeft.top + (imgHeight - 44), "left":posLeft.left, "width":imgWidth - 9, "opacity":0.5});
            $(this).children("p").css({"top":posLeft.top + (pHeight - 10), "left":posLeft.left, "width":pWidth});
        }
    }
});

// JavaScript Document
$(document).ready(function(){

    $("img").error(function(){$(this).hide();});

    var i = 0;
    $("#link-assine-boletim").click(function(){
        
        if(i % 2 == 0) {
               var position = $(this).offset();

               $("#form-boletim").slideDown().css({'display':'block' ,'top':(position.top - 170), 'left':(position.left - 140)});
        } else {

            $("#form-boletim").css('display','none');
        }
        i++;

        return false;
    });

    $("#editar-reserva").click(function(){

        $("form").removeClass("invisible");
        $(this).remove();
        return false;
    });


    $('#slideshowHolder').jqFancyTransitions({
        width: 350,
        height: 250,
        delay: 6000,
        stripDelay: 100,
        navigation: true,
        links: true
    });


    $('#news_nome').val('Nome...').css('fontColor','#cccccc');
    $('#news_nome').focus(function(){if($(this).val() == 'Nome...') {$(this).val('');}});
    $('#news_nome').blur(function(){if($(this).val() == '') {$(this).val('Nome...').css('fontColor','#cccccc');}});

    $('#news_email').val('E-mail...').css('fontColor','#cccccc');
    $('#news_email').focus(function(){if($(this).val() == 'E-mail...') {$(this).val('');}});
    $('#news_email').blur(function(){if($(this).val() == '') {$(this).val('E-mail...').css('fontColor','#cccccc');}});

    //$("#tag-cloud").tagCloud({"speed":10000});

    $(".caroussel-galeria").carousel({dispItems: 5});


    $(".ampliar-imagem").fancybox();

    $(".informacao-cidade").fancybox({'type': 'iframe'});

    $('#photos').galleryView({
            panel_width: 604,
            panel_height: 220,
            frame_width: 40,
            frame_height: 40,
            overlay_height: 50,
            overlay_font_size: '0.8em',
            overlay_text_color: 'white',
            caption_text_color: '#222',
            background_color: 'transparent',            
            easing: 'easeInOutQuad',
            nav_theme: 'grey',
            border: 'none',
            pause_on_hover: true

    });    

    $("select[name=filtro]").change(function(){document.eventos.submit();});
    $("select[name=combo_cia]").change(function(){document.filtro_cia.submit();});
    $(".pages a").click(function(){document.eventos.submit();});
    $("#votar-enquete").click(function(){document.enquete.submit();});
    
    $("a.ampliar-imagem").fancybox();

    $('#container-2').tabs({fxShow: {height: 'show', opacity: 'show'}});

    $(".fone").mask("(99) 9999-9999");
    
    

     $('#ctt_como_conheceu').change(function(){

        if(($(this).val() == 'Outro')) {
            $('p.como_conheceu').css('display','block');

            if($('body').find('#outro').size() == 0) {

                var html = '<label for="outro">Favor especificar</label><br /><input type="text" name="outro" id="outro" class="char" value="" />';

                $(html).appendTo('p.como_conheceu');
            }

        } else {
            $('p.como_conheceu').css('display','none');

        }

    });
	 
    $(".link-to-content-expand").click(function(){

       var indice = $(".link-to-content-expand").index(this);

       $(".content-expand").eq(indice).slideToggle("slow");

       return false;
    });

    $("dt a").click(function(){

       var indice = $("dt a").index(this);

       $("dd").eq(indice).slideToggle();

       return false;
    });

    $(".data").change(function(){document.data_post.submit();return false;});

    $("select[name=cidade_url]").change(function(){document.form_cidade_url.submit();return false;});

    //estrutura o caption da imagem
    var image_width = $(".image-in-content img").width();
    $(".image-in-content").css({"marginRight":"10px", "width": image_width});
    
    
    $("#contato-anuncie").validate({
            rules: {
                    ancie_email: {
                            required: true,
                            email: true
                    },
                    ancie_telefone: {
                        required: true,
                        number: false
                    },
                    code: {
                        required: true,
                        number: false
                    },
                    ancie_nome: "required",
                    ancie_empresa: "required"
            }
    });

    $("form[name=end_reserva]").validate({
            rules: {
                    email: {
                            required: true,
                            email: true
                    },
                    placa: {
                      require: true,
                      number: false
                    },
                    telefone: {
                      require: true,
                      number: false
                    },
                    nome: "required"
            }
    });

    $("#contato").validate({
            rules: {
                    ctt_email: {
                            required: true,
                            email: true
                    },
                    ctt_telefone: {
                        required: true,
                        number: false
                    },
                    ctt_celular: {
                        required: false,
                        number: false
                    },
                    code: {
                        required: true,
                        number: false
                    },
                    ctt_nome: "required",
                    ctt_cidade: "required",
                    ctt_estado: "required",
                    ctt_como_conheceu: "required",
                    ctt_mensagem: "required",
                    outro: "required"
            }
    });


});

jQuery(window).load(function(){

   $(".programe-se-destaque").tarja();

   $(".dicas-destaque").tarja();
   
});
