;(function($) {
	// Write noscript style
	document.write("<style type='text/css'>.noscript{display:none}</style>");
	var defaults = {speed:50,isUpDown:true,isPositive:true,x:1,y:1};
	var scrollCls = {
		interval:null,
		settings:{},
		stop:false,
		started:false,
		pointPx:0,
		position:"up",
		goUp:function(){
			if(this.scrollTop()>=this.pointPx) this.scrollTop(0);
			else this.scrollTop(this.scrollTop()+this.settings.y);
		},
		goDown:function(){
			if(this.scrollTop()<=0) this.scrollTop(this.pointPx);
			else this.scrollTop(this.scrollTop()-this.settings.y);
		},
		goLeft:function(){
			if(this.scrollLeft()>=this.pointPx) this.scrollLeft(0);
			else this.scrollLeft(this.scrollLeft()+this.settings.x);
		},
		goRight:function(){
			if(this.scrollLeft()<=0) this.scrollLeft(this.pointPx);
			else this.scrollLeft(this.scrollLeft()-this.settings.x);
		},
		start:function(){
			if(!this.stop){
				this.started=true;
				switch(this.position){
				case "up":
					this.goUp();
					break;
				case "down":
					this.goDown();
					break;
				case "left":
					this.goLeft();
					break;
				case "right":
					this.goRight();
					break;
				}
				var o = this;
				setTimeout(function(){o.start();},o.settings.speed);
			}
		},
		init:function(){
			var child = this.children();
			if(this.settings.isUpDown){
				var h = child.height();
				child.append(child.html());
				this.pointPx = child.height()-h;
				if(this.settings.isPositive)
					this.position = "up";
				else
					this.position = "down";
			}else{
				var w = child.width();
				child.append(child.html());
				this.pointPx = child.width()-w;
				if(this.settings.isPositive)
					this.position = "left";
				else
					this.position = "right";
			}
			var o = this;
			o.start();
			o.hover(function(){o.stop=true;o.started=false;},
					function(){o.stop=false;setTimeout(function(){
						if(o.started==false) o.start();
					},500);});
		}
	};
	jQuery.fn.scrollCycle = function(settings){
		var s = this;
		$.extend(s,scrollCls);
		s.settings = $.extend({},defaults,settings);
		var html = s.html();
		if(s.settings.isUpDown==false) {
			s.css("position","relative");
			s.html("<pre></pre>");
			var child = s.children();
			child.css("position","absolute");
			child.html(html);
			if(child.width()>s.innerWidth()){
				s.init();
			}
		} else {
			s.html("<div></div>");
			var child = s.children();
			child.html(html);
			if(child.height()>s.innerHeight()){
				s.init();
			}	
		}
	};
})(jQuery);