function $(){
    var els=new Array();
    for (var i=0;i<arguments.length;i++){
        var el=arguments[i];
        if(typeof el == 'string'){el=document.getElementById(el)}
        if(arguments.length == 1){return el;}
    els.push(element);
    }
    return els;
}
Function.prototype.bind=function(obj){
    var _method=this;
    return function(){
        _method.apply(obj,arguments);
    }
}
var Try={
    these: function(){
        var returnValue;
        for (var i = 0; i < arguments.length; i++) {
              var lambda = arguments[i];
              try{
                returnValue = lambda();
                break;
              }catch (e){}
        }
        return returnValue;
      }
}
//Ajax
var Ajax={
      getTransport: function(){
        return Try.these(
              function(){return new ActiveXObject('Msxml2.XMLHTTP')},
              function(){return new ActiveXObject('Microsoft.XMLHTTP')},
              function(){return new XMLHttpRequest()}
        ) || false;
  }
}
Ajax.sendRequest=function(){}
Ajax.sendRequest=function(url,postString,method,onload,onerror){
    this.url=url;
    this.postString=postString;
    this.method=method;
    this.onload=onload?onload:this.defaultOnload;
    this.onerror=onerror?onerror:this.defaultError;
    this.req=null;
    this.loadXMLDoc(url);
}
Ajax.sendRequest.prototype={
    loadXMLDoc:function(url){
        this.req=new Ajax.getTransport();
        if(this.req){
            try{
                var loader=this;
                this.req.onreadystatechange=function(){
                    loader.onReadyState.call(loader);
                }
                if(this.method=="POST"){
                    this.req.open('POST',url,true);
                    this.req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
                    this.req.send(this.postString);
                }else{
                    this.req.open('GET',url,true);
                    this.req.send(null);
                }
            }catch(e){
                this.onerror.call(this);
            }
        }
    },
    onReadyState:function(){
        var req=this.req;
        var ready=req.readyState;
        if(ready==4){
            var httpStatus=req.status;
            if(httpStatus==200||httpStatus==0){
                this.onload.call(this,req);
            }else{
                this.onerror.call(this);
            }
        }    
    },
    defaultOnload:function(req){
        document.write(unescape(req.responseText));
    },
    defaultError:function(){
        alert("error fetching data!"+"\nreadyState:"+this.req.readyState+"\nstatus:"+this.req.status+"\nheaders:"+this.req.getAllResponseHeaders());
    }
}

function tab(id,normal,touchType,isSpecial,special,autoPlay,aAjaxUrl){
    this.id=id;
    this.tabPosition=0;
    this.touchType=touchType;
    this.dl=$(this.id)
    this.dt=(this.dl).getElementsByTagName('dt');
    this.dd=(this.dl).getElementsByTagName('dd');
    this.touchedArray=[];
    var ajaxUrl=typeof(aAjaxUrl)=="object"?aAjaxUrl:[];
    var _self=this;
    this.x=function(evt,htype){
        var od;
        for(var i=0;i<_self.dt.length;i++){
            if(evt!=_self.dt[i]){
                if(isSpecial){
                    if(i==0){
                        _self.dt[i].className=special.firstTabOff;
                        _self.dd[i].className=special.firstConOff;
                    }else if(i==(_self.dt.length-1)){
                        _self.dt[i].className=special.lastTabOff;
                        _self.dd[i].className=special.lastConOff;
                    }else{
                        _self.dt[i].className=special.tabOff;
                        _self.dd[i].className=special.conOff;
                    }
                }else{
                    _self.dt[i].className=normal.tabOff;
                    _self.dd[i].className=normal.conOff;
                }
            }else{
                od=_self.dd[i];
                if(htype){
                    if(ajaxUrl[i]){
                        if(!_self.touchedArray[ajaxUrl[i]]){
                            new Ajax.sendRequest(ajaxUrl[i],"","GET",fillDate,function(req){});
                        }else{
                            _self.dd[i].innerHTML=_self.touchedArray[ajaxUrl[i]];
                        }
                    }
                }
                if(isSpecial){
                    if(i==0){
                        _self.dt[i].className=special.firstTabOn;
                        _self.dd[i].className=special.firstConOn;
                    }else if(i==(_self.dt.length-1)){
                        _self.dt[i].className=special.lastTabOn;
                        _self.dd[i].className=special.lastConOn;
                    }else{
                        _self.dt[i].className=special.tabOn;
                        _self.dd[i].className=special.conOn;
                    }
                }else{
                    _self.dt[i].className=normal.tabOn;
                    _self.dd[i].className=normal.conOn;
                }
                this.tabPosition=i;
            }
        }
        function fillDate(req){
            try{
                od.innerHTML=req.responseText;
                _self.touchedArray.push(ajaxUrl[i]);
                _self.touchedArray[ajaxUrl[i]]=req.responseText;
            }catch(e){}
        }
    }
    this.init=function(){
        var state=false;
        if(autoPlay){
            var time=parseInt(autoPlay)||3;
        }
        if(!time)return;
        if(_self.touchType){
            var otouchType=_self.touchType?_self.touchType:"onclick";
            for(var i=0;i<_self.dt.length;i++){
                _self.dt[i][otouchType]=function(e){
                    var e=e||event;
                    var t=e.srcElement||e.target;
                    _self.x(t,0);
                }
            }
        }
        $(this.id).onmouseover=function(){
            state=true;
        }
        $(this.id).onmouseout=function(){
            state=false;
        }
        setInterval(function() {
            if(state)return;
            if(!_self.tabPosition)_self.tabPosition=0;
            _self.x(_self.dt[++(_self.tabPosition)% _self.dt.length],0);
        },time*1000);
    }
    var initState=false;
    if(!initState){
        var tabFocus=undefined;
        for(var i=0;i<_self.dt.length;i++){
            _self.x(_self.dt[++(_self.tabPosition)% _self.dt.length],0);
        }
        initState=true;
    }
    $(this.id).onclick=function(e){
        var e=e||event;
        var t=e.srcElement||e.target;
        if(t.tagName.toLowerCase()!="dt")return;
        _self.x(t,1);
    }
    if(touchType)$(this.id)[touchType]=$(this.id).onclick.bind(this);
}
