﻿var $ = function (){
  var ele,Str;
  if(arguments.length<2){
      if(typeof arguments[0] != 'string'){
          ele = arguments[0];
          ele.$ADD = function (fn){CLS.add(this,fn)};
          return ele;
      }
      Str = arguments[0];
      ele = document;
  }else{
      if(typeof arguments[0] != 'string')ele = arguments[0];
      else ele = $(arguments[0]);
      Str = arguments[1] ;
  }
  Str=Str.replace(/\s+/g," ").split(" ");
  for(i=0;i<Str.length;i++){
      ele = G(Str[i]);
  }
    function G(str){
         if(str.indexOf('#')!=-1){return document.getElementById(str.split("#")[1])}
         if(str.indexOf('.')!=-1){
             if(ele.length)return ele;
             str = str.split(".");
             var tagname = str[0]==""?'*':str[0];
             str1 = str[1].split(":");
             var elems =ele.getElementsByTagName(tagname);
             var elemList=[],_n = 0;
             str1[1] = str1[1].toUpperCase();
               for(var i=0,j;j=elems[i];i++){
                     var att=j["className"]||j.getAttribute("class");
                     if (att==str1[0]){
                         if(str1[1]!=""){
                             if(str1[1]=="FIRST")return j;
                             else if(parseInt(str1[1])==_n)return j;
                         }
                         elemList.push(j);
                         _n++;
                     }
               }
              if(str1[1]=="LAST")return j;
              else if (str1[1]!="")return null;
              return elemList;
          }
       if(str.indexOf(':')!=-1){
           if(ele == document)ele = document.body;
           str = str.split(":");
           eles = str[0]==""?ele.childNodes:ele.getElementsByTagName(str[0]);
           var i=0,endi = str[1].toUpperCase(),lastEle;
           if(endi=='*')var allEle = [];
           for(var n=0,__ele;__ele=eles[n];n++){
               if(__ele.nodeType != 3 ){
                   if(endi=='FIRST')return __ele;
                   else if(i==parseInt(endi))return __ele;
                   lastEle = __ele;
                   if(endi=='*')allEle.push(__ele);
                   i++;
               }
               __ele = __ele.nextSibling;
           }
           if(endi=='LAST')return lastEle;
           if(endi=='*')return allEle;
           return null;
       }
            return ele.getElementsByTagName(str);
      }
    return ele;
};



function right_main_resize(){
	var cw=document.body.clientWidth;
	if (cw>936){
		$("#right_main").style.width = cw-182;
		$("#main").style.width = "100%";
	}else{
		$("#right_main").style.width = 770;
		$("#main").style.width = 936;
	}
}


function boxs(v){ 
	window.scrollTo(0,0); 
	var bo = document.getElementsByTagName('body')[0]; 
	var ht = document.getElementsByTagName('html')[0]; 
	var boht = document.getElementById('boxs'); 
	var bg = document.getElementById('bg'); 
	var info = document.getElementById('info'); 
	boht.innerHTML = "";
	bo.style.height='auto';
	bo.style.overflow='auto';
	ht.style.height='auto';
	bg.style.display='none';
	info.style.display='none';
	if(v == 1){ 
		bo.style.height='100%';
		bo.style.overflow='hidden';
		ht.style.height='100%';
		bg.style.display='';
		info.style.display='';
	} 
}

function lighttext(st,rt){
	var swd=$(rt).innerHTML;
	var ac=$(st).innerHTML;
	var re=new RegExp(swd,"gi");
	$(st).innerHTML = $(st).innerHTML.replace(re,eval("'<span style=color:red>'+swd+'</span>'"));
}



