function p(o){var pa=[0,0];if(o.offsetParent){do{pa[0]+=o.offsetLeft;pa[1]+=o.offsetTop;}while(o=o.offsetParent);}
return pa;}
function GetPosition(obj){var p=[0,0];do{p[0]+=obj.offsetLeft;p[1]+=obj.offsetTop;}while(obj=obj.offsetParent);return p;}
function is_valid_uri(u){var r=u.match(/^(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(:[0-9]*)?\/?([a-zA-Z0-9\-\._\?\,\'\/\\\+&%\$\#\=~])*$/);return r?true:false;}
function l(t){var l=t.value.length;if(l>141)t.value=t.value.substring(0,141);else document.getElementById('chars_left').innerHTML=(141-l);}
var fadei;function FadeScreen(in_text){var f=document.getElementById('_fade');if(in_text){if(!f){f=document.createElement('div');f.id='_fade';var c=document.createElement('div');c.id='_fadecontent';var t=document.createElement('span');t.id='_fadetxt';f.appendChild(c);c.appendChild(t);c.appendChild(document.createElement('br'));c.appendChild(fadei);document.body.appendChild(f);}
document.getElementById('_fadetxt').innerHTML=in_text;f.style.display='block';}
else{if(f)f.style.display='none';}}
function fs(t){FadeScreen(t);}
function is_youtube(u){var r=u.match(/^http:\/\/(www\.)?youtube\.com\/.*v=([a-z0-9_-]{11})/i);return r?r[2]:false;}
function is_vimeo(u){var r=u.match(/^http:\/\/(www\.)?vimeo\.com\/([0-9]+)/i);return r?r[2]:false;}
function is_capped_tv(u){var r=u.match(/^http:\/\/(www\.)?capped\.tv\/(\w+-\w+|[0-9]+-1-0)/i);return r?r[2]:false;}
function is_demoscene_tv(u){var r=u.match(/^http:\/\/(www\.)?demoscene\.tv\/.*id_prod=([0-9]+)/i);return r?r[2]:false;}
function is_video(u){return(is_youtube(u)||is_vimeo(u)||is_capped_tv(u)||is_demoscene_tv(u));}
function FormatTitle(title,img_src){var parts=title.match(/^([\s\S]*)\[([^\[\]]*?)(\w+)\]$/);var t='<div class="src">'+parts[2]+'<strong>'+parts[3]+'</strong></div>'
+'<div class="txt">'+parts[1]+'</div>'
+'<div style="text-align:center"><img onload="ImgResize(this);" class="img" src="'+img_src+'"></div>';return t.replace(/(\r|\n)/g,'<br>').replace(/(<br>){2,}/g,'<br>');}
function ImgResize(img){var title=document.getElementById('_title');var mosaic=document.getElementById('_mosaic');var w=(img.width>200)?img.width:200;var txt=title.childNodes[1];if(txt){txt.style.maxWidth=w+'px';}
if(title.ppx_x<0){title.style.left=((-title.ppx_x)-(w+14))+'px';}
if(title.ppx_show)title.style.display='block';}
function ShowTitle(e){if(!e)e=window.event;var from=e.currentTarget||e.toElement;var to=e.relatedTarget||e.fromElement;if(from.tagName=='IMG')
from=from.parentNode;if(to&&to.tagName=='IMG')
to=to.parentNode;if(from==to)
return;var t=document.getElementById('_title');t.title=from.title;if(t.title.length>0){var img=from.getElementsByTagName('img')[0];var img_src=img.src.replace(/\/tb\//,'/tf/');t.innerHTML=FormatTitle(t.title,img_src);var width=(window.width||document.body.clientWidth);var bb=GetPosition(from);if(bb[0]<width/2)t.ppx_x=(bb[0]+from.offsetWidth);else t.ppx_x=-(bb[0]);t.style.left=(bb[0]+from.offsetWidth)+'px';t.style.top=bb[1]+'px';t.ppx_show=true;}
from.title='';}
function HideTitle(e){if(!e)e=window.event;var from=e.currentTarget||e.fromElement;var to=e.relatedTarget||e.toElement;if(from.tagName=='IMG')
from=from.parentNode;if(to&&to.tagName=='IMG')
to=to.parentNode;if(from==to)
return;var t=document.getElementById('_title');t.ppx_show=false;t.style.display='none';if(t.title.length>0)
from.title=t.title;t.title='';t.innerHTML='';}
function ClickLink(e){if(!e)e=window.event;var from=e.currentTarget||e.fromElement||e.srcElement;if(e.altKey){var img=(from.tagName=='IMG'||from.tagName=='img')?from:from.childNodes[0];var matches=img.src.match(/\/([\w\-]{11})\.jpg$/i);if(matches&&matches[1]){location.href='http://passingpix.com/'+matches[1]+'.relink';if(e.preventDefault)
e.preventDefault();else
e.returnValue=false;return false;}}
else if(!e.shiftKey&&!e.controlKey){var a=(from.tagName=='A'||from.tagName=='a')?from:from.parentNode;var i=a.getElementsByTagName('img')[0];var matches=i.src.match(/http:\/\/passing(?:pix|pics|pictures).com\/tb\/([\w\-]{11})/);if(matches&&matches[1]){ShowPiP(matches[1]);return false;}}}
function RenderPiP(req){if(req.readyState==4){if(req.status==200){var pc=document.getElementById('_pipcontent');pc.innerHTML=req.responseText;}
else{alert('error');}}}
function ShowPiP(id){var p=document.getElementById('_pip');p.style.display='block';var req=new XMLHttpRequest();req.open('GET','http://passingpix.com/bin/1/'+id+'.html',true);req.onreadystatechange=function(ae){RenderPiP(req)};req.send(null);}
function HidePiP(){var p=document.getElementById('_pip');p.style.display='none';var pc=document.getElementById('_pipcontent');pc.innerHTML='';}
function SetupTitle(){var mosaic=document.getElementById('_mosaic');if(mosaic){if(!document.getElementById('_title')){t=document.createElement('div');t.id='_title';t.style.position='absolute';t.style.display='none';document.body.appendChild(t);}
if(!document.getElementById('_pip')){p=document.createElement('div');p.id='_pip';p.style.position='absolute';p.style.display='none';p.style.textAlign='center';p.innerHTML='<div class="streambox"><div style="text-align:right"><a href="#" onclick="HidePiP()"><strong>[close]</strong></a></div></div><div style="text-align:center"><div id="_pipcontent" style="display:block-inline"></div></div>';p.style.position='fixed';p.style.left='0';p.style.top='0';p.style.bottom='0';p.style.right='0';document.body.appendChild(p);}
var c=mosaic.getElementsByTagName('a');var isWatcher=document.location.href.match(/\.watch/);for(var i=0;i<c.length;i++){c[i].onmouseover=ShowTitle;c[i].onmouseout=HideTitle;if(!isWatcher)c[i].onclick=ClickLink;}}}
function PLoad(){SetupTitle();fadei=document.createElement('img');fadei.src='http://passingpix.com/g/fadeanim.gif';fadei.width=43;fadei.height=11;}
function PUnload(){FadeScreen();}
