;(function($){
	$.fn.flip=function(opt){
		opt=$.extend({delay:4000,speed:500},opt);
		$(this).each(function(i,n){
			var self=$(n).find("ul");
			function fix(){
				setTimeout(function(){
					var flag=true;
					self.find("img").each(function(i,n){						
						if(!n.resized){
							flag=false;
						}
					});
					if(flag){
						var height=self.find("li").outerHeight();
						var width=self.find("li").outerWidth();
						var size=self.find("li").size();
						var row=Math.floor(self.height()/height);
						var col=Math.floor(self.width()/width);
						self.wrap('<div id="fliper" class="ovh" style="height:'+height+'px; padding-bottom:10px"></div>');
						var box=self.parent();
						if(size>col){
							var cur=1;
							if(size%col==0){
								window.setInterval(function(){
									box.animate({scrollTop:height*cur},opt.speed,"swing",function(){
										if(cur==row-1){
											self.find("li:lt("+(col*(row-1))+")").insertAfter(self.find("li:last"));
											box.attr("scrollTop",0);			
											cur=1;
										}else{
											cur++;
										}
									});
								},opt.delay);
							}else{
								window.setInterval(function(){
									if(cur==row-1){
										self.find("li:lt("+(col*(row-1))+")").clone(true).insertAfter(self.find("li:last"));
									}
									box.animate({scrollTop:height*cur},opt.speed,"swing",function(){
										if(cur==row-1){
											self.find("li:lt("+(col*(row-1))+")").remove();
											box.attr("scrollTop",0);			
											cur=1;
										}else{
											cur++;
										}
									});
								},opt.delay);
							}
						}
					}else{
						fix();
					}
				},300);
			}
			fix();
		});
	}
})(jQuery);
$(function(){
	if($(".cm-imglist-special").size()>0){
		$(".cm-imglist-special:eq(0)").flip({});
	}else{
		$(".cm-imglist-m:eq(0)").flip({});
	}
})
