var useragent=navigator.userAgent.toLowerCase();
var isIE=((useragent.indexOf('msie')!=-1)&&(useragent.indexOf('opera')==-1)&&(useragent.indexOf('webtv')==-1));
String.prototype.trim=function()
	{
	return this.replace(/(^\s*)|(\s*$)/g,"")
};
function $gbi(id)
	{
	return document.getElementById(id)
}
function getEvent()
	{
	if(document.all)return window.event;
	var func=getEvent.caller;
	while(func!=null)
		{
		var arg0=func.arguments[0];
		if(arg0)
			{
			if((arg0.constructor==Event||arg0.constructor==MouseEvent)||(typeof(arg0)=="object"&&arg0.preventDefault&&arg0.stopPropagation))
				{
				return arg0
			}
		}
		func=func.caller
	}
}
function addEvent(obj,evt,fun)
	{
	if(!obj||typeof(fun)!="function")return;
	if(isIE)obj.attachEvent("on"+evt,fun);
	else obj.addEventListener(evt,fun,false)
}
function removeEvent(obj,evt,fun)
	{
	if(!obj||typeof(fun)!="function")return;
	if(isIE)obj.detachEvent("on"+evt,fun);
	else obj.removeEventListener(evt,fun,false)
}
function stopEvent()
	{
	if(window.event)
		{
		window.event.cancelBubble=true
	}
	else
		{
		var e=getEvent();
		if(e&&e.stopPropagation)e.stopPropagation()
	}
}
function getEventTarget()
	{
	var e=getEvent();
	var tl=null;
	if(e)tl=isIE?e.srcElement:e.target;
	return tl
}
function getInfo(o)
	{
	var to=new Object();
	to.left=to.right=to.top=to.bottom=0;
	var twidth=o.offsetWidth;
	var theight=o.offsetHeight;
	while(o)
		{
		to.left+=o.offsetLeft;
		to.top+=o.offsetTop;
		o=o.offsetParent
	}
	to.right=to.left+twidth;
	to.bottom=to.top+theight;
	return to
}

function getExpDate(days,hours,minutes)
	{
	var expDate=new Date();
	if(typeof(days)=="number"&&typeof(hours)=="number"&&typeof(hours)=="number")
		{
		expDate.setDate(expDate.getDate()+parseInt(days));
		expDate.setHours(expDate.getHours()+parseInt(hours));
		expDate.setMinutes(expDate.getMinutes()+parseInt(minutes));
		return expDate
	}
}
function getStyle(obj,field)
	{
	if(!obj)return"";
	try
		{
		if(isIE)return obj.currentStyle[field];
		else return document.defaultView.getComputedStyle(obj,null)[field]
	}
	catch(e)
		{
		return""
	}
}
function coverI(target,cover,offw,offh,repos)
	{
	if(!cover)return;
	cover.style.display="none";
	if(!cover.getAttribute("repos"))
		{
		if(repos)
			{
			var tem=document.createElement("div");
			document.body.insertBefore(tem,document.body.firstChild);
			document.body.replaceChild(cover,tem)
		}
		cover.setAttribute("repos",1);
		cover.style.position="absolute";
		addEvent(cover,"click",stopEvent)
	}
	var obj=this;
	obj.hideP=hideP;
	obj.showP=showP;
	obj.target=target;
	obj.cover=cover;
	function showP()
		{
		stopEvent();
		obj.cover.style.display="none";
		var pos=getInfo(obj.target);
		obj.cover.style.top=pos.top+offh+"px";
		obj.cover.style.left=pos.left+offw+"px";
		obj.cover.style.display="block"
	}
	function hideP()
		{
		obj.cover.style.display="none"
	}
	addEvent(document,"click",obj.hideP)
}
function setCurrentCat(catslugs,catboxid)
	{
	if(!catboxid)catboxid='categories';
	var catbox=$gbi(catboxid);
	if(!catbox)return;
	var cls=catbox.getElementsByTagName("a");
	var cns=catslugs.split(',');
	for(var i=0;
	i<cls.length;
	i++)
		{
		var al=cls[i];
		for(var j=0;
		j<cns.length;
		j++)
			{
			if(al.href.indexOf('/'+cns[j].trim()+'/')>0)
				{
				if(!al.className)al.className='current';
				else al.className+=' current';
				break
			}
		}
	}
}
var entry_pbox_id=null;
var post_lbox_id=null;
var source_link=null;
function setRpUrl(slogo)
	{
	var lbox=$gbi(post_lbox_id?post_lbox_id:"content");
	if(!lbox)return;
	if(slogo)
		{
		var logobox=document.createElement("div");
		logobox.className="slogo right";
		logobox.innerHTML='<img src="'+slogo+'" alt="Source" height="30"/>';
		lbox.insertBefore(logobox,lbox.firstChild)
	}
}
function fillRpUrl(udata)
	{
	for(var id in udata)
		{
		var url=udata[id][0];
		var logo=udata[id][1];
		var sp=$gbi("rp_s_"+id);
		if(sp)
			{
			if(logo)logo='<img src="'+logo+'.icon.gif" alt="Source" height="16"/>';
			else logo='Source';
			sp.innerHTML='<a class="fet-more right" href="'+url+'">'+logo+'</a>'
		}
	}
}
function fireLoadPanel(pid,cid)
	{
	var p=$gbi(pid),c=$gbi(cid);
	if(p&&c)
		{
		try
			{
			var temdiv=document.createElement("div");
			c.appendChild(temdiv);
			c.replaceChild(p,temdiv)
		}
		catch(e)
			{
		}
	}
}
var yul_select=null;
function repos_yubox(yubox,rul)
	{
	var nsul=rul.nextSibling;
	while(nsul&&nsul.nodeType!=1)nsul=nsul.nextSibling;
	if(!nsul||nsul.className!='yubox_con')
		{
		var con=document.createElement('div');
		con.className='yubox_con';
		if(!nsul)rul.parentNode.appendChild(con);
		else rul.parentNode.insertBefore(con,nsul);
		nsul=con
	}
	if(yubox.parentNode!=nsul)
		{
		var temdiv=document.createElement("div");
		nsul.appendChild(temdiv);
		nsul.replaceChild(yubox,temdiv)
	}
}
function getDescbox(ay)
	{
	while(ay&&ay.tagName.toLowerCase()!='li')ay=ay.parentNode;
	var tArr=ay.getElementsByTagName("div");
	if(tArr.lengh==0)return;
	var descBox=null;
	for(var i=0;
	i<tArr.length;
	i++)
		{
		if(tArr[i].className=="yu_desc")
			{
			descBox=tArr[i];
			break
		}
	}
	return descBox
}
function filter_link(boxid,yuw,yuh,func_html,url_key,func_ready)
	{
	var ybox=$gbi(boxid);
	if(!ybox)return;
	var ytbox=$gbi("yuv_box");
	if(!ytbox)
		{
		ytbox=document.createElement("div");
		ytbox.id="yuv_box";
		ytbox.innerHTML='<div id="yuv_head"><div id="yuv_close">Close</div><div id="yuv_title"></div></div><div id="yuv_pbox"><div id="yuv_player"></div></div>';
		ybox.appendChild(ytbox)
	}
	function ylink(ay)
		{
		var vid=ay.href.substring(url_key.length,ay.href.length);
		var ayt=ay.title;
		ay.onclick=function()
			{
			if(wyv(vid,ay,ayt))return false
		};
		ydesc(ay,ayt)
	}
	function ydesc(ay,ayt)
		{
		var descBox=getDescbox(ay);
		if(!descBox)return;
		var dh=document.createElement("h3");
		dh.innerHTML=ayt;
		descBox.insertBefore(dh,descBox.firstChild);
		ay.parentNode.onmouseover=function()
			{
			ay.title="";
			ay.mosc=1;
			var descCover=new coverI(ay,descBox,ay.offsetWidth+1,-10,1);
			setTimeout(function()
				{
				if(ay.mosc==1)descCover.showP()
			}
			,500);
			ay.parentNode.onmouseout=function()
				{
				ay.mosc=0;
				descCover.hideP()
			}
		}
	}
	function style_vsel(elem,sel)
		{
		var selelem=elem;
		while(selelem&&selelem.tagName.toLowerCase()!='li')selelem=selelem.parentNode;
		if(selelem)selelem.className=sel?'yuv_select':''
	}
	function wyv(vid,ay,aytitle)
		{
		if(yul_select)style_vsel(yul_select,false);
		yul_select=ay;
		style_vsel(yul_select,true);
		var yubox=$gbi('yuv_box');
		var ytitle=$gbi('yuv_title');
		var yclose=$gbi('yuv_close');
		var ypbox=$gbi('yuv_pbox');
		var yplayer=$gbi('yuv_player');
		var rul=ay.parentNode;
		while(rul&&rul.tagName.toLowerCase()!='ul')rul=rul.parentNode;
		if(!rul)return;
		repos_yubox(yubox,rul);
		yubox.style.display="block";
		ytitle.innerHTML="Loading...";
		yclose.onclick=function()
			{
			ypbox.style.overflow='hidden';
			yplayer.innerHTML="";
			if(yul_select)
				{
				style_vsel(yul_select,false);
				yul_select=null
			}
			var fsoi=setInterval(function()
				{
				var h=parseInt(ypbox.style.height);
				var fh=0;
				if(h>fh)
					{
					var ch=fh-h;
					h+=ch<-200?-200:ch;
					ypbox.style.height=h+"px"
				}
				else
					{
					ypbox.style.height=fh+"px";
					yubox.style.display="none";
					clearInterval(fsoi);
					window.scrollBy(0,-50)
				}
			}
			,13)
		};
		yplayer.style.position='absolute';
		yplayer.style.left='-99999px';
		yplayer.innerHTML=func_html(vid,yuw,yuh,ay);
		function fadeOutPlayer()
			{
			ypbox.style.height="0px";
			ypbox.style.overflow='hidden';
			var fost=50;
			var foi=setInterval(function()
				{
				var h=parseInt(ypbox.style.height);
				var fh=yuh;
				if(h<fh)
					{
					var ch=fh-h;
					h+=ch>100?100:ch;
					ypbox.style.height=h+"px"
				}
				else
					{
					ypbox.style.height=fh+"px";
					if(yplayer.style.position=="absolute")ypbox.className='yp_loading';
					func_ready();
					ytitle.innerHTML=aytitle;
					clearInterval(foi)
				}
				rul.scrollIntoView()
			}
			,13)
		}
		fadeOutPlayer();
		return true
	}
	var aE=ybox.getElementsByTagName("a");
	for(var i=0;
	i<aE.length;
	i++)
		{
		if(aE[i].href.indexOf(url_key)==0)
			{
			ylink(aE[i])
		}
	}
}
function onYouTubePlayerReady(vid)
	{
	$gbi('yuv_player').style.position="";
	$gbi('yuv_pbox').className=''
}
function filter_ylink(boxid,yuw,yuh)
	{
	var ybox=$gbi(boxid);
	if(!ybox)return;
	var aE=ybox.getElementsByTagName("a");
	for(var i=0;
	i<aE.length;
	i++)
		{
		if(aE[i].className=='yuvideo')
			{
			var vicon=document.createElement('span');
			vicon.className="playvideo";
			aE[i].appendChild(vicon)
		}
	}
	var yurl="http://www.youtube.com/watch?v=";
	function getYvHtml(vid,yuw,yuh,ay)
		{
		return'<object id="yvplayer_'+vid+'" width="'+yuw+'" height="'+yuh+'" bgcolor="#000000"><param name="movie" value="http://www.youtube.com/v/'+vid+'&rel=0&color1=006699&color2=54abd6&border=1&&hl=en&fs=1&autoplay=1&enablejsapi=1&playerapiid='+vid+'"></param><param name="allowFullScreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/'+vid+'&rel=0&color1=006699&color2=54abd6&border=1&hl=en&fs=1&autoplay=1&enablejsapi=1&playerapiid='+vid+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000" width="'+yuw+'" height="'+yuh+'"></embed></object>'
	}
	function pready()
		{
		setTimeout(onYouTubePlayerReady,17000)
	}
	filter_link(boxid,yuw,yuh,getYvHtml,yurl,pready)
}
function bk_wgimgs(boxid)
	{
	var con=$gbi(boxid);
	if(!con)return;
	var imgs=con.getElementsByTagName("img");
	for(var i=0;
	i<imgs.length;
	i++)
		{
		var wimg=imgs[i];
		wimg.style.display='none';
		var bkdiv=document.createElement('div');
		bkdiv.style.background='#000 url('+wimg.src+') no-repeat 50% 50%';
		bkdiv.style.width='100%';
		bkdiv.style.height='100%';
		bkdiv.style.cursor='pointer';
		wimg.parentNode.appendChild(bkdiv)
	}
}
function init_scat()
	{
	var flagCookie='sctab';
	var cur_sc=getCookie(flagCookie);
	var con=$gbi('scat');
	if(!con)return;
	var tcon=con.getElementsByTagName('h4');
	if(tcon.length!=1)return;
	tcon=tcon[0];
	var ta=tcon.getElementsByTagName('a');
	if(ta.length==0)return;
	function show_sct(sc_id)
		{
		for(var i=0;
		i<ta.length;
		i++)
			{
			var t=ta[i];
			var conid=t.id.replace('_t','_c');
			var c=$gbi(conid);
			if(!c)continue;
			var iscur=sc_id==t.id;
			t.className=c.className=iscur?'current':''
		}
	}
	if(cur_sc)show_sct(cur_sc);
	function aclick(a)
		{
		a.onclick=function()
			{
			show_sct(a.id);
			setCookie(flagCookie,a.id,getExpDate(0,0,30),"/");
			return false
		}
	}
	for(var i=0;
	i<ta.length;
	i++)
		{
		aclick(ta[i])
	}
}
var defLang='en';
var userLang=navigator.language?navigator.language:navigator.userLanguage;
function tr_isL(l1,l2)
	{
	l1=l1.toLowerCase();
	l2=l2.toLowerCase();
	if(l1==l2)return 1;
	if(l1.indexOf(l2)>=0||l2.indexOf(l1)>=0)return 2;
	return 0
}
if(userLang&&!tr_isL(defLang,userLang))
	{
	document.write('<script language="javascript" type="text/javascript" src="http://www.google.com/jsapi"></script>')
}
var pftools=new Object();
pftools.id='ptools';
pftools.visible=false;
pftools.add=function(href,title,img)
	{
	var pfo=$gbi(pftools.id);
	if(!pfo)return;
	var al=document.createElement('a');	
	al.innerHTML=img?'<img class="icon" src="'+img+'" align="absmiddle" />':title;
	al.href=href;
	al.title=title;
	pfo.appendChild(al);
	pftools.show()
};
pftools.show=function()
	{
	if(pftools.visible)return;
	var pfo=$gbi(pftools.id);
	if(!pfo)return;
	if(!pfo.innerHTML.trim())return;
	function adpos()
		{
		if(pfo.parentNode!=document.body)
			{
			var docwidth=parseInt(document.documentElement.clientWidth);
			var conwidth=parseInt(pfo.parentNode.offsetWidth);
			pfo.style.right=(docwidth-conwidth)/2+'px'
		}
	}
	adpos();
	pfo.style.display='block';
	pftools.visible=true;
	addEvent(window,'resize',adpos)
};
var izoomer=new Object();
izoomer.zooming=false;
izoomer.init=function(imgid,bimgw,bimgh,imgw,imgh)
	{
	var imgobj=$gbi(imgid);
	if(!imgobj)return;
	var bCi=$gbi('bci_'+imgid);
	if(!bCi)
		{
		bCi=document.createElement('div');
		bCi.id='bci_'+imgid;
		bCi.style.display='none';
		bCi.style.position='absolute';
		bCi.className='frimg';
		document.body.insertBefore(bCi,document.body.firstChild)
	}
	var imgobjbox=document.createElement('div');
	imgobjbox.className='pymimg_con';
	imgobjbox.style.width=imgw+10+'px';
	imgobj.parentNode.insertBefore(imgobjbox,imgobj);
	var temdiv=document.createElement('div');
	imgobjbox.appendChild(temdiv);
	imgobjbox.replaceChild(imgobj,temdiv);
	var imgmtools=document.createElement('div');
	imgmtools.className='pymimg_tools';
	imgobjbox.appendChild(imgmtools);
	var fullsize=document.createElement('span');
	fullsize.innerHTML='Larger size';
	imgmtools.appendChild(fullsize);
	function showfrimg()
		{
		if(izoomer.zooming)return;
		var posinfo=getInfo(imgobj);
		bCi.style.left=parseInt(posinfo.left)-10+'px';
		var scroll_top=parseInt(document.documentElement.scrollTop);
		var imgtop=parseInt(posinfo.top)-20;
		var ftop=imgtop>scroll_top?imgtop:scroll_top;
		bCi.style.top=ftop+'px';
		bCi.style.display='block';
		bCi.style.zIndex='999999999';
		var frmimg=$gbi('bfi_'+imgid);
		if(!frmimg)
			{
			frmimg=document.createElement('img');
			frmimg.id='bfi_'+imgid;
			frmimg.className='pybigimg';
			bCi.appendChild(frmimg)
		}
		frmimg.src=imgobj.src.replace(".thumb.jpg",".jpg");
		var obj=frmimg;
		obj.style.width=imgw+'px';
		obj.style.height=imgh+'px';
		var fw=bimgw;
		var fh=bimgh;
		var inv=13;
		var timespan=100;
		var stpw=(fw-imgw)*inv/timespan;
		var stph=(fh-imgh)*inv/timespan;
		var zoomPt=null;
		function doZoom()
			{
			var done=true;
			var w=parseInt(obj.style.width);
			if(w<fw)
				{
				obj.style.width=(w+stpw>fw?fw:w+stpw)+'px';
				done=false
			}
			var h=parseInt(obj.style.height);
			if(h<fh)
				{
				obj.style.height=(h+stph>fh?fh:h+stph)+'px';
				done=false
			}
			if(!done)zoomPt=setTimeout(doZoom,inv);
			else
				{
				izoomer.zooming=false;
				addTools()
			}
		}
		izoomer.zooming=true;
		doZoom();
		function addTools()
			{
			function hidefrimg()
				{
				if(zoomPt)clearTimeout(zoomPt);
				bCi.style.display='none'
			}
			frmimg.onclick=hidefrimg;
			bCi.onmouseout=function()
				{
				if(izoomer.zooming)return;
				var event=getEvent();
				var current_mouse_target=null;
				if(event.toElement)
					{
					current_mouse_target=event.toElement
				}
				else if(event.relatedTarget)
					{
					current_mouse_target=event.relatedTarget
				}
				function is_child_of(parent,child)
					{
					if(child!=null)
						{
						while(child.parentNode)
							{
							if((child=child.parentNode)==parent)
								{
								return true
							}
						}
					}
					return false
				}
				if(!is_child_of(bCi,current_mouse_target)&&bCi!=current_mouse_target)
					{
					hidefrimg()
				}
			}
		}
	};
	fullsize.onclick=showfrimg;
	imgobj.onclick=showfrimg
};
