var PortfolioView = BaseView.extend({
    init: function(){
        this._super();
        this.current_client = null;
        this.current_content = null;
        this.current_item_g = 0;
        
        this.gallery($('.galeria_p_list'), 8);
        this.full_image_gallery($('.galeria_g_list'), 1, 710);
        this.set_download();
        
        $('a.fullscreen').bind('click', $.proxy(this.set_fullscreen, this));
        $('.view_list a.thumb').bind('click', $.proxy(this.on_click_thumb, this));
    },
    on_click_thumb: function(e){
        e.preventDefault();
        var el = $(e.currentTarget);
        window.location.hash = el.parent().attr('id');
        window.location = el.attr('href');
    },
    full_image_gallery: function(scope, max, width){
        this.max_g = max;
	    this.w_g = width || 81;
	    this.nav_holder_g = $('.galeria_g_list .holder_slider');
        this.nav_g = $('ul', this.nav_holder_g);
        this.items_g = $('li', this.nav_g);
        this.total_items_g = $('li', this.nav_g).length;
        
        this.nav_g.width(this.w_g * this.total_items_g);
        
        if(this.total_items_g <= this.max_g){
            $('.prev, .next', this.nav_holder_g).hide();
            return;
        } else {
            $('.prev, .next', this.nav_holder_g).show();
        }
        
        $('.galeria_g_list .prev').bind('click', $.proxy(this.goto_preview_g, this));
        $('.galeria_g_list .next').bind('click', $.proxy(this.goto_next_g, this));
    },
    goto_preview_g: function(e){
        if(this.current_item_g < 1){
            return false;
        }
        this.current_item_g--;
        this.animate_g();
        e.preventDefault();
    },
    goto_next_g: function(e){
        if(this.current_item_g >= this.items_g.length - this.max_g){
            return false;
        }
        this.current_item_g++;
        this.animate_g();
        e.preventDefault();
    },
    animate_g: function(){
        var w = this.w_g;
        this.nav_g.animate({ marginLeft: -(w * this.current_item_g).toString() }, 600, 'easeInOutExpo');
        this.set_download();
    },
    set_download: function(){
        this.path = $('.galeria_g_list ul.slider li:eq('+ this.current_item_g +') img').attr('data-image');    
        $('.download > a').attr('href', this.path);
    },
    set_fullscreen: function(e){
        var arr = [];
        $('.galeria_g_list .slider img').each(function(){
            arr.push(String($(this).attr('data-image')));
        });
        $.fancybox(arr, {'titleShow': false, 'type': 'image', 'index': this.current_item_g});
        e.preventDefault();
    }
});
