(function($){
    $.fn.productRotator = function(options){
        options = $.extend({}, $.fn.productRotator.defaults, options); 
        var owner = this;     

        return this.each(function() {
            var tot = $('> div', owner).size(),
                divs = owner.find('div'),
                cur = Math.floor(Math.random() * tot), /* gonna set random first item to show */
                active = true;

            function shownext() {
                if (active) {
                    divs.eq(cur).fadeOut(options.transition);
                    cur = (cur + 1 >= tot) ? 0 : cur + 1;
                    divs.eq(cur).fadeIn(options.transition);
                    owner.height(divs.eq(cur).height());
                }
                setTimeout(shownext, options.interval);
            }  
        
            owner.find('div').hide();
            owner.hover(function(){active = false;},function(){active = true;});
            shownext();
        });
    };
    $.fn.productRotator.defaults = {
        interval : 4000,
        transition: 800
    };
})(jQuery);



$(document).ready(function(){
	$('#product-rotator').productRotator();
	$("#packages").tabs();
});
