﻿/**
*
*
* superslider:jQuery based images slider on the home page 
*
* Author: alex wang
* Email: wpsnowwolf@gmail.com
* URL: http://www.brightyoursite.com
* 
*
**/
(function($) {

jQuery.fn.superSlider = function(options){
  options = $.extend({},$.fn.superSlider.defaults, options); 
  	 return this.each(function() {
     $this = $(this); 
	$this.opts=options;
	$this.currentIndex = 0; 
    $this.contentlist=$this.find(options.contentlist+' li');
    $this.textlist=$this.find(options.textlist+' li');
    $this.btnlist=$this.find(options.btnlist+' li');
     $.fn.superSlider.init($this);
     
      });
}


$.fn.superSlider.defaults = {
		contentlist:'.contentlist',
		textlist:'.textlist',
		btnlist:'.btnlist', 
		timeout:5000
	}; 
	
$.fn.superSlider.init=function(me)
    {
		me.contentlist.eq(0).show();  
		$.fn.superSlider.autoScroll(me);
		me.btnlist.hover(function() {
				$.fn.superSlider.StopScrolll(me);
				me.btnlist.removeClass("current")
				$(this).addClass("current");  
				me.currentIndex=  me.find(me.opts.btnlist+' li').index(this); 
				me.contentlist.eq( me.currentIndex).fadeIn("slow"); 
				me.contentlist.not($(me.contentlist)[me.currentIndex]).hide();  
				me.textlist.hide();
				me.textlist.eq(me.currentIndex).show();
            }, function() {                
                $.fn.superSlider.autoScroll(me);
            });
		me.contentlist.hover(function(){
				$.fn.superSlider.StopScrolll(me);
				me.contentlist.removeClass("current")
				$(this).addClass("current");  
				me.currentIndex=  me.find(me.opts.contentlist+' li').index(this); 
				me.textlist.hide();
				me.textlist.eq(me.currentIndex).show();
		}, function(){
			$.fn.superSlider.autoScroll(me);
		});
}     
	
$.fn.superSlider.autoScroll=function(me) 
{
   me.find(me.opts.btnlist+' li:last').removeClass("current");
   me.find(me.opts.textlist+' li:last').hide();
   me.btnlist.eq(me.currentIndex).addClass("current");
   me.btnlist.eq(me.currentIndex - 1).removeClass("current");
   me.textlist.eq(me.currentIndex).show();
   me.textlist.eq(me.currentIndex - 1).hide();
   me.contentlist.eq(me.currentIndex).fadeIn("slow");
   me.contentlist.eq(me.currentIndex - 1).hide();
   me.currentIndex++; me.currentIndex = me.currentIndex >= me.btnlist.length ? 0 : me.currentIndex;
   clearInterval(me.t);
   me.t= setInterval(function(){ $.fn.superSlider.autoScroll(me);},me.opts.timeout); 
}
$.fn.superSlider.StopScrolll=function(me) 
   {
       clearInterval(me.t);
   }


})(jQuery);

