(function($){
  
  var CSU = {
  	data:{
			licount:1
		},
  	getWidth:function(o){
		if(o){
			return o.innerWidth();
		}
	},
	getHeight:function(o){
		if(o){
			return o.innerHeight();
		}
	},	
	setViewPortHeight:function(elem,h){
		if(elem){
			elem.height(h);
		}
	},
	scrollEnd:function(o){
		if(o){
			return (CSU.data.licount < o.lislength-1)
		}
	},
	scrollMe:function(el,opt,dir){
		var scrollStr,self=this;
		if(dir){
			var dirObj = {
				down:"-="+opt.vph,
				up:"+="+opt.vph,
				top:0
			}
			scrollStr = dirObj[dir];
		}
		el.animate({opacity:1},3000).animate({
			top:scrollStr	
		},750,function(){
			if(self.scrollEnd(opt)){
				self.scrollMe(el,opt,"down");
				CSU.data.licount = CSU.data.licount+=1;
			}else{
				self.scrollMe(el,opt,"top");
				CSU.data.licount = 0;
			}
		});	
	},
	scrollDisplay: function(elem,opt){
		var self=this;
		self.scrollMe(elem,opt,"down");
	}

  }
  $.fn.coolScroll = function() {
	var defaults = {
		autoScroll: true	
	};

	var init = function(config){
		if(config){
			$.extend(config,defaults,config);
		}
		var allCoolScrolls = $('.coolScroll');
		$.each(allCoolScrolls,function(){
			var el = $(this),
			    ul = el.find('ul:first-child'),
			    li = el.find('li:first-child'),
			    lis = el.find('li'),
			    viewPortHeight = CSU.getHeight(li),
				  options = {
						vph:viewPortHeight,
						lislength:lis.length
			    };
					if(lis.length === 1){
						return false;
					}
			    $.extend(options,defaults,options);
			    CSU.setViewPortHeight(el,viewPortHeight);
			    if(options.autoScroll){
			    	CSU.scrollDisplay(ul,options);
			    }

		});
	};

	init();
  
  };

})(this.jQuery);

window.log = function(){
  log.history = log.history || [];
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});



