

function playVid(vidId, noBlackout) {
	if (_vidPane==null) {
	    _vidPane=document.getElementById('vidPane');
        if (!_vidPane) {
	        var tbody = document.getElementsByTagName("body")[0];
            tnode = document.createElement('div');
            tnode.id='vidPane';
            tnode.className='vidFrame';
            tbody.appendChild(tnode);
            _vidPane=document.getElementById('vidPane');
            _vidPane.style.position='absolute';
            _vidPane.style.display='none';
            _vidPane.style.zIndex='100';
            _vidPane.style.backgroundColor='#fff';
            _vidPane.style.width='435px';
            _vidPane.style.height='372px';
            _vidPane.style.fontFamily='verdana';
            _vidPane.style.fontSize='11px';
        }

        _blackout=document.getElementById('blackout');

        if (!_blackout) {
	        tnode = document.createElement('div');
            tnode.id='blackout';
            tbody.appendChild(tnode);
            _blackout=document.getElementById('blackout');
            _blackout.style.position='absolute';
            _blackout.style.display='none';
            _blackout.style.left='0px';
            _blackout.style.top='0px';
            _blackout.style.backgroundColor='#000';
            _blackout.style.opacity='.9';
            _blackout.style.filter='alpha(opacity=90)';
            _blackout.style.zIndex='50';
		}

        _vidPane.style.top='75px';
        _vidPane.style.left='75px';
	}

	if (vidId==null) { 
        _vidPane.style.display='none';
        _vidPane.innerHTML='';
        _blackout.style.display='none';
    } else {
		vidId=vidId.href;

        if (!noBlackout) {
	        _blackout.style.width='100%';
            _blackout.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
            _blackout.style.display='block';
        } else {
            _blackout.style.display='none';
        }
        
		var vidInfo = vidId.split('/');
              
        var vidstring ='<center><embed style="margin-top: 5px;"';  
        vidstring+=' enableJavascript="false" allowScriptAccess="never"';
        vidstring+=' allownetworking="internal" type="application/x-shockwave-flash"';
        vidstring+=' wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" ';

        if (vidInfo[2].indexOf('youtube.com')>=0) {
        	vidInfo=vidId.match(/v=.+$/);
           	vidInfo=String(vidInfo).replace(/v=/g,'');
           	vidstring+=' src="http://www.youtube.com/v/'+vidInfo+'?fs=1&autoplay=1" ';
           	vidstring+=' height="350" width="425" allowfullscreen="true"></embed></center>';
        } else if (vidInfo[2].indexOf('metacafe.com')>0) {
          	vidInfo=vidId.match(/watch.+$/);
          	vidInfo=String(vidInfo).replace(/watch./,'');
           	vidInfo=String(vidInfo).replace(/.$/,'');
           	vidstring+=' flashVars="playerVars=autoPlay=yes" ';
           	vidstring+=' src="http://www.metacafe.com/fplayer/'+vidInfo+'.swf" ';
           	vidstring+=' width="400" height="345" allowfullscreen="true">';  
           	vidstring+='</embed></center>';
		} else if (vidInfo[2].indexOf('dailymotion.com')>=0) {
           	vidInfo=vidId.match(/video.+$/);
			vidInfo2=vidId.match(/_.+$/);
            vidInfo=String(vidInfo).replace(/video./,'');
            vidInfo=String(vidInfo).replace(vidInfo2,'');
			vidstring+=' src="http://www.dailymotion.com/swf/video/'+vidInfo+'?&autoPlay=1&start=" flashVars="autoStart=1" ';
           	vidstring+=' allowFullScreen="true" height="350" width="425">';
           	vidstring+='</embed></center>';
        } else if (vidInfo[2].indexOf('video.yahoo.com')>=0) {
           	vidInfo=vidId.match(/watch.+$/);
          	vidInfo=String(vidInfo).replace(/watch./,'');
		 	var vidtemp = new Array();
		  	vidtemp = vidInfo.split('/');
		  	vidstring+=' src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf" ';
           	vidstring+=' allowFullScreen="true" height="350" width="425" flashVars="id='+vidtemp[1]+'&vid='+vidtemp[0]+'&lang=en-us&intl=us&autoPlay=1">';
           	vidstring+='</embed></center>';
        } else if (vidInfo[2].indexOf('vimeo.com')>=0) {
           	vidInfo=vidId.match(/[0-9].+$/);
           	vidstring+=' src="http://vimeo.com/moogaloop.swf?clip_id='+vidInfo+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" ';
           	vidstring+=' height="350" width="425" allowfullscreen="true"></embed></center>';
        } else {
           	vidstring += '></embed><BR><BR><BR>Unsupported Video Source.</center>';
        }
            
		vidstring+= '<div style="background:#fff;text-align:right;padding:10px 5px 10px 5px"><A HREF="'+vidId+'" target="_blank"><strong>VIDEO LINK</strong></A> &nbsp;|&nbsp; <A style="color=#555" HREF="#" onClick="return(playVid())"><strong>CLOSE X</strong></A><div>';  
        _vidPane.innerHTML=vidstring;
            
		var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop)
	      	scrollTop = document.documentElement.scrollTop;
        else if (document.body)
	        scrollTop = document.body.scrollTop
            
		_vidPane.style.top=scrollTop+100+'px';
		_vidPane.style.left=((document.body.clientWidth/2)-200)+'px';
        _vidPane.style.display='block'; 
	}
	return(false);
}

function moveHandler(e){
	if (e == null) { e = window.event }
    	if ( _dragOK ){
        	_savedTarget.style.left=e.clientX-_dragXoffset+'px';
            _savedTarget.style.top=e.clientY-_dragYoffset+'px';
            return false;
        }
}
      
function cleanup(e) {
	document.onmousemove=null;
    document.onmouseup=null;
  	_savedTarget.style.cursor=_orgCursor;
    _dragOK=false;
}
      
function dragHandler(e){
    var cursorType='-moz-grabbing';
    if (e == null) { e = window.event; cursorType='move';}
	    var target = e.target != null ? e.target : e.srcElement;
        if (target.className=="vidFrame") {
			_orgCursor=target.style.cursor;
			_savedTarget=target;
			target.style.cursor=cursorType;
			_dragOK=true;
			_dragXoffset=e.clientX-parseInt(_savedTarget.style.left);
			_dragYoffset=e.clientY-parseInt(_savedTarget.style.top);
			document.onmousemove=moveHandler;
			document.onmouseup=cleanup;
			return false;
		}
}

document.onmousedown=dragHandler;

var _savedTarget=null;
var _orgCursor=null;
var _dragOK=false;
var _dragXoffset=0;
var _dragYoffset=0;
var _vidPane = null;
var _blackout= null;
