/**
 * jQuery IE6 Alert
 * - red blok with text to
 * Version 1.0 - 9.4.2010
 * @author Ladislav -knedle- Sevcuj
 * http://blog.3tecky.cz
 *
 **/

(function($){
    // promenne
    
    var sec = 0;
    var min = 0;
    var hod = 0;
    var cas = '';
    var base = 60;

    $.fn.stopwatch = function(options) {

        //var defaults = {};
        //var options = $.extend(defaults, options);

        return this.each(function() {
            var timeInSec = 0;
            var element = $(this);
            timedCount(element, timeInSec);
        });
    };

    /**
     *
     */
    function timedCount(element, timeInSec)
    {
        if (timeInSec > base) { // (min or hour) and sec
            min = Math.floor(timeInSec/base);
            sec = timeInSec-(min*base);
            if (min > base) { // hour and min and sec
                hod = Math.floor(min/base);
                min = min-(hod*base);
                cas = printNumber(hod, false) + ":" + printNumber(min) + ":" + printNumber(sec);
            }
            else { // min and sec
                cas = printNumber(min, false) + ":" + printNumber(sec);
            }
        }
        else { // only sec
            cas = printNumber(timeInSec, false);
        }
        
        if ($(element).is(":input")) {
            $(element).val(cas);
        }
        else {
            $(element).text(cas);
        }

        timeInSec = timeInSec + 1;
        setTimeout(function(){
            timedCount(element, timeInSec)
            },1000);
    }

    /**
     *
     */
    function printNumber(number, addZero) {
        if (addZero == null)  {
            addZero = true;
        }
        if (addZero && number < 10) {
            return "0" + number;
        }
        else {
            return number;
        }
    }
})(jQuery);  
