﻿
jQuery.fn.StepBar = function(config) {

    //参数
    config = jQuery.extend({

        id: null,     //ID
        count: 1,
        tips: [],
        seleted: 0,
        callback: function() { return false; } //回调函数

    }, config || {});

    return this.each(function() {

        var me = $(this);

        makeBar = function() {
            var str = new Array();
            str.push('<ul class="StepBar">');
            $.each(config.tips, function(i, t) {
                str.push('<li class="' + SetClass(i) + '">');
                str.push('<div class="step">Step ' + (i + 1) + ': ' + t + '</div>');
                str.push('</li>');
            });
            str.push('</ul>');
            me.html(str.join(''));
        }

        function SetClass(i) {
            var rtn = "";
            if ((i + 1) == config.seleted) {
                rtn = "nextSlted";
            }
            if ((i) == config.seleted) {
                rtn = "meSlted";
            }
            if (i == config.tips.length - 1) {
                if ((i) == config.seleted)
                    rtn = "lastSlted";
                else
                    rtn = "lastNoSlted";
            }
            return rtn;

        }
        function init() {
            if (!config.seleted) config.seleted = 0;

            makeBar();
        }

        init();
    });
}
