(function($){  
  
	$.fn.iSlider = function(options){
		$.fn.iSlider.defaults = {
			animSpeed:1000,
			
			autoStart: false,
			pauseTime:3000,
			
			arrowsNav:true,
			arrowsNavHide:false,
			
			listNav:true,
			listNavThumbs:false,
			listNavThumbName:'_thumb',
			
			pauseOnHover: false,
			
			vertical: false 
		};
		var settings = $.extend({}, $.fn.iSlider.defaults, options);
		
		var blocks = {
			frame: '<div class="i-slider-frame">',
			tape: '<div class="i-slider-sections">',
			section: '<div class="i-slider-section">'
		};
		
		var $previous = $('<div class="i-slider-arrows previous"></div>');
        var $next = $('<div class="i-slider-arrows next"></div>');
		var $switcher = $('<ul class="switcher"></ul>');
		
        var $this = $(this);
        
        var init = {
        	height: $this.height(),
            width: $this.width(),
            images_total: $this.find('div.section').length,
            images_amount: $this.find('div.section').length
        };
        
        if(settings.layers){
        	var layers = settings.layers;
        }
        
        var current_image = 1;
                
		var make = function()
        {
			// get slider height and width
			var height = $this.height();
			var width = $this.width();
			
			//console.log( width, height );
			
			$this.wrapInner(blocks.frame);
			$('div.i-slider-frame',$this).wrapInner(blocks.tape);
           
			// set equal height and width for all sections and the frame
			$('div.i-slider-section',$this).height(height).width(width);
			$('div.i-slider-frame',$this).height(height).width(width);
			
			
			// clone the first and last and set them before and after all images
			var firts_last = $('div.i-slider-section:last', $this).clone();
			var last_first = $('div.i-slider-section:first', $this).clone();
			$('div.i-slider-sections', $this).prepend(firts_last).append(last_first);
			
			//check direction and set init width of tape and start position
			if(settings.vertical){
				$('div.i-slider-sections', $this).css('top','-'+height+'px');
			}
			else {
				$('div.i-slider-sections', $this).height(height).width( ($('div.i-slider-section',$this).length)*width ).css('left','-'+width+'px');
			}
			
			
			
			if(settings.arrowsNav){
        		$('div.i-slider-frame',$this).append($previous).append($next);
        		if(settings.arrowsNavHide){
        			$('div.i-slider-arrows',$this).hide();
        		}
			}
           
			/*
            if(settings.listNav){
	           if(settings.listNavThumbs){
	        	   $switcher.addClass('i-slider-listNavThumbs');
	        	   $.each(images, function(key, value) {
	        		   var img_src = $(value).attr('src');
	        		   var img_src_parts = img_src.split(".");
	        		   var img_thumb = img_src.replace('.'+img_src_parts[img_src_parts.length-1], settings.listNavThumbName+'.'+img_src_parts[img_src_parts.length-1])
	        		   $switcher.append('<li><img src="'+img_thumb+'" /></li>');
	        	   });
	           }
	           else {
	        	   $switcher.addClass('i-slider-listNav');
	        	   for(t=0;t<init.images_total;t++){
		        	   $switcher.append('<li></li>');
		           } 
	           }
	           $('li:first-child',$switcher).addClass('active');
	           $switcher.css('left', ($('div.i-slider-frame', this).width() - $switcher.width())/2 );
           }
           
           $('div.i-slider-images', $this).width( init.width * init.images_total);
           $('div.i-slider-image-outer', $this).width( init.width );
           */
 
        };
        
        
        
        $previous.bind('click', function(){
        	if(settings.vertical){
        		$this.find('div.i-slider-sections').animate({
 			   		top: '+='+init.height
 		   		}, settings.animSpeed, function(){
    		   		if( $('div.i-slider-sections',$this).css('top') == '0px' ){
    			   		$('div.i-slider-sections',$this).css('top','-'+( ($('div.i-slider-section',$this).length - 2) * $('div.i-slider-section',$this).height() )+'px');
    		   		}
    	   		});
        	}
        	else {
        		$this.find('div.i-slider-sections').animate({
 			   		left: '+='+init.width
 		   		}, settings.animSpeed, function(){
    		   		if( $('div.i-slider-sections',$this).css('left') == '0px' ){
    			   		$('div.i-slider-sections',$this).css('left','-'+( ($('div.i-slider-section',$this).length - 2) * $('div.i-slider-section',$this).width() )+'px');
    		   		}
    	   		});
        	}
        });
        
        $next.bind('click', function(){ 
        	if(settings.vertical){
        		$this.find('div.i-slider-sections').animate({
        			top: '-='+init.height
        		}, settings.animSpeed, function(){
        			if( $('div.i-slider-sections',$this).css('top') == '-'+( ($('div.i-slider-section',$this).length -1) * $('div.i-slider-section',$this).height() )+'px' ){
        				$('div.i-slider-sections',$this).css('top','-'+ $('div.i-slider-section',$this).height() +'px');
        			}
        		});
        	}
        	else {
        		$this.find('div.i-slider-sections').animate({
        			left: '-='+init.width
        		}, settings.animSpeed, function(){
        			if( $('div.i-slider-sections',$this).css('left') == '-'+( ($('div.i-slider-section',$this).length -1) * $('div.i-slider-section',$this).width() )+'px' ){
        				$('div.i-slider-sections',$this).css('left','-'+ $('div.i-slider-section',$this).width() +'px');
        			}
        		});
        	}

        });
        
        var timer = '';
        
        if(settings.autoStart){
        	if(settings.vertical){
        		timer = setInterval( function(){ $previous.trigger('click') }, settings.pauseTime );
        	}
        	else {
        		timer = setInterval( function(){ $next.trigger('click') }, settings.pauseTime );	
        	}
        }
        if(settings.pauseOnHover && settings.autoStart){
			$this.hover(function(){
				clearInterval(timer);
				timer = '';
			}, function(){
				if(timer == ''){
					timer = setInterval( function(){ $next.trigger('click') }, settings.pauseTime );
				}
			});
		}
        
        if(settings.arrowsNav && settings.arrowsNavHide){
        	$this.hover(function(){
				$('div.i-slider-arrows',$this).show();
			}, function(){
				$('div.i-slider-arrows',$this).hide();
			});
        }
        
        return this.each(make);
       
    };
    
})(jQuery);  
