var _doc = document;
var xPos, yPos;
var dragObj,dragX,dragY,dragZ=1;
var	nrSteps = 10;
var popupEl = null;

var tempX = 0;
var tempY = 0;
var podURL = '';

var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = function(event){ getMPos(event) };

function getMPos(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  return true
}

function sX(e,x){e.style.left=x+'px'}
function sY(e,y){e.style.top=y+'px'}
function sW(e,w){e.style.width=w+'px'}
function sH(e,h){e.style.height=h+'px'}
function wH(e,h){e.innerHTML=h}


function sizePopupSendAFriend(left,top,width,height,step) {
	// New and improved: with slomogrow effect!
	var html, mouse;

	width = width + 12;	
	height = height + 12;

	left = left -2;
	top = top -1;
	sX(popupEl, left);
	sY(popupEl, top);

	sW(popupEl, width);
	sH(popupEl, height);

	if (width < 400) {
		setTimeout("sizePopupSendAFriend("+left+","+top+","+width+","+height+","+(step-1)+")",0);
	} else {
		temp = '<div class="content"><h5>Mail dit artikel<span><a href="#"><img src="/gfx/jeugdjournaal/btn_pop_infobox_close.gif" width="21" height="21" border="0" alt="sluiten" title="sluiten" onclick="deleteThis()"/></a></span></h5>';
		temp = temp + '<iframe frameborder="0" width="350" height="200" src="http://cgi.nos.nl/cgi/nosrtv/mail/maileenvriend/mailscript_jj.php?url=' + podURL + '" class="mailframe"></iframe>';
		temp = temp + '</div>'; 
		popupEl.innerHTML = temp;
	};
}

function dragStart(e,el) {
	if (!e)e= window.event;
	dragObj = el;
	dragObj.style.zIndex = dragZ++;
	dragX = e.clientX - dragObj.offsetLeft;
	dragY = e.clientY - dragObj.offsetTop;
	_doc.onmousemove=dragMove;
	_doc.onselectstart=function(){return false};
}

function dragMove(e) {
	if (!e)e=window.event;
	if(dragObj) {
		sX(dragObj,e.clientX - dragX);
		sY(dragObj,e.clientY - dragY);
	}
}

function mUp() {
	dragObj = null;
}

function deleteThis() {
	if (popupEl) {
		var code = '_doc.body.removeChild(popupEl);popupEl=null;'
		eval(code);
	};
	document.onmousemove = function(event){ getMPos(event) };
}

function cPopUpSendAFriend(url) {	
	if (!popupEl) {
		podURL = url;
		popupEl = _doc.createElement('div');
		popupEl.className = 'pop_sendafriendbox';
//		popupEl.onmousedown=function(event){ dragStart(event,this) };
//		popupEl.onmouseup=function(event) { mUp() };
//		popupEl.onmouseclick=function(event) { mUp() };
		
		_doc.body.appendChild(popupEl);	
		
		popupEl.style.left	= '10px';
		popupEl.style.top	= '10px';

		popupEl.innerHTML = '<div class="content"></div>';
		sizePopupSendAFriend(tempX-100,tempY-150,200,40,10);
	};
};	