/**
 * sg_pluginProperites
 *
 */
;( function( $ ){
	
	var methods = {
		
		init : function( options ) {
			
			return this.each(function(){
				
				var $this = $(this);
				var data = $.extend( {}, {
					
					autoplay : true,
					interval : 5000,
					
					scrollable : undefined,
					slider : $this.find( '.slider.scrollable' ),
					controls : $this.find( 'a.next, a.prev')
					
				}, options );
				
				$this.data( 'sg_sliderPlugin', data );
				
				methods.initSlider.apply( $this );
				
			});
			
		},
		
		initSlider : function(){
			var $this = $( this );
			var data = $this.data( 'sg_sliderPlugin' );
			
			data.controls.fadeTo(0,0);
			
			$this
				.hover(
					function(){ methods.showArrows.apply( $this, arguments ) },
					function(){ methods.hideArrows.apply( $this, arguments ) }
				);
			
			data.slider
				.scrollable({
					circular:true
				})
				.navigator();
				
			data.scrollable = data.slider.data('scrollable');
			
			if ( data.autoplay ) {
				
				setInterval(function(){
					
					data.scrollable.next();
					
				}, data.interval);
				
			}
		
		},
		
		showArrows : function(){
			var $this = $( this );
			var data = $this.data( 'sg_sliderPlugin' );
		
			data.controls.stop().css( 'visibility', 'visible' ).fadeTo('fast', 1);
			$this.find( 'div.navi-outer-wrapper' ).addClass( 'hover' );			
		
		},
		
		hideArrows : function(){
			var $this = $( this );
			var data = $this.data( 'sg_sliderPlugin' );
		
			data.controls.stop().fadeTo('fast', 0);
			$this.find( 'div.navi-outer-wrapper' ).removeClass( 'hover' );			
		
		},
		
	}
	
	$.fn.sg_sliderPlugin = function( method ) {
		
		if ( methods[method] ) {
			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.sg_sliderPlugin' );
		}
	
	};
	
} )( jQuery );


