/* 
 * jrslider script
 * Developed by Roshan Bhattarai
 */
(function($){
 $.fn.jrslider = function(options) {

  var defaults = {
   speed:3000,
   items:5,
   activeClass:'selected'  
   };
  var options = $.extend(defaults, options);
  return this.each(function() {
	  obj = $(this); 
          actClass = options.activeClass;
          //console.log($('#tabnavs a:first',obj).length+' '+actClass);
          $('#tabnavs a:first',obj).addClass(actClass);
          
		  $('.jrpanel',obj).not(':first').css('display','none');
            
          var currIndex = 0;
          
          function rotateSlides(){
                
                var nextIndex = currIndex ==(options.items-1)? 0 : currIndex+1 ;
				//change the tabs background
                $('#tabnavs a:eq('+nextIndex+')',obj).addClass(actClass);
				$('#tabnavs a:eq('+currIndex+')',obj).removeClass(actClass);
                //now change fadeout the current index and fade in the next index
                
				$('.jrpanel:eq('+nextIndex+')',obj).fadeIn(400);
				$('.jrpanel:eq('+currIndex+')',obj).fadeOut(900);
				//console.log(currIndex+' '+nextIndex)
				currIndex++;

                if( currIndex >= options.items )
					currIndex = 0;
            }

          theInt = setInterval(rotateSlides, options.speed);
          //$('li h2',obj).unbind('mouseenter').unbind('mouseleave');
          $('#tabnavs a',obj).hover(function(){
              	clearInterval(theInt);
              	var cuRdivIndex=$('#tabnavs a',obj).index(this);
              	currIndex = cuRdivIndex;
              	//console.log(cuRdivIndex);
				//change the tabs background
                $('#tabnavs a',obj).removeClass(actClass);
				$(this).addClass(actClass);
                //now change the panel
				$('.jrpanel:visible',obj).fadeOut(900);
				$('.jrpanel:eq('+currIndex+')',obj).fadeIn(400);
				
          },function(){
              theInt = setInterval(rotateSlides, options.speed);
          });
	  
  });
 };
})(jQuery);


