var _W=window,_D=document,popupEl,nrSteps=1,dragObj,dragX,dragY,dragZ=1,close_n=new Image(13,13),close_h=new Image(13,13),xmlhttp=false;
_D.onmouseup=function(){try{dragObj=_D.onselectstart=_D.onmousemove=null}catch(e){}};

// Preload all rollover images
var ro = ['button_abonneer_ro.png','button_download_ro.png','button_speelaf_ro.png','ga_ro.gif','live_ro.png','play_blue_ro.gif','play_white_ro.gif','rss_ro.png','terugnaarhome_ro.gif','webkanalen_ro.png'];
function _init() {
	for (x in ro) {
		var tmp = new Image;
		tmp.src = '/pics/' + ro[x];
	}
}

//close_h.src = '/pics/close_hi.gif';
//close_n.src = '/pics/close.gif';

function sniff(){
	var t=this,T=true,F=false,n=navigator,ua=n.userAgent.toLowerCase();
	t.ver=parseInt(n.appVersion);
	t.mac=ua.indexOf('mac')!=-1;
	t.win=!t.mac&&ua.indexOf('wind')!=-1||ua.indexOf('16bit')!=-1;
	t.safari=ua.indexOf('safari')!=-1&&t.mac;
	t.konq=ua.indexOf('konqueror')!=-1;
	t.khtml=t.safari||t.konq;
	t.opera=_W.opera?T:F;
	t.opera5=ua.indexOf('opera 5')!=-1||ua.indexOf('opera/5')!=-1;
	t.opera6=ua.indexOf('opera 6')!=-1||ua.indexOf('opera/6')!=-1;
	t.opera7=t.opera&&_D.createComment?T:F;
	t.ie5=t.ie55=t.ie6=F;
	t.ie=_D.all&&!t.opera&&ua.indexOf('msie')!=-1?T:F;
	if(t.ie){
		t.ieBox=_D.compatMode!='CSS1Compat';
		t.ie5=!_D.fireEvent?T:F;
		t.ie55=_D.fireEvent&&!_D.createComment?T:F;
		t.ie6=_D.fireEvent&&_D.createComment?T:F
	}
	t.gecko=!t.khtml&&!_D.all&&!t.opera&&_D.getElementById?T:F;
	t.ns4=n.appName=='Netscape'&&t.ver==4
}
var is=new sniff(),op=is.opera;
function gE(e){if(_D.getElementById)return _D.getElementById(e);if(_D.all)return _D.all[e]}
function sE(e){e.style.visibility='visible'}
function hE(e){e.style.visibility='hidden'}
function SE(e){e.style.display=''}
function HE(e){e.style.display='none'}
function sX(e,x){op?e.style.pixelLeft=x:e.style.left=x+'px'}
function sY(e,y){op?e.style.pixelTop=y:e.style.top=y+'px'}
function sW(e,w){op?e.style.pixelWidth=w:e.style.width=w+'px'}
function sH(e,h){op?e.style.pixelHeight=h:e.style.height=h+'px'}
function wH(e,h){e.innerHTML=h}

function getWinSize(what) {
	if (what == 'height')
		return (is.ie) ? (is.ieBox) ? _D.body.clientHeight : _D.documentElement.clientHeight : _W.innerHeight;
	if (what == 'width')
		return (is.ie) ? (is.ieBox) ? _D.body.clientWidth : _D.documentElement.clientWidth : _W.innerWidth;
}

function makePopup(e, width, height, title, url) {
	killPopup();
	
	var objOverlay = document.getElementById('overlay');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = ((arrayPageSize[1] + 20) + 'px');
	objOverlay.style.display = 'block';

	// Disable select-boxes.
   var x, n, v, f, sels;
   if (is.ie && !is.ie7) {
      sels = _D.getElementsByTagName('select');
      for(x in sels) {
         n = sels[x].name, v = sels[x].value, f = sels[x].form;
         if (n && f) {
            f.insertAdjacentHTML('beforeEnd', '<input type="hidden" name="'+n+'" value="'+v+'" />');
         }
         if (sels[x] && sels[x].style) sels[x].style.visibility='hidden';
      }
   }

	height += 24;
	var wh = getWinSize('height'), ww = getWinSize('width'), st, sl;
	if (!e) {
		e = new Object();
		e.clientX = ww/2-width/2;
		e.clientY = wh/2-height/2;
	}
	var top = e.clientY, left = e.clientX;
	if (is.ie) {
		sl = (is.ieBox) ? _D.body.scrollLeft : _D.documentElement.scrollLeft;
		st = (is.ieBox) ? _D.body.scrollTop  : _D.documentElement.scrollTop;
	}
	else {
		sl = _W.pageXOffset;
		st = _W.pageYOffset;
	}
	if (e.clientX + width > ww)
		left = ww-width-5;
	if (e.clientY + height > wh)
		top = wh-height-5;

	popupEl = _D.createElement('div');
	popupEl.style.zIndex = 99;
	popupEl.id = 'popup';
	popupEl.className = 'popup';
	_D.body.appendChild(popupEl);
	sizePopup(title,url,left+sl,top+st,width,height,nrSteps);
}

function sizePopup(title,url,left,top,width,height,step) {
	// New and improved: with slomogrow effect!
	var html, mouse;
	if (step < 0) {
		html  = '<div style="float:left; width: 5px; height: 5px;"><img src="/pics/ned3/popup_corner_lt.gif" width="5" height="5" alt="" /></div>';
		html += '<div style="float:left; width: '+(width-10)+'px; height: 5px; background: #488215; font-size: 1px;"></div>';
		html += '<div style="float:left; width: 5px; height: 5px;"><img src="/pics/ned3/popup_corner_rt.gif" width="5" height="5" alt="" /></div>';
		html += '<div id="popupContainer">';
		html += '<div class="popupCaption">';
		html += '<div class="popupTitle">' + title + '</div>';
		html += '<div class="popupClose" onclick="killPopup();">sluit venster</div>';
		html += '</div>'; // einde popupCaption
		html += '<iframe frameborder="0" src="'+url+'" style="width:'+(width-10)+'px;height:'+(height-36)+'px;" scrolling="no"></iframe>';
		html += '</div>' // einde popupContainer
		html += '<div style="float:left; width: 5px; height: 5px;"><img src="/pics/ned3/popup_corner_lb.gif" width="5" height="5" alt="" /></div>';
		html += '<div style="float:left; width: '+(width-10)+'px; height: 5px; background: #488215; font-size: 1px;"></div>';
		html += '<div style="float:left; width: 5px; height: 5px;"><img src="/pics/ned3/popup_corner_rb.gif" width="5" height="5" alt="" /></div>';
		
		wH(popupEl, html);
		return;
	}
	sX(popupEl, left + step*width/nrSteps/2);
	sY(popupEl, top + step*height/nrSteps/2);
	sW(popupEl, width - step*width/nrSteps);
	sH(popupEl, height - step*height/nrSteps + (is.safari?2:0));
	setTimeout("sizePopup('"+title+"','"+url+"',"+left+","+top+","+width+","+height+","+(step-1)+")",0);
}

function killPopup() {
	if (popupEl) {
		var code = '_D.body.removeChild(popupEl);popupEl=null;';
		eval(code);
	}
	
	// Enable select-boxes.
   var x, n, v, f, sels;
   if (is.ie) {
      sels = _D.getElementsByTagName('select');
      for(x in sels) {
         n = sels[x].name, v = sels[x].value, f = sels[x].form;
         if (n && f) {
            f.insertAdjacentHTML('beforeEnd', '<input type="hidden" name="'+n+'" value="'+v+'" />');
         }
			if (sels[x] && sels[x].style) sels[x].style.visibility='visible';
      }
   }

	gE('overlay').style.display = 'none';
}

function dragStart(e,el) {
	if (!e)e=_W.event;
	dragObj = el;
	dragObj.style.zIndex = dragZ++;
	dragX = e.clientX - dragObj.offsetLeft;
	dragY = e.clientY - dragObj.offsetTop;
	_D.onmousemove=dragMove;
	_D.onselectstart=function(){return false};
}

function dragMove(e) {
	if (!e)e=_W.event;
	if(dragObj) {
		sX(dragObj,e.clientX - dragX);
		sY(dragObj,e.clientY - dragY);
	}
}

/*@cc_on @*/
/*@if(@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch(e) {
			xmlhttp = false;
		}
	}
@else
	var xmlhttp = false;
@end @*/
if(!xmlhttp && document.createElement) {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch(e) {
		xmlhttp = false;
	}
}

/*
	Returns array with x,y page scroll values.
	Code from quirksmode.org
*/
function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

/*
	Returns array with page width, height and window width, height
	Code from - quirksmode.org
	Edit for Firefox by pHaez
*/
function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function testLink(inId) {
	if (document.getElementById(inId).value != "") {
		window.open(document.getElementById(inId).value, '_blank');
	}
	return false;
}	