<!--
/* Any Video in Post (header portion)- Eton Bones*/
/* last updated: 7/27/2008  (rev 9) */
var caller=[];
var vidType={	
	_Globals:{
		defaultType:'Embed',
		params:{allowfullscreen:true, allowscriptaccess:'always', pluginspage:'http://www.macromedia.com/go/getflashplayer', type:'application/x-shockwave-flash', classid:'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000', quality:'autohigh', codebase:'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab', wmode:'transparent'},
		maxVidsPerPost:100,
		maxVidsPerPage:300,
		defaultWidth:'720px',
		defaultHeight:'480px',
		canPost:'-Guest',
		//canView:'-Guest',
		autoLink:'YouTube'
	},
	Embed:{
	prefix:'%video%',
	checkid:function(vid){  if(/<(object|embed)\b/im.test(deEntify(vid)) /*&& /\.swf\b/i.test(vid)*/)return true; else return false;},
	postprocess: function(ret){
		var w=vidType['Embed'].maxwidth; var h=vidType['Embed'].maxheight
		ret=deEntify(caller[caller.length-1].arguments[2])
		if(!/width=\d+/i.test(caller[caller.length-1].arguments[0].split(/\]/)[0]))w=0
		if(!/height=\d+/i.test(caller[caller.length-1].arguments[0].split(/\]/)[0]))h=0
		ret=ret.replace(/(width|height)=['"]?(\d+)/gi,function(m,p1,p2){
			if(/width/i.test(p1)&&w>0){
				m=m.replace(/width=('|")\d+/i,'width=$1'+w)
			}else if(/height/i.test(p1)&&h>0){
				m=m.replace(/height=('|")\d+/i,'height=$1'+h)
			}
			return m;
		})
		//disable all SWF browser navigation and browser interaction APIs to avoid possible popups
		if(/\ballownetworking\b/i.test(ret))			
			ret=ret.replace(/(value|allownetworking)=('|")all['"]/gim, "$1=$2internal$2");			
		else
			ret=ret.replace(/<embed\s/gi,'<embed allownetworking="internal" ').replace( /<param\s/i,'<param name="allownetworking" value="internal"/><param ');		
		
		return String('<div name="swfPlayer">'+ret)
	},
	preprocess:function(vType,vURI){		
		//attempt to fix Proboards' hard wraps
		vURI=pb_unwrap(vURI) 
		//allow only specific HTML tags
		vURI = vURI.replace(/&(nbsp);?/gi,' ').replace(/&(quot);?/gi,'"').replace(/(<|&l{1}t;?)\s*(\/?\w+)/gi,function(m,p1,p2,i,s){
			p1=''; 
			if(p2.substr(0,1)=='/'){p1='/';p2 = p2.substr(1)}
			p2=p2.toLowerCase()
			if(p2== 'embed'){
				var t = s.substr(i).split(/>/)[0];
				if(t.match(/type\s*=\s*['"]?([^'"\s]+)/))					
				{if(!/shockwave-flash/i.test(RegExp.$1))return '&#'+'60;' + p1 + p2}							
			}else if( p2.match(/^(param|object)$/)){
				return '<font></font'
			}else if( p2.match(/^(table|tr|td|thead|tbody|tfoot|th|center)$/)){				
			}else if( p2.match(/^(font|a|span|div|img|br|b|i|u|s|hr)$/)){				
			}else{
				return '&#'+'60;' + p1 + p2
			}
			return m
		});
		//disable possible script handlers
		vURI=vURI.replace(/\bon(\w+)=/gi,'no$1=').replace(/javascript\:/gi,'pbscript:')
		caller[caller.length-1].arguments[2]= vURI
	},
	description:'Embed Code'
	},
	AnySWF:{
		prefix:'%video%', 
		description:'Generic SWF Player',
		maxwidth:'425px',
		maxheight:'350px',		
		params:{flashvars:_getFlashVars},
		checkid:function(vid){return /\.swf(\?|\s*$)/i.test(vid)}
	},
	AnyFLV:{
		prefix:'http://www.jeroenwijering.com/embed/mediaplayer.swf?file=%video%',
		description:'Generic FLV Player',
		maxwidth:'720px',
		maxheight:'350px',
		custom:{skinall:'&displayheight=%height%&displaywidth=%width%',skin1:'&lightcolor=0x000000&backcolor=0x334455&frontcolor=0x666666&screencolor=0xFFFFFF'},
		params:{flashvars:_getFlashVars},
		preprocess:function(vType,vURI){this['flashvars']=((this['flashvars'])?this['flashvars']:'');this.flashvars=this.flashvars.replace(/%height%/gi,parseInt(this.maxheight)).replace(/%width%/gi,parseInt(this.maxheight));if(vURI.match(/\.(flv|mp4|m4v|m4a|3gp|mov|f4v|f4p|f4a|f4b)(\?|\s*$)/i))this.flashvars+='&type='+RegExp.$1;},
		checkid:function(vid){return /\.(flv|mp4|m4v|m4a|3gp|mov|f4v|f4p|f4a|f4b|xml|asx)(\?|\s*$)/i.test(vid)}
	},
	WMP:{
		prefix:'%video%',
		description:'Windows Media Player',		
		example:'http://etonbones.proboards100.com/index.cgi?board=examples&action=display&thread=18',
		params:{CLASSID:'clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6', invokeurls:0, autostart:0,playcount:1, name:'mediaplayer1',CODEBASE:'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',pluginspage:'http://www.microsoft.com/Windows/MediaPlayer/',type:'application/x-mplayer2'}		
	},
	Quicktime:{
		prefix:'%video%',		
		example:'http://etonbones.proboards100.com/index.cgi?board=examples&action=display&thread=17',
		params:{CLASSID:'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B', autoplay:0 , name:'quicktimeplayer1', CODEBASE:'http://www.apple.com/qtactivex/qtplugin.cab',pluginspage:'http://www.apple.com/quicktime/download',type:'video/quicktime'}
	},
	Real:{
		description:'Real Player',
		prefix:'%video%',		
		example:'http://etonbones.proboards100.com/index.cgi?board=examples&action=display&thread=15',
		preprocess:function(vType,vURI){if(!vURI.match(/\?embed$/i))caller[caller.length-1].arguments[2]+='?embed'},
		postprocess:function(ret){
			//real player requires separate controls for vid and control panel
			ret+='<br><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" '+ret.match(/width=[^\s]+/)[0]+' '+ ' height="36" >'
			ret+='<param name="controls" value="ControlPanel">';
			ret+='<param name="console" value="vidplayer">';					
			ret+=ret.match(/\<embed[\w\W]+?<\/embed>/im)[0].replace(/controls="ImageWindow"/,'controls="ControlPanel"').replace(/height=".+?"/,'height="36"')
			ret + '></object>'
			return ret
		},
		params:{CLASSID:'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA', autogotourl :0 , autostart :0, controls:'ImageWindow', console:'vidplayer', pluginspage:'http://www.real.com/', /*type:'audio/x-pn-realaudio-plugin'*/type:'application/vnd.rn-realplayer'}
	},
	VLC:{
		prefix:'%video%',
		description:'VideoLAN (VLC)',		
		params:{CLASSID:'clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8',CODEBASE:'http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab',pluginspage:'http://www.videolan.org',type:'application/x-vlc-plugin'}
	}
	
}

function aV(video){
	video=(video)?video:vidType._Globals.defaultType
	add("[video=", "[/video]", video);
}
function _getFlashVars(){	
	var vType=caller[caller.length-1].arguments[1];
	var a=prefix.split(/\?/);
	prefix=a[0]; if(a.length==1)a.push('')
	if(vidType[vType]['flashvars']){ a[1]+=((a[1].length)?'&':'')+vidType[vType]['flashvars']; }
	return a[1]
}
function deEntify(sStr){
	return sStr.replace(/&am{1}p;/gi,"&").replace(/&l{1}t;/gi,"<").replace(/&g{1}t;/gi,">")
}
function pb_unwrap(sStr){return sStr.replace(/([^\s\n\r]{111,})(\s|%20)/gm,'$1')}
function trim(sStr){
	return sStr.replace(/(^\s+|\s+$)/g,'')
}

function isAllowed(users,user){
	if(!vidType._Globals[users])return true
	var u=vidType._Globals[users]
	u=u.split(/,/).sort().reverse().join('|')
	var v=u.indexOf('-')
	if(v>-1){
		if(RegExp('^('+u.substr(v).replace('-','')+')$').test(user))return false;
		u=u.substr(0,v).replace(/|$/,'')
	}
	if(u.length){
		if(RegExp('^('+u+')$',"i").test(user))return true;
		return false; 
	}else{ return true;}
}

function disableVideo(vid,link,title){
	title=(title)?title:''
	var ret='<a href="javascript:void(0)" onClick="enableVideo(this)" title="'+title+'">'
	ret+=link+'</a><xm'+'p style="display:none;">'+ vid +'</xm'+'p>'
	return ret
}
function enableVideo(thiss){	
	var v=document.createElement('div');
	v.innerHTML=deEntify(thiss.nextSibling.innerHTML);
	thiss.parentNode.replaceChild(v.firstChild,thiss.nextSibling);
 	thiss.style.display="none"
}
function makeEmbed(m,vType,vURI){
	var params=''; var attribs=null;
	if(mTD[i].getElementsByTagName('a').length<((window['pb_VersionNo'])?2:1) && !isAllowed('canPost','Guest')) return '<DIV>Guests are not allowed to post videos</DIV>'
	if(mTD[i].getElementsByTagName('a').length>((window['pb_VersionNo'])?2:1) && mTD[i].getElementsByTagName('a')[((window['pb_VersionNo'])?2:1)].href.match(/user=(\w+)/) && !isAllowed('canPost',RegExp.$1)) 
		return '<DIV>'+mTD[i].getElementsByTagName('a')[((window['pb_VersionNo'])?2:1)].innerHTML + ' is not allowed to post videos</DIV>'
	if(vidType._Globals['boards'] && !vidType._Globals['boards'].match(/\bmain\b/i))vidType._Globals['boards']+=",main";
	if(!isAllowed('boards',((document.getElementsByName('board').length)?document.getElementsByName('board')[0].value:'main'))) return m;
	if(!vType)vType=vidType._Globals.defaultType;
	if(!/^Embed\b/.test(vType) && vURI.match(/href=['"]?([^\s'">]+)/i))vURI=RegExp.$1;
	//if(/\<\s*(embed|object)/i.test(m))return m
	if(/,/.test(vType)){attribs=trim(deEntify(vType.substr(vType.indexOf(',')+1)));vType=trim(vType.split(/,/)[0]);}				
	if(!vidType[vType]) return m;
	if('checkid' in vidType[vType]) if(!vidType[vType].checkid(vURI)) return m;
	caller.push(arguments.callee) //opera+safari don't support arguments.callee.caller
	if(!vidType[vType]['maxwidth'])vidType[vType].maxwidth=vidType._Globals.defaultWidth;
	if(!vidType[vType]['maxheight'])vidType[vType].maxheight=vidType._Globals.defaultHeight;
	prefix=vidType[vType].prefix
	if(attribs){
		vidType[vType].maxwidth=(/width=([^,]+)/i.test(attribs) && parseInt(RegExp.$1)<=parseInt(vidType[vType].maxwidth))?RegExp.$1:vidType[vType].maxwidth;
		vidType[vType].maxheight=(/height=([^,]+)/i.test(attribs) && parseInt(RegExp.$1)<=parseInt(vidType[vType].maxheight))?RegExp.$1:vidType[vType].maxheight;		
		if(attribs.match(/flashvars=([^,]+)/i)){if(/\?/.test(prefix))prefix+='&'; else prefix+='?'; prefix+=trim(attribs.match(/flashvars=([^,]+)/i)[1])}
	}				
	if("custom" in vidType[vType]){
		if(!('flashvars' in vidType[vType]))vidType[vType].flashvars='';
		if('skin'+pb_skinid in vidType[vType].custom)vidType[vType].flashvars+=((vidType[vType].flashvars.length && vidType[vType].custom['skin'+pb_skinid].substr(0,1)!='&')?'&' + vidType[vType].custom['skin'+pb_skinid]:vidType[vType].custom['skin'+pb_skinid])
		if('skinall' in vidType[vType].custom)vidType[vType].flashvars+=((vidType[vType].flashvars.length && vidType[vType].custom['skinall'].substr(0,1)!='&')?'&'+ vidType[vType].custom['skinall']:vidType[vType].custom['skinall'])
	}
	if("preprocess" in vidType[vType])vidType[vType].preprocess(vType,vURI)
	prefix=prefix.replace(/%video%/g,vURI)
	var ret='<div name="swfPlayer"><OBJECT width="'+ vidType[vType].maxwidth + '" height="'+ vidType[vType].maxheight + '" data="'+prefix.replace(/%video%/,vURI).split('?')[0]+'" standby="Loading player components..." >'
	ret+= '<PARAM name="movie" value="'+prefix + '" />';
	ret+= '<PARAM name="url" value="'+prefix + '" />';
	ret+= '<PARAM name="src" value="'+prefix + '" />';
	if("params" in vidType[vType]){
		for(var v in vidType[vType].params){
			var ret1=("function"==typeof vidType[vType].params[v])?vidType[vType].params[v]():vidType[vType].params[v]
			if(!/^pluginspage$/.test(v)){
				if(!/^(classid|codebase)$/i.test(v))
					ret+= '<PARAM name="'+v + '" value="'+ ret1 + '" />';
				else
					ret=ret.replace(/<OBJECT\s/i,'<OBJECT '+v+'="'+ret1+'" ')
			}
			if(!/^(classid|codebase)$/i.test(v)){							
				params+= v + '="'+ ret1 + '" ';
			}
		}
	} 
	for(var u in vidType._Globals.params){
		if(!ret.match(new RegExp('name="'+ u +'"','i')) && !ret.match(new RegExp( u +'="','i')) && !params.match(new RegExp( u +'="','i'))){
			var ret2=("function"==typeof vidType._Globals.params[u])?vidType._Globals.params[u]():vidType._Globals.params[u]
			if(!/^pluginspage$/.test(u)){							
				if(!/^(classid|codebase)$/i.test(u))
					ret+= '<PARAM name="'+ u + '" value="'+ ret2 + '" />';
				else
					ret=ret.replace(/<object\s/i,'<OBJECT '+u+'="'+ret2+'" ')
			}
			if(!/^(classid|codebase)$/i.test(u))
			params+= u + '="'+ ret2 + '" ';
		}
	}
	ret= '<div name="swfPlayer">' //7/4/08  abandon twice cooked embedding for <embed> alone
	ret+= '<embed src=\042'+ prefix.replace(/%video%/,vURI) 
	ret+= '\042 width="'+ vidType[vType].maxwidth + '" height="'+ vidType[vType].maxheight + '" '+ params
	ret+= ' id="_'+perPage+'"></embed>' //</object>' 
	
	
	if('postprocess' in vidType[vType])ret=vidType[vType].postprocess(ret)
	ret+='</div>'
	perPost++;
	if(!isLink && (vidType._Globals.maxVidsPerPost<perPost || vidType._Globals.maxVidsPerPage<perPage || (attribs && attribs.match(/disabled?=(true|[1-9])/i))))
	ret=disableVideo(ret,'<div style="text-align:center;line-height:30px;width:'+vidType[vType].maxwidth+';height:'+vidType[vType].maxheight+';" class="bordercolor" ><br><br>This video has been disabled to save bandwidth.<br> Click to enable</div>')
	else
	perPage++; caller.pop();
	return ret
}
//-->
