( function( $ ) {
	$.fn.imageScroller = function ( options ) {
		return this.each( function() {
			var $this = $( this );

			var loadImgs = 0;
			var totalWidth = 0;

			var opt = $.extend(
				{
					  direction: "left",
					  move: true
				}
				, options || {}
			);
			$( "div.scroll_banner_item_box" , $this ).each(
				function () {
					loadImgs++;
				}
			);

			var intVal = window.setInterval(
				function () {

						window.clearInterval( intVal );
						var totImg = 0;

						$.each(
							  $this.children( ":eq(0)" ).children( "div" )
							, function () {

								totImg += $( this ).width();

								$( this ).bind(
									  "mouseover"
									, function () {
										opt.move = false;
									}
								).bind(
									  "mouseout"
									, function () {
										opt.move = true;
									}
								);
							}
						);

						totalWidth = totImg;

						switch ( opt.direction ) {
							case 'right':
								$( "div:eq(1)" , $this ).css({
									marginLeft: -1800 + "px"
								});
								break;
						}
						setInterval(function(){
						    scrollStart( $( "div:eq(0)" , $this ) , opt );
						}, 35);
				}
				, 100
			);

			function scrollStart ( $scroll , opt ) {

			    switch ( opt.direction ) {
					case 'left':
						var pos = parseInt($scroll.css( "marginLeft")) - 1;
						if (pos < -1000) pos = 0;
						break;

					case 'right':
						var pos = parseInt($scroll.css( "marginLeft")) + 1;
						if (pos > 1600) pos = 30;
						//if (pos > -700) opt.move= false;
						break;
				}
                if (opt.move)
				    $scroll.css( "marginLeft" , pos + "px" );
			};
		});
	};
})(jQuery);
