/**
 * Copyright (C) 2010-2010 jamjax.com. All rights reserved.
 */
var IS_DEBUG=true;
var Timer = {
    _timers: {},
    _results: [],
    
    stopWatch:
    function () {
	     this.start = 0;
	     this.total = 0;
    },

	start: 
	function (name) {
	    if (typeof(IS_DEBUG) != "undefined" && IS_DEBUG) {
		    var t = this._timers[ name ];
		    if(!t) {t = new Timer.stopWatch();}
		    t.start = new Date().getTime();
		    Timer._timers[ name ] = t;
        }
	},
	
	stop: 
	function (name) {
	    if (typeof(IS_DEBUG) != "undefined" && IS_DEBUG) {
		    var t = this._timers[ name ];
		    if(t) {
		        t.total += new Date().getTime() - t.start;
		        Timer._results.push({name:name,time:t.total});
		        t.total = 0;
		    }
        }
	},
	
	show:
	function () {
        if(typeof(IS_DEBUG) != "undefined" && IS_DEBUG) {
            var str = "";
            for (var i=0;i<Timer._results.length;i++) {
                str += Timer._results[i].name + " : " +Timer._results[i].time + "ms\n";

            }
            //prompt(str,str;)
            if (confirm(str + "\n\nPress OK to reset" )) {
            /*
            	if (confirm('Copy results?')) {
                    if (document.all) {
                        prompt('Timer Results:', str);
                    } else {
                        for (var j=0;i<Timer._results.length;j++) {
                            console.log(Timer._results[j].name + ',' +Timer._results[j].time);
                        }
                    }
                }
              */
                Timer._timers= {};
                Timer._results= [];
            }
        }
    }
};

