vmf.rotate = function($){
    var defaults = {
        autoRotate: false,
        autoResume: false,
        rotateSpeed: 3
    };
    var currIdx = 0;
    var timerId = -1;
    var $divs = null;
    var next = function(){
        window.clearInterval(timerId);
        $divs.eq(currIdx).fadeOut(function(){	            
			
			var cnt = (currIdx + 1 <= $divs.size()) ? (currIdx + 1) : 1;
			currIdx = (currIdx + 1 < $divs.size()) ? (currIdx + 1) : 0; 			

           $('#show' + cnt).parent().removeClass("active");
		    
			$divs.eq(currIdx).fadeIn();
			
			var cnt = currIdx + 1;			
			$('#show' + cnt).parent().addClass("active");
			
            if(defaults.autoResume){
                timerId = window.setInterval(next, defaults.rotateSpeed * 1000);
            } 
        });
    };
    var previous = function(){
        window.clearInterval(timerId);
        $divs.eq(currIdx).fadeOut(function(){
            
			var cnt = currIdx + 1;		
            currIdx = (currIdx - 1 >= 0) ? (currIdx - 1) : ($divs.size() - 1);
			
			$('#show' + cnt).parent().removeClass("active");
            $divs.eq(currIdx).fadeIn();
			var cnt1 = currIdx + 1;
			$('#show' + cnt1).parent().addClass("active");
            if(defaults.autoResume){
                timerId = window.setInterval(next, defaults.rotateSpeed * 1000);
            }
        });
    };
    var show = function(i){
        if((i < 0) || (i > $divs.size()))
            return false;
        i = i - 1;
        window.clearInterval(timerId);
        $divs.eq(currIdx).fadeOut(function(){
            currIdx = i;
            $divs.eq(currIdx).fadeIn();
            if(defaults.autoResume){
                timerId = window.setInterval(next, defaults.rotateSpeed * 1000);
            }
        });
    };
    return{
        build: function($elems, config){
            $divs = $elems;
            defaults = $.extend(defaults, config);
            $divs.eq(currIdx).show();
            if(defaults.autoRotate){
                timerId = window.setInterval(next, defaults.rotateSpeed * 1000);
            }
        },
        next: function(){
            next();
        },
        previous: function(){
            previous();
        },
        show: function(i){
            show(i);
        },
        getIdx: function(){
            return (currIdx + 1);
        }
    };
}(jQuery);

