(function($) {

    $.girlsMustHaveContent = function(element, options) {

        var defaults = {
            foo: 'bar',
            onFoo: function() {}
        }

        var plugin = this;

        plugin.settings = {}

        var $element = $(element),
             element = element;
        
		
	    var $collection_wrapper	= $element;     
		var $collection	= $('.entry-content', $collection_wrapper);

        
        //PROPERTIES
        var scroll_acceleration	= 20;
	    var collection_x		= 0;
        var collection_animated = false;
        var scroll_api;

        plugin.init = function() {
            plugin.settings = $.extend({}, defaults, options);
            initListeners();
            initCollection();
           	onDocumentResize();
           
	
        }

        plugin.foo_public_method = function() {
            // code goes here
        }

        var initListeners = function() {
            $element.bind('mousewheel', onDocumentScroll);
            $(window).bind('resize', onDocumentResize);
			
        }
        
        var initCollection = function(){
        	scroll_api = $collection_wrapper.jScrollPane({ animateDuration: 1000});
        }        
        
        /********************************/
		/* EVENT HANDLING				*/
		/********************************/
		
		var onDocumentScroll = function(event, delta, deltaX, deltaY){
			if( deltaY ){
				scroll_api.data('jsp').scrollByX(-deltaY * scroll_acceleration);
			}
		}
		
		
		
		var onDocumentResize = function( event ){
			
			var collection_width = 0;
			
			$('.horizontal', $collection).each(function(){
				collection_width += $(this).outerWidth(true);
				
				$(this).css({
					'margin-top': -( $(this).innerHeight() /2 )
					});
			})
			
			var w = Math.ceil(collection_width);
			$collection.css({ width: w });
			
			scroll_api.data('jsp').reinitialise();
		 }
		
		 
		 
		
		
		
        plugin.init();

    }

    $.fn.girlsMustHaveContent = function(options) {

        return this.each(function() {
            if (undefined == $(this).data('girlsMustHaveContent')) {
                var plugin = new $.girlsMustHaveContent(this, options);
                $(this).data('girlsMustHaveContent', plugin);
            }
        });

    }

})(jQuery);
