function tab(Id, tId, EclassName, iBeHavior){
	if(!$(Id))return;
	if(iBeHavior==null)iBeHavior='mouseover';
	if(EclassName==null)EclassName='more';
	var self=this;
	var links=$(Id).getElementsByTagName('a');
	if(links.length==0)return;

	this.init=function(){
		for(var i=0;i<links.length;i++){
			eval("links[i].on"+iBeHavior+"=function(e){return self.itab(this);};");
			links[i].onclick=function(){
				return (this.href.indexOf('javascript:')>-1 || this.href.indexOf('#')<0 || this.className==EclassName);
			};
			links[i].onfocus=function(e){
				this.blur();
			};
		}
		self.itab(links[0]);
	};
	this.itab=function(o){
		if(o.href.indexOf('javascript:')>-1 || o.href.indexOf('#')<0 || o.className==EclassName){return true;}
		for(var i=0;i<links.length;i++){
			if(links[i].className!=EclassName)links[i].className='';
		}
		o.className='s';
		var url=o.href.substring(o.href.indexOf('#')+1);
		this.showDiv(url);
		return false;
	};
	this.showDiv=function(tDiv){
		if($(tId) && $(tDiv)){
			$(tId).innerHTML=$(tDiv).innerHTML;
			img_border($(tId));
			blank_link($(tId));
			set_className($(tId));
		}
	};
	this.createDiv=function(id){
		var div=document.createElement('div');
		div.style.display='none';
		div.id=id;
		document.body.appendChild(div);
		return div;
	};
	this.init();
}

function img_border(obj){
	var li = obj.getElementsByTagName('li');
	var img = null;
	for(var i=0;i<li.length;i++){
		img = li[i].getElementsByTagName('img');
		for(var j=0;j<img.length;j++){
			img[j].style.borderColor='#333';
			img[j].onmouseover=function(){this.style.borderColor='#f60';};
			img[j].onmouseout=function(){this.style.borderColor='#333';};
		}
	}
}

function blank_link(obj){
	obj=obj==null?document:obj;
	var links = obj.getElementsByTagName('a');
	for(var j=0;j<links.length;j++){
		links[j].setAttribute('target','_blank');
	}
}

function set_className(obj){
	obj=obj==null?document:obj;
	this.initialize=function(){
		var ename='';
		var links=obj.getElementsByTagName('a');
		for(var i=0;i<links.length;i++){
			ename=links[i].className;
			if(ename=='new' || ename=='hot'){
				links[i].style.position='relative';
				this.createDiv(links[i],ename);
			}
		}
	};
	this.createDiv=function(ilink, en){
		var a=document.createElement('div');
		a.className='icon_'+en;
		a.style.left=parseInt(ilink.offsetLeft-15)+'px';
		a.style.top=parseInt(ilink.offsetTop-15)+'px';
		ilink.parentNode.appendChild(a);
		return a;
	};
	this.initialize();
}

function $(){
	var elements = new Array();
	for (var i=0; i<arguments.length; i++) {
		var element = arguments[i];
		if(typeof element == 'string'){
			element = document.getElementById(element);
			if(arguments.length==1){return element;}
			elements.push(element);
		}
	}
	return elements;
}

function copyData(iData){
	window.clipboardData.setData("text",iData);
}

function maskAd(){
	this.createMaskImg=function(div,obj){
		var i=document.createElement('img');
		i.className='adsMaskImg';
		i.src='http://www.766.com/skin/2008/images/blank.gif';
		i.style.width=obj.parentNode.offsetWidth+'px';
		i.style.height=obj.parentNode.offsetHeight+'px';
		i.style.top='-'+obj.parentNode.offsetHeight+'px';
		div.appendChild(i);
		return i;
	};

	this.maskAds=function(links){
		if(links==null)links=document.getElementsByTagName('a');
		var re1=/^<object([\s\S]+)\/object>$/i;
		var re2=/^http\:\/\/get\.766\.com\/(.*)$/i;
		for(var i=0;i<links.length;i++){
			if(re1.test(links[i].innerHTML)){
				var obj = links[i].getElementsByTagName('object')[0];
				links[i].style.height=links[i].parentNode.offsetHeight+'px';
				links[i].className='adsMaskImg';
				this.createMaskImg(links[i],obj);
			}
		}
	};
}


function p_in_p(Id, cId, iLen){
	if(!$(Id))return;
	if(!$(cId))return;
	if($(Id).innerHTML=='')return;

	var url=window.location.href;
	if(/^http\:\/\/(.*)\/([\w\-]+)(_|\.)\d+\.shtml$/ig.test(url))return;

	var cPi=0, cEnd=false,len=0;
	var cDiv = $(cId);

	var newId = document.createElement('div');
	newId.id = Id;
	newId.innerHTML=$(Id).innerHTML;
	newId.style.display='block';

	this.show=function(){
		var pp = this.pd();
		if (document.createRange){
			/*google广告在FF下会出现空白一片，将其取消*/
			if(newId.innerHTML.indexOf('google_')>-1)return;
			var oRange = document.createRange();
			oRange.selectNodeContents(cDiv);
			if(pp!=null){oRange.setStart(pp, 0);}
			oRange.insertNode(newId);
		} else {
			if(pp!=null){
				if(cPi<=1 || cEnd){
					cDiv.insertBefore(newId, pp);
				}else{
					pp.appendChild(newId);
				}
			}else{
				if(iLen>len){
					cDiv.insertBefore(newId, cDiv.firstChild);
				}else{
					var newId1 = document.createElement('div');
					newId1.innerHTML='';
					newId1.style.display='none';
					document.body.appendChild(newId1);
					newId1.appendChild(newId);
					var oRange = document.body.createTextRange();
					oRange.moveToElementText(cDiv);
					oRange.move("character",iLen);
					oRange.pasteHTML(newId1.innerHTML);
				}
			}
		}
	};

	this.pd=function(){
		var P = cDiv.getElementsByTagName('p');
		for(var i=0;i<P.length;i++){
			len+=P[i].innerHTML.replace(/<.+?>/g,'#').length;
			if(len>iLen){cPi=i+1;break;}
			cEnd=true;
		}
		if(len==0)len=cDiv.innerHTML.replace(/<.+?>/g,'#').length;

		if(P.length > 0){
			if(cPi > 1 && cPi < 10){
				return P[cPi-1];
			}else{
				return P[0];
			}
		}
		return null;

	};
	this.show();
}
