(function(){
function pr(){
	this.$=function(obj,tag){
		var a;
		if(typeof obj=='string'){a=document.getElementById(obj);}
		else if(typeof obj!='string'){a=obj;}
		if(tag&&typeof tag=='string'){a=a.getElementsByTagName(tag);}
		return a;
	}
	this.$css=function(css,obj){
		if(!obj){obj=this.$(document,'*');}
		var objs=[];
		var cssName=new RegExp("\\b"+css+"\\b");
		for(i=0;i<obj.length;i++){if(obj[i].className.match(cssName)){objs.push(obj[i]);}}
		return objs=(objs.length==1)?objs[0]:objs;
	}
	this.addEvent=function(obj,type,fn){
		if(obj.attachEvent){
			obj['e'+type+fn]=fn;
			obj[type+fn]=function(){obj['e'+type+fn](window.event);}
			obj.attachEvent(type,obj[type+fn]);
		}
		else obj.addEventListener(type.slice(2),fn,false);
	}
	this.cc=function(obj,c){
		for(var i in c){
			if(typeof c[i]=="string"){obj[i]=c[i];}
			else{for(var n in c[i]){obj[i][n]=c[i][n]}}
		}
	}
	this.cTag=function(obj,c,fobj){
		if(typeof obj=="string")obj=document.createElement(obj);
		this.cc(obj,c);
		if(!fobj){return obj;}
		else{fobj.appendChild(obj);}
	}
}
pr.prototype={
	interColor:function(objs){//隔行换色 | objs:数组对象
		if((typeof objs.length)=="undefined")return;
		var	len=objs.length;
		for(var i=0;i<len;i++){
			objs[i].className=(i%2>0)?"bg":"";
		}
	},
	tab:function(x){//选项卡 | x.objA:标题(数组) | x.css:作用类名 | x.objB:对应内容(数组/可选) | x.on:事件类型(可选/默认click) | x.i:默认作用对象序列号(可选/默认0)
		if(!x.objB)x.objB=x.objA;
		if(!x.on)x.on="onclick";
		if(!x.i)x.i=0;
		if((typeof x.objA.length)=="undefined"&&(typeof x.objB.length)=="undefined"&&typeof x.on=="srting"&&typeof x.css=="srting"&&typeof x.i=="number")return;
		var z=new RegExp("\\b"+x.css+"\\b");
		var len=x.objA.length,
			fn=function(){
				for(var n=0;n<len;n++){
					x.objA[n].className=x.objA[n].className.replace(z,"");
					x.objB[n].className=x.objB[n].className.replace(z,"");
				}
				if(typeof this.temp=="number")x.i=this.temp;
				x.objA[x.i].className+=" "+x.css;
				x.objB[x.i].className+=" "+x.css;
			}
		for(var i=0;i<len;i++){
			x.objA[i].temp=i;
			this.addEvent(x.objA[i],x.on,fn);
		}
		fn();
	},
	marque:function(x){//内容滚动 | x.obj:运动对象 | x.d:运动方向(top/right/bottom/left) | x.h:运动幅度(px) | x.s:运动频率(毫秒)
		var max,min,box=this.cTag("div",{"style":{"position":"absolute"},"innerHTML":x.obj.innerHTML});
		x.obj.innerHTML="";
		if(!h)var h=-x.h;
		this.cTag(box,{},x.obj);
		if(x.d=="left"||x.d=="right"){
			max=box.scrollWidth;
			min=x.obj.clientWidth;
			box.style.width=max+"px";
		}
		else{
			max=box.scrollHeight;
			min=x.obj.clientHeight;
			box.style.height=max+"px";
		}
		var m=function(n){
			if(n<-max)n=min;
			box.style[x.d]=(n+"px");
			h=n-x.h;
		}
		x.obj.gt=function(){this.setI=setInterval(function(){m(h)},x.s);}
		x.obj.onmouseover=function(){clearInterval(this.setI)}
		x.obj.onmouseout=function(){this.gt()}
		x.obj.gt();
	},
	fade:function(x){//淡入淡出 | x.obj:作用对象 | x.x:作用类型(max:显,min:隐) | x.fn:作用完毕后执行语句(可选)
		var fadeMy=this,lvMin=100,lvMax=0;
		this.fadeGtMax=function(){
			if(lvMax<100){
				lvMax+=10;
				this.opacity(x.obj,lvMax)
				x.obj.mm=setTimeout(function(){fadeMy.fadeGtMax()},50);
			}
			else eval(x.fn);
		}
		this.fadeGtMin=function(){
			if(lvMin>0){
				lvMin-=10;
				this.opacity(x.obj,lvMin);
				x.obj.mm=setTimeout(function(){fadeMy.fadeGtMin()},50);
			}
			else eval(x.fn);
		}
		if(x.x=="max")this.fadeGtMax();
		else this.fadeGtMin();
	},
	opacity:function(obj,lv){//透明度设置
		if(typeof lv=="number"){
			if(document.all)obj.style.filter="alpha(opacity="+lv+")";
			else obj.style.opacity=lv/100;
		}
	}
}
window.pr=new pr();
})();
