// JavaScript Document


//文章页复制文本框中的内

function copyqqText(text)
{
	var obj=document.getElementById(text);
	if (obj!=null)
	{
		var thisHtml=obj.innerText;
		 clipboardData.setData("text", thisHtml);
		 alert('信息已复制，直接粘贴即可。')
	}
}


function showListLi(liobj,num)
{
  var obj=$("#"+liobj+" li");
  
 // alert(liobj)
  var n=0;
  for(var i=0 ;i< obj.length;i++)
  {
	  if  (n==num)
	  {
		  obj.eq(i).after("<li class='link'> </li>");
		  n=0;
	  }
	  n++;
  }
}


function changeType(el,type){
   var els = el.parentNode.getElementsByTagName(el.tagName);
   for(i=0,l=els.length;i<l;i++){
		els[i].className = "";
	}
	el.className = "cur";
   document.getElementById('searchType').value = type;
   
}


function changeSkin(el){
	
	var skin = el.className
	if(/cur/.test(skin)) return;
	
   var els = el.parentNode.getElementsByTagName(el.tagName);
   for(i=0,l=els.length;i<l;i++){
		if(/(s\d)\scur/.test(els[i].className)){
			els[i].className = RegExp.$1;
			break;
		}
		
	}


	el.className = skin + " cur";
	document.body.className = skin;
	PostCookie("skin=" + skin);
   
}

function loadSkin(){
	
	var skin = getCookie("skin");
	var els = document.getElementById("skin").getElementsByTagName("span");
	
	if(skin == ""  || skin == null ) {
		document.body.className = "s0";
		return;
	}
	
	var cur = parseInt(skin.charAt(1));

	document.body.className = skin;

	if (cur === 0) return;
	els[0].className = "s0";
	els[cur].className += " cur";
	
}




function InfoHeight(){
	var contentBox = document.getElementById('info_content');
	var showWrap = document.getElementById("show_content");
	var showButton =  document.getElementById('show_button');
	var showText = showButton.getElementsByTagName("span")[0];
	var hideBg = document.getElementById("hide_bg");
	var maxHeight = 800;	
	
	this.init = function(){
		
		if(contentBox.offsetHeight > maxHeight){
			contentBox.style.height = maxHeight + 'px';
			showWrap.style.display = 'block';
			hideBg.style.display = "block";
		}
		
	}
	
	this.button = function(){
		

		if(showButton.className == "show" ){
			
			showButton.className = "hide";
			showText.innerHTML = "收起信息";
			hideBg.style.display = "none";
			contentBox.style.height ="auto";
		} else {
			showButton.className = "show";
			hideBg.style.display = "block";
			showText.innerHTML = "显示全部";
			contentBox.style.height = maxHeight + 'px';
		}
		
	}	
}



var proMaxHeight = 48;
var proMaxWidth = 48;

function proDownImage(ImgD){
      var image=new Image();
      image.src=ImgD.src;
      if(image.width>0 && image.height>0){
		  if(image.width <proMaxWidth || image.height <proMaxHeight){
			  ImgD.style.left = (proMaxHeight - image.height)/2 + 'px';
			  ImgD.style.top = (proMaxWidth - image.width)/2 + 'px';

			  
		  }else if(image.width/image.height >= proMaxWidth/proMaxHeight ){
			  ImgD.width = image.width*(proMaxHeight/image.height);
			  ImgD.height =  proMaxHeight
			  ImgD.style.left = -(image.width*(proMaxHeight/image.height)-proMaxWidth)/2 + "px";

     	  } else {		  
			  ImgD.width = proMaxWidth;
			  ImgD.height =  image.height*(proMaxWidth/image.width);
			  ImgD.style.top = -(image.height*(proMaxWidth/image.width)-proMaxHeight)/2 + "px";
		  }
      }
}



var showSortsMenu ={
	init: function(){
		
		//兼容未修改菜单
		var uls = document.getElementsByTagName("ul"),
			nav;
		
		for(i=0, l=uls.length;i<l;i++){
			if(uls[i].className == "nav"){
				nav = uls[i];
				break;
			} 
		}
		
		var lis = nav.getElementsByTagName("li");
		if(lis.length === 16){
			lis[12].style.display = "none";
		}

		var menu = document.getElementById("show_sorts").parentNode,
		box = document.getElementById("menu_sorts");
		
		menu.onmouseover = function(){
			box.style.display = "block";
		}
		
		menu.onmouseout = function(){
			box.style.display =  "none";

		}
		
		box.onmouseout = function(){
			box.style.display = "none";
		}
		box.onmouseover = function(){
			box.style.display = "block";
		}
		
		var subSortsMenu = document.getElementById("menu_sorts").getElementsByTagName("dd");
		var ssmenu = [];
		for(var i=0,l=subSortsMenu.length; i < l ;i++){
			if(subSortsMenu[i].className == "sorts_sub"){
				var strong = subSortsMenu[i].getElementsByTagName('strong')[0];
				var ul = strong.parentNode.getElementsByTagName('ul')[0]
				strong.onmouseover = function(){
					this.className = "cur";
					this.parentNode.getElementsByTagName('ul')[0].style.display = "block";
				}
				
				strong.onmouseout = function(){
					this.className = "";
					this.parentNode.getElementsByTagName('ul')[0].style.display = "none";					
				}
				
				ul.onmouseover = function(){
					this.parentNode.getElementsByTagName('strong')[0].className = "cur";
					this.style.display = "block";
				}
				
				ul.onmouseout = function(){
					this.parentNode.getElementsByTagName('strong')[0].className = "";
					this.style.display = "none";					
				}
			}
		}		
		
	}
	 
}



var easyTab = function(){
	
	var cache = {}, menu = {}, box_name = 'box_';
	
	return function(e){
	
		var parent= e.parentNode,
		id = parent.id.replace(/\D+/g,''),
		boxs = cache[id],
		tabs = menu[id];
		
		if(!tabs){
			var tag = e.tagName.toLowerCase(),
			tabs = parent.getElementsByTagName(tag);
			menu[id] = tabs;
		}
		
		
		//筛选出选项卡内容区域
		if( !boxs){
			var box_parent = document.getElementById( box_name + id ),
				child = box_parent.getElementsByTagName('*');
			
			cache[id] = [];
			for(var i = 0, len = child.length; i < len ; i++){
				if( child[i].parentNode ==  box_parent ) cache[id].push(child[i]);
			}
			
			boxs = cache[id];
		}
		
		
		//显示隐藏
		for(var i = 0, len = tabs.length; i < len ; i++){
				//if(tabs[i].className == 'more') continue; //过滤
				var is_self = tabs[i] == e ;
				tabs[i].className = is_self ? "cur" : "";
				boxs[i] && (boxs[i].style.display = is_self ? "block" :  "none");
		}	
	
	}
	
}();

// 单行内容复制
function copyLine(id){
	
	// 检测页面
	
	if( $('.nvbar a').eq(2).text().search(/QQ网名|QQ签名|QQ分组/i)  < 0) return;
	
	var doc =  document.getElementById(id);
	

	
	if(!doc) return;
	
	

	
	var fragment = document.createDocumentFragment(),
		arc =  doc.cloneNode(true), 
		node = arc.firstChild,
		res = [],
		getElem =function(elem){
				if(elem.getElementsByTagName('br').length){
					elem =	makeChild(elem)
				} else if( elem.innerHTML.replace(/&nbsp;/ig,'').replace(/\s+/) == ''){
					elem = document.createElement('br');
				}
				return elem
			},
		getText = function(elem){
			var p = document.createElement('p');
			p.appendChild(elem);
			return p;
		},
		
		makeChild = function(elem){
		
			//@hack IE中 "a<br><br>b".split(/<br[^>]*>/i) 的结果会是  ['a','b']
			var p = elem.cloneNode(false),
				con = elem.innerHTML.replace(/<br[^>]*>/ig,'<br>').split('<br>'),
				result = [];
		
			for(var i =0 , len = con.length; i < len; i++){
				var c = con[i],
					r;
				if (c == '') r= document.createElement("br");
				else {
					r = p.cloneNode(false);
					r.innerHTML = c;
				}
				result.push(r);
			}
		
			return result
		};

	do { res.push(node) } while( node = node.nextSibling)
	
	for(var i=0, len = res.length; i < len; i++){
		var after,
			elem = res[i],
			type = elem.nodeType;
	
		if(type == 1) elem = getElem(elem);
		else if( type == 3 ) elem = getText(elem);
		
		if( Object.prototype.toString.call(elem).toLowerCase().indexOf('array') > -1){
			
			for(var j=0, k = elem.length; j < k; j++){
				fragment.appendChild(elem[j]);
			}
			
		} else {
			fragment.appendChild(elem);	
		}
	}

	arc.innerHTML = '';
	arc.appendChild(fragment);
	doc.parentNode.replaceChild(arc,doc);

	
	// @hack 在ie中使用 append 移动元素后将不能再触发事件

	$(".copy-line").live('click',function(){
			var txt = $(this).parent().text();
			try{
					window.clipboardData.setData("Text",txt); 
					alert("复制成功!");
			} catch(e){
				alert("您使用的浏览器器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
			}								  
	})
	
	$(arc).find('p').hover(function(){
		var $this = $(this),
			$copy = $this.find('.copy-line');
		
		if( $copy.length) $copy.show()
		else $this.append('<span class="copy-line"></span>');
	}, function(){
		$(this).find('.copy-line').hide();
	})
	
	
}

// jQuery Ready


(function(){
	
	if (typeof jQuery == "undefined"){
		setTimeout( arguments.callee,200)
	} else {
		// jQuery 加载后执行
		copyLine('zoom');
	}
	
})()
