/*
	Powered by 766.com Copyright (c) All rights reserved.
	@By GhostWei
	@Email: ghostwei#gmail.com
	@2010-9-7 update for 766UE
*/
if(typeof(IndexID)!='undefined'){
	document.write('<script type="text/javascript" src="http://static.766.com/comment/2009/comment.js"></script>');
	document.write('<script type="text/javascript" src="http://comment.766.com/json.php?IndexID='+IndexID+'&num=10&var=comments"></script>');
	document.write('<script type="text/javascript" src="http://dynamic.766.com/publish/pn.php?IndexID='+IndexID+'"></script>');
}

if(typeof(news)=='undefined')var news = {};
news.Id = '_766_page_' + Math.random().toString().replace('.', '_');
news.$ = function(o){return document.getElementById(o);};
news.trim = function(s){return s.replace(/(^\s*)|(\s*$)/g, "");};

news.np = function(Id){
	if(!this.$(Id))return;
	if(typeof(PnNews)=='undefined')return;
	var s = '';
	/*上一篇，下一篇*/
	if(typeof(PnNews)=='object'){
		s += '<li class="pre">上一篇：';
		if(PnNews['pre'][0]==''){
			s += PnNews['pre'][1];
		}else{
			s += '<a href="'+PnNews['pre'][0]+'">'+PnNews['pre'][1]+'</a>';
		}
		s += '</li>';
		s += '<li class="next">下一篇：';
		if(PnNews['next'][0]==''){
			s += PnNews['next'][1];
		}else{
			s += '<a href="'+PnNews['next'][0]+'">'+PnNews['next'][1]+'</a>';
		}
		s += '</li>';
	}
	this.$(Id).innerHTML = s;
	if(this.$('np1'))
	this.$('np1').innerHTML = s;
};
news.copyData = function(iData){
	var s = v = '';
	if(iData==null)
	s = window.location.href + '\r\n' + document.title;	
	else s = iData;
	try{
		window.clipboardData.setData("text", s);
		v += '复制成功，按CTRL+V发送给好友、论坛或博客。';
	}catch(e){
		v += '浏览器限制，请复制以下链接和标题给好友、论坛或博客：\n\n' + s;
	}
	alert(v);
};
news.share = function(Id){
	/*复制链接地址给网友*/
	var self = this;
	if(this.$(Id)){
		this.$(Id).onclick = function(){
			var s = '';
			if(document.getElementsByTagName('h1')[0]){
				h1 = document.getElementsByTagName('h1')[0];
				var a = h1.getElementsByTagName('a')[0];
				s += '推荐一篇好文章：' + a.innerHTML + '\r\n' + a.href;
			}else{
				s = null;
			}
			self.copyData(s);
		};
	}
};
news.addFavorite = function(){
	var Title = document.title;
	var url = window.location.href;
	try{
		window.external.addFavorite(url, Title);
		return false;
	}catch(e){
		try{
			window.sidebar.addPanel(Title, url, "");
			return false;
		}catch (e){
			alert("加入收藏失败，请使用Ctrl+D进行添加");
			return false;
		}
	}
};

news.form = function(Id){
	if(!this.$(Id))return;
	var f = this.$(Id);
	var k = f.Keywords;
	var b = f.Submit;
	var t = f.TableID;
	
	k.value = '英雄联盟';
		
	var self = this;		
	f.onsubmit = function(){
		k.value = self.trim(k.value);
		if(k.value==''){
			alert('请输入搜索关键字！');
			k.focus();
			return false;
		}
		var action = f.action;
		action = 'http://search.766.com/search?Keywords='+(k.value)+'&TableID='+t.value;
		window.open(action);
		return false;
	};
	b.onclick = function(){
		f.onsubmit();
	};
};

news.ablank = function(Id){
	if(this.$(Id)){
		var a = this.$(Id).getElementsByTagName('a');
		for(var i=0;i<a.length;i++){
			a[i].style.border = 0;
			a[i].setAttribute('target', '_blank');
		}
	}
};
news.emotion = function(Id,css){
	if(!this.$(Id))return;
	if(typeof(IndexID)=='undefined')return;
	var e = this.$(Id);
	e.innerHTML = '';
	var iframe = document.createElement('iframe');
	iframe.id = 'emotion_frame_' + this._Id;
	with(iframe.style){
		height = '190px';
		width = '100%';
		border = 0;
		clear = 'both';
		padding = '0';
		frameBorder = 0;
	}
	iframe.setAttribute('scrolling', 'no');
	iframe.setAttribute('frameborder', '0', 0);
	iframe.setAttribute('src', 'http://dynamic.766.com/publish/emotion.php?IndexID=' + IndexID + '&css=' + css);
	e.appendChild(iframe);
};

news.comment = function(Id){
	if(!this.$(Id))return;
	if(typeof(IndexID)!='undefined'){
		Comment.IndexID = IndexID;
		Comment.Id = Id;
		Comment.loadForm('default');
		Comment.loadCss('http://css.ue.766.com/common/default_comment_list.css');
		if(window.addEventListener){
			window.addEventListener('load', function(){Comment.loadData(comments);}, false);
		}else{
			window.attachEvent('onload', function(){Comment.loadData(comments);});
		}
	}else{
		this.$(Id).innerHTML = '加载评论失败。';
	}
};
news.counter = function(){
	/*cms统计*/
	if(typeof(IndexID)!='undefined'){
		document.write('<script type="text/javascript" src="http://dynamic.766.com/publish/counter.php?IndexID='+IndexID+'"></script>');
		document.write('<script type="text/javascript" src="http://dynamic.766.com/publish/counter.php?action=json&IndexID='+IndexID+'"></script>');		
	}
};

news.mask = function(o,zindex){
	var div = o.getElementsByTagName('a')[0];
	var obj = o.getElementsByTagName('object')[0];
	if(typeof(obj)=='undefined')return;
	div.style.position = 'relative';
	div.style.display = 'block';
	div.style.styleFloat = 'left';
	div.style.cssFloat = 'left';
	div.style.left = 0;
	div.style.top = 0;
	obj.style.position ='absolute';
	obj.style.left = 0;
	obj.style.top = 0;
	obj.zIndex = 0;
	var i=document.createElement('img');
	i.style.position = 'absolute';
	i.src='http://static.766.com/a/images/blank.gif';
	i.style.width=obj.offsetWidth+'px';
	i.style.height=obj.offsetHeight+'px';
	i.style.top=0;
	i.style.left = 0;
	i.style.zIndex = zindex;
	i.style.border = 0;
	div.appendChild(i);	
	return i;
};
news.init = function(IndexID){
	if(this.$('banner_top'))this.mask(this.$('banner_top'),3);
	if(this.$('banner_relate'))this.mask(this.$('banner_relate'),3);
	if(this.$('banner_page'))this.mask(this.$('banner_page'),3);
	if(this.$('banner_side_one'))this.mask(this.$('banner_side_one'),3);
	if(this.$('banner_side_two'))this.mask(this.$('banner_side_two'),3);
	if(typeof(IndexID)!='undefined'){
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'http://dynamic.766.com/publish/counter.php?IndexID=' + IndexID;
		document.getElementsByTagName('head')[0].appendChild(script);
	}
};
if(window.addEventListener){
	window.addEventListener('load', function(){news.init(IndexID);}, false);
}else{
	window.attachEvent('onload', function(){news.init(IndexID);});
}
