Array.prototype.indexOf = function(o, from){
        var len = this.length;
        from = from || 0;
        from += (from < 0) ? len : 0;
        for (; from < len; ++from){
            if(this[from] === o){
                return from;
            }
        }
        return -1;
    }
	function getElByClsName(ct,cls){
		var childs = ct.children , i = 0 ,len = childs.length , arr = [];
		//console.dir(childs )
		for(;len>i;i++){
			if(childs[i].className.indexOf(cls) != -1){
				arr[arr.length] = childs[i];
			}
		}
		return arr;
	}
	String.prototype.trim = function(){
	    var re = /^\s+|\s+$/g;
	    return function(){ return this.replace(re, ""); };
	}();
	function Wg_Tab(id,i,crtCls,eventName){
		var doc = document;
		var ct = doc.getElementById(id);
		var titleCls = 'wg_tab_title';
		var contentCls = 'wg_tab_content';
		eventName = eventName || 'click';
		i =  typeof i == 'number'? i :0;
		crtCls = crtCls || 'current';
		var currentIndex = i;
		var currentContent = null;
		var tCt = getElByClsName(ct,'wg_tab_titles')[0];	
		var cCt = getElByClsName(ct,'wg_tab_contents')[0];
		tCt['on'+eventName] = function(e){
			e = window.event || e;
			var target =  e.srcElement || e.target ;
			var j = Array.prototype.indexOf.apply(tCt.children,[target] );
			if(j !== -1 && currentIndex !== j){
				var c  = cCt.children[j];
				var old = cCt.children[currentIndex];
				old.className = old.className.trim().replace(crtCls,'') +' hide';
				c.className = c.className.trim().replace('hide',crtCls);
				//console.log(tCt.children[currentIndex].className)
				tCt.children[currentIndex].className = tCt.children[currentIndex].className.trim().replace(crtCls,'');
				tCt.children[j].className = tCt.children[j].className.trim().replace('hide','') + ' '+crtCls;
				currentContent = c;
				currentIndex  = j;
			}
		};
	}
	
	//new Wg_Tab('wg_tab1',1)
	//new Wg_Tab('wg_tab2')

