$(document).ready(function() {
   

    if($('#main_foto a').lenght!=0){
        executeLightBox($('#url_imagens'),$('#main_foto a'));
    }

    $('#galeria .link_galeria').live('click', function(e){
        e.preventDefault();
        src = $(this).attr('href');
        $('#main_foto').html('<a href="'+src+'"><img src="'+src+'"/></a>');
        executeLightBox($('#url_imagens'),$('#main_foto a'));
    });
	
	 $('#maracar_galeria .link_galeria').live('click', function(e){
        e.preventDefault();
        executeLightBox($('#url_imagens'),$('#maracar_galeria .link_galeria a').attr('href'));
    });

    if ($("#refresh_captcha").length!=0){
        $("#refresh_captcha").click(function(e){
            e.preventDefault();
            $('#img_captcha').html('');
            var link = $(this);
            $.ajax({
                url: link.attr('href'),
                success:function(response) {
                    $('#img_captcha').html(response);
                },
                error: function(response){
                    alert('A sessão expirou, por favor recarregue a página.');
                }
            });

        });
    }

    if($('#searchForm input').lenght!=0){
        var temp = $('#carro_filters_campo').val();
        $('#searchForm input').focus(function () {
            if ($(this).val()==temp)
                $(this).val('');
        });

        $('#searchForm input').blur(function () {
            if ($(this).val()=='')
                $(this).val(temp);
        });
    }
    
});

$(window).load(function() {
    $.fx.prototype.cur = function(){
        if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
            return this.elem[ this.prop ];
        }

        var r = parseFloat( jQuery.css( this.elem, this.prop ) );

        return typeof r == 'undefined' ? 0 : r;
    }

    if($('#galeria').length!=0){
        $('.showcase .loading').css('visibility','hidden');
         $('#galeria').css('display','block'); //.fadeIn(500);//
        ThumbnailScroller("galeria","horizontal",0,800,"easeOutCirc",0.5,300);
    }


    if($('#slider').length!=0){

        $('#slider').ready(function(){
            $('.slideshow .loading').css('visibility','hidden');
            $('#slider').css('display','block');
        });

        $('#slider').anythingSlider({
            //width : 800,          // Override the default CSS width
            easing: 'easeInOutExpo',
            buildArrows         : false,
            buildNavigation         : false,
            autoPlay            : false,
            /*startStopped        : true,*/
            animationTime:1500,
            delay:4000
        });


        if( $('#slider li').length>3){
            $('#slider').data('AnythingSlider').startStop(true);
            $('#right_btn').click(function(e){
                e.preventDefault();
                $('#slider').data('AnythingSlider').goForward();
                $('#slider').data('AnythingSlider').startStop(true);
            });
            $('#left_btn').click(function(e){
                e.preventDefault();
                $('#slider').data('AnythingSlider').goBack();
                $('#slider').data('AnythingSlider').startStop(true);
            });
        }
    }
    
    if($('.index_list').length!=0){
        if($('.loading').length!=0){
            $('.loading').css('display','none');
        }
        $('.index_list').css('display','block');
    }

    if($('#carro_detalhes').length!=0){
        if($('.loading').length!=0){
            $('.loading').css('display','none');
        }
        $('#carro_detalhes').css('visibility','visible');
    }
    
});

function showModeloNovo(div, link){
    $(div).html('carregando...');
    loadDiv(link, div);
    loadPopUp();
}
