(function($){
    var methods = {
        init: function(options) {       
            var settings = {
            'interval':'6000'
            };
            return this.each(function(){              
                var $this = $(this), data = $this.data('slider');
                if ( ! data ) {
                    if (options) {
                        $.extend(settings,options);
                    }
                    $this.data('slider',settings);
                }
                var largura = $(".window",$this).width();
                var num_imgs = $(".image_reel a",$this).size();
                $(".paging",$this).html('');
                for (i=1;i<=num_imgs;i++) {
                    $(".paging",$this).append("<a href='javascript:void(0)' rel='"+i+"'>"+i+"</a>");
                }
                $('img',$this).css({'width':largura});
                $(".paging",$this).show();
                $(".paging a:first",$this).addClass('active');
                $(".image_reel a",$this).css({'position':'absolute','z-index':'0'}).show();
                $(".image_reel a:first",$this).addClass('active').css({'z-index':'2'});
                var intervalo = window.setInterval(function(){
                    $($this).slider('moveNext');
                }, settings.interval);
                $('.paging a').each(function(i,v){
                    $(this).click(function(){
                        window.clearInterval(intervalo);
                        $active = $($('.paging a',$this)[i]);
                        $img_active = $($('.image_reel a',$this)[i]);
                        if ($active.length===0) {
                            $active = $('.paging a:first',$this);
                        }
                        if ($img_active.length===0) {
                            $img_active = $('.image_reel a:first',$this);
                        }
                        $(".paging a",$this).removeClass('active');
                        $active.addClass('active');
                        $img_active.css({'z-index':'1'}).show();
                        $('.image_reel a.active',$this).fadeOut('slow',function(){
                            $(".image_reel a",$this).removeClass('active');
                            $img_active.addClass('active').css({'z-index':'2'});
                        });
                        intervalo = window.setInterval(function(){
                                $($this).slider('moveNext');
                            }, settings.interval);
                    });
                });

            });           
        },
        moveNext: function() {
            return this.each(function(){
                var $this = $(this), data = $this.data('slider');
                $active = $('.paging a.active',$this).next();
                $img_active = $('.image_reel a.active',$this).next();
                if ($active.length===0) {
                    $active = $('.paging a:first',$this);
                }
                if ($img_active.length===0) {
                    $img_active = $('.image_reel a:first',$this);
                }
                $(".paging a",$this).removeClass('active');
                $active.addClass('active');
                $img_active.css({'z-index':'1'}).show();
                $('.image_reel a.active',$this).fadeOut('slow',function(){
                    $(".image_reel a",$this).removeClass('active');
                    $img_active.addClass('active').css({'z-index':'2'});
                });
            });
        }
    };
    $.fn.slider = function( method ){
         if ( methods[method] ) {            
          return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {          
          return methods.init.apply( this, arguments );
        } else {
          $.error( 'Method ' +  method + ' does not exist on jQuery.slider' );
        }
    }
})(jQuery);



    $(function(){
        $('.main_view').slider({'interval':6000});
        //DD_belatedPNG.fix('.text');
    });
