(function($) {
	var defaults = {};
	var options;
    var duration = 300;
    var viewCount = 9;
    var steps = [];
    var count = 0;
    var counts = [];
	var methods = {
	    init:function($element) {
	        steps[count] = 0;
            counts[count] = $element.find('li').length;
            $element.find('ul').css({width: counts[count] * 70});
            $element.attr('data-count', count);
            
            $element.find('.b-smallgallery-prev, .b-smallgallery-mask').hide();
            
            if(counts[count] <= viewCount) {
                $element.find('.b-smallgallery-next, .b-smallgallery-mask2').hide();
                var offset = 300 - (counts[count] * 70) / 2;
                if($element.parents('.short').length == 0)
                    $element.find('.b-smallgallery-wrap ul').css({paddingLeft: offset});
            }
            
            $element.find('.b-smallgallery-next').click(function(){
                steps[$element.attr('data-count')]++;
                methods.move($element, steps[$element.attr('data-count')]);
                return false;
            });

            $element.find('.b-smallgallery-prev').click(function(){
                steps[$element.attr('data-count')]--;
                methods.move($element, steps[$element.attr('data-count')]);
                
                return false;
            });
            
            count++;

	    },
	    move: function($element, step) {
	       var offset = 70 * step * -1;
	       $element.find('.b-smallgallery-wrap ul').stop(true, true).animate({marginLeft: offset}, duration);   
	       	       
	       if(viewCount + step == counts[$element.attr('data-count')]) {
	           $element.find('.b-smallgallery-next, .b-smallgallery-mask2').hide();
	       } else {
	           $element.find('.b-smallgallery-next, .b-smallgallery-mask2').show();
	       }
	       
   	       if(step  == 0) {
	           $element.find('.b-smallgallery-prev, .b-smallgallery-mask').hide();
	       } else {
	           $element.find('.b-smallgallery-prev, .b-smallgallery-mask').show();
	       }

	    }
	};

	$.fn.hGallery = function(params) {
        //methods.init.apply( this, arguments );
        this.each(function() {
            methods.init( $(this) );
        });
        return this;
	};
})(jQuery);


(function($) {
	var defaults = {};
	var options;
    var duration = 300;
    var viewCount = 7;
    var steps = [];
    var count = 0;
    var counts = [];
	var methods = {
	    init:function($element) {
	        steps[count] = 0;
            counts[count] = $element.find('.b-smallgallery-items li').length;
            $element.find('.b-smallgallery-items').css({height: counts[count] * 60});
            $element.attr('data-count', count);
            
            $element.find('.b-smallgallery-prev, .b-smallgallery-mask').hide();
           
            //console.info( $element.find('.b-smallgallery-wrap li').length, counts );
            //console.info(viewCount, counts[$element.attr('data-count')]);   
             
            if(counts[count] <= viewCount) {
                $element.find('.b-smallgallery-next, .b-smallgallery-mask2').hide();
                var offset = 190 - (counts[count] * 50) / 2;
                $element.find('.b-smallgallery-items').css({paddingTop: offset});
            }
            
            $element.find('.b-smallgallery-next').click(function(){
                steps[$element.attr('data-count')]++;
                methods.move($element, steps[$element.attr('data-count')]);
                return false;
            });

            $element.find('.b-smallgallery-prev').click(function(){
                steps[$element.attr('data-count')]--;
                methods.move($element, steps[$element.attr('data-count')]);
                
                return false;
            });
            
            $element.find('.b-smallgallery-items li a').click(function(){
                if( $(this).parent().hasClass('active') ) return false;

                $activeElement = $(this).parent('li'); 
                
                steps[$element.attr('data-count')] =  $activeElement.index();
                methods.move($element, steps[$element.attr('data-count')]);

/*
                $activeElement.addClass('active');
                
                $element.find('.b-verticalgallery-items li').fadeOut('slow');
                $element.find('.b-verticalgallery-items li[data-id="' + $activeElement.attr('data-id') + '"]').fadeIn('slow');
*/
                
                return false;
            });
            
            count++;


	    },
	    move: function($element, step) {
	       var offset = 50 * step * -1;
	       $activeElement = $element.find('.b-verticalgallery-list ul li:eq(' + step + ')'); 
           
           if( $activeElement.hasClass('active') ) return false;

	       $element.find('.b-verticalgallery-list ul li.active').removeClass('active');
	       $activeElement.addClass('active');

	       $element.find('.b-verticalgallery-items li').fadeOut('slow');
	       $element.find('.b-verticalgallery-items li[data-id="' + $activeElement.attr('data-id') + '"]').fadeIn('slow');
	       
	       
	       if(step > 3 && step < counts[$element.attr('data-count')] - 3) 
	           $element.find('.b-smallgallery-items').stop(true, true).animate({marginTop: offset + 150}, duration);   
	       
	       if(step == 0)
	           $element.find('.b-smallgallery-items').stop(true, true).animate({marginTop: 0}, duration);   
	       
//	       console.info( step, counts[$element.attr('data-count')] );
	       
	       if(step == counts[$element.attr('data-count')] - 1) {
	           $element.find('.b-smallgallery-next, .b-smallgallery-mask2').hide();
	       } else {
	           $element.find('.b-smallgallery-next, .b-smallgallery-mask2').show();
	       }
	       
   	       if(step  == 0) {
	           $element.find('.b-smallgallery-prev, .b-smallgallery-mask').hide();
	       } else {
	           $element.find('.b-smallgallery-prev, .b-smallgallery-mask').show();
	       }


	    }
	};

	$.fn.vGallery = function(params) {
        //methods.init.apply( this, arguments );
        this.each(function() {
            methods.init( $(this) );
        });
        return this;
	};
})(jQuery);
