function scriptsladen_onload() 
{ 
    MM_preloadImages('/shared/img/loading.gif');
    calc_sizes(); 
    correctPNG(); 
    alphaBackgrounds(); 
} 

function scriptsladen_onresize() 
{ 
    calc_sizes(); 
} 
		
window.onload = scriptsladen_onload;
window.onresize = scriptsladen_onresize; 
		
function MM_preloadImages() 
{
    var d=document; 
    if(d.images)
    { 
	if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
	for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0)
	    { 
	    	d.MM_p[j]=new Image; 
		d.MM_p[j++].src=a[i];
	    }
    }
}
		
function laden()
{
    document.getElementById('body_laden').className 			= 'body_laden_hidden';
}
function klaarmetladen()
{
    document.getElementById('body_laden').className 			= 'body_laden_normal';
    document.getElementById('laden_background').className 		= 'hide_display';
    document.getElementById('laden_content').className 			= 'hide_display';
}

function calc_sizes() 
{
    var windowname = window.name;
    var main_container_width = 950;
    var height_of_footer = 26;
    var paddingcontent_ALL = 10;
    if(document.getElementById("header"))
	var height_of_header = document.getElementById("header").clientHeight;
    else
	var height_of_header = 0;
    var kruimelpad_height = 20;
    var kruimelpad_width = main_container_width - (paddingcontent_ALL * 2);			
    var containerelement_small_height = 95;
    var containerelement_large_height = 240;
    var containerelement_small_width = 300;
    var containerelement_smaller_width = 250;
    var containerelement_large_width = 310;
    var hoofdscherm_width = 620;
    var div_small_height = 74;
    var div_large_height = 219;
    var buttons	= 24;

    // browser ophalen
    var non_IE 	= (typeof( window.innerWidth ) == 'number');
    var IE_6 = (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ));
    var IE_4 = (document.body && ( document.body.clientWidth || document.body.clientHeight ));
			
    if( non_IE ){
	//Non-IE vars
	bodywidth = window.innerWidth;
	bodyheight = window.innerHeight;
	paddingcontent_FF = 10;				
	borders_FF = 2;
	paddingcontent_IE = 0;
	borders_IE = 0;
	cursor = 'pointer';
    }else if( IE_6 ){
	//IE 6+ in 'standards compliant mode'
	bodywidth = document.documentElement.clientWidth;
	bodyheight = document.documentElement.clientHeight;
	paddingcontent_FF = 0;
	borders_FF = 0;
	paddingcontent_IE = 10;
	borders_IE = 2;
	cursor = 'hand';
    }else{
	//IE 4 compatible
	bodywidth = document.body.clientWidth;
	bodyheight = document.body.clientHeight;
	paddingcontent_FF = 0;
	borders_FF = 0;
	paddingcontent_IE = 10;
	borders_IE = 2;
	cursor = 'hand';
    }
    
    // voor allemaal gelijk (popup en gewone paginas)
    kruimelpad_height = kruimelpad_height - borders_FF;
    kruimelpad_height_inc = kruimelpad_height + (paddingcontent_ALL * 2) + (borders_FF * 2); // borders en paddings
    kruimelpad_width = kruimelpad_width - borders_FF;
    containerelement_small_height = containerelement_small_height - borders_FF;
    containerelement_large_height = containerelement_large_height - borders_FF;
    containerelement_small_width = containerelement_small_width - borders_FF;
    containerelement_large_width = containerelement_large_width - borders_FF;
    hoofdscherm_width = hoofdscherm_width - borders_FF;
    div_titel_height = kruimelpad_height - (1 + (borders_FF / 2));
    div_small_height = div_small_height - paddingcontent_FF;
    div_large_height = div_large_height - paddingcontent_FF;
    
    // cursor op de player buttons
    for (var i = 1; i<= 9; i++){
	if (document.getElementById("audioplayer_btn"+i)){
	    document.getElementById("audioplayer_btn"+i).style.cursor = cursor;
	}
    }

    if(document.getElementById("container_mediafragment"))
    {
	if(document.getElementById("content_container")){
	    document.getElementById("content_container").style.height 	=  (bodyheight-(height_of_footer+(paddingcontent_FF / 2)+borders_FF))+"px";
	    if(!non_IE){
		// another dirty IE hack, height of container -10px for footer visibility
		document.getElementById("content_container").style.height =  (bodyheight-(height_of_footer+(paddingcontent_FF / 2)+borders_FF)-10)+"px";
	    }
	}
	
	mfragmentHeight= bodyheight - (paddingcontent_ALL * 2) - height_of_header -  height_of_footer - borders_IE - borders_FF
	document.getElementById("container_mediafragment").style.height =  mfragmentHeight + "px";
	document.getElementById("container_mediafragment").style.width = bodywidth - (paddingcontent_ALL * 2) - borders_IE - borders_FF + "px";
					
	if(document.getElementById("header") && non_IE){
	    heightOfMarginPix=(bodyheight-height_of_footer-height_of_header-mfragmentHeight);
	    document.getElementById("container_mediafragment").style.marginTop = (heightOfMarginPix/2) + 'px';
	}
	if(document.getElementById("footer_popup")){
	    document.getElementById("footer_popup").style.width = bodywidth +'px';
	}else if(document.getElementById("footer")){
	    document.getElementById("footer").style.width = bodywidth +'px';
    	}
					
	height_container_mediafragment 	= document.getElementById("container_mediafragment").clientHeight; 
	height_container_titel 	= document.getElementById("mediafragment_titel").clientHeight; 
	document.getElementById("popuptekst").style.height  = height_container_mediafragment - buttons - height_container_titel - (borders_FF / 2) - (borders_IE / 2) + "px";
    }
}
	
function popup_content(name, type,  popupwidth, popupheight,opts)
{ 
    var leftstart = (screen.width/2) - (popupwidth/2);
    var topstart = (screen.height/2) - (popupheight/2);
    var properties = "width="+popupwidth+", height="+popupheight+", left="+leftstart+", top="+topstart+", toolbar=no, titlebar=no, title=0, location=no,scrollbars=yes,status=no,resizable=no";
    var popup = "/popup.php?i="+name+"&type="+type+'&'+opts;
    window.open(popup,'popup',properties);
}

function popupRaadsInfo(name, type,  popupwidth, popupheight,opts)
{ 
    var leftstart = (screen.width/2) - (popupwidth/2);
    var topstart = (screen.height/2) - (popupheight/2);
    var properties = "width="+popupwidth+", height="+popupheight+", left="+leftstart+", top="+topstart+", toolbar=no, titlebar=no, title=0, location=no,scrollbars=yes,status=no,resizable=no";
    var popup = "/popup.php?i="+name+"&type="+type+'&'+opts;
    window.open(popup,'popup',properties);
}


function hidestatus()
{
    window.status=''
    return true
}
if (document.layers)
    document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
		
document.onmouseover=hidestatus
document.onmouseout=hidestatus

function paginalink(theURL,winName) 
{
    window.open(theURL,winName);
}



//---------------------------------------------------------------------------------------------------------------------
// PNG FIX IE (YAIEH)
//---------------------------------------------------------------------------------------------------------------------

		var strGif = "/shared/img/spacer.gif"
		var strFilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader"
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
		
		function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
		{
		   var arVersion = navigator.appVersion.split("MSIE")
		   var version = parseFloat(arVersion[1])
		   if ((version >= 5.5 && version < 7) && (document.body.filters))
		   {
			  for(var i=0; i<document.images.length; i++)
			  {
				 var img = document.images[i]
				 var imgName = img.src.toUpperCase()
				 if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
				 {
					var imgID = (img.id) ? "id='" + img.id + "' " : ""
					var imgClass = (img.className) ? "class='" + img.className + "' " : ""
					var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
					var imgStyle = "display:inline-block;" + img.style.cssText 
					if (img.align == "left") imgStyle = "float:left;" + imgStyle
					if (img.align == "right") imgStyle = "float:right;" + imgStyle
					if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
					if (img.useMap)
					  {  
						 strAddMap = "<img style=\"position:relative; left:0px; top:-" + img.height + "px;"
						 + "height:" + img.height + "px;width:" + img.width +"\" "
						 + "src=\"" + strGif + "\" usemap=\"" + img.useMap 
						 + "\" border=\"" + img.border + "\">"
					  }
					var strNewHTML = "<span " + imgID + imgClass + imgTitle
					+ " style=\"" + " width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
					+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
					if (img.useMap) strNewHTML += strAddMap
					img.outerHTML = strNewHTML
					i = i-1
				 }
			  }
		   }    
		}
		
		function findImgInputs(oParent)
		{
		   var oChildren = oParent.children
		   if (oChildren)
		   {
			  for (var i=0; i < oChildren.length; i++ )
			  {
				 var oChild = oChildren(i)
				 if ((oChild.type == 'image') && (oChild.src))
				 {
					 var origSrc = oChild.src
					 oChild.src = strGif
					 oChild.style.filter = strFilter + "(src='" + origSrc + "')"
				 }
				 findImgInputs(oChild)
			  }
		   }
		}
		
		function alphaBackgrounds() // correctly handle PNG "BACKGROUNDCOLOUR" transparency in Win IE 5.5 or higher.
			{
			var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
			var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
			
			var div = document.getElementsByTagName("div");
			for (var i = 0; i< div.length; i++)
			{
				if (itsAllGood)
				{
					var bg = div[i].currentStyle.backgroundImage;
					if (bg.match(/\.png/i) != null)
					{
						var mypng = bg.substring(5,bg.length-2);
						div[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
						div[i].style.backgroundImage = "url('/shared/img/spacer.gif')";
					}
				}
			}			
		}

//---------------------------------------------------------------------------------------------------------------------
// EINDE PNG FIX
//---------------------------------------------------------------------------------------------------------------------



function switchMedia(newType)
{
    sendRequest('/shared/switchMedia.php?mediaPref='+newType,catchSwitchMedia);
}

function switchMediaNoReload(newType)
{
    streamPreference=newType;
    sendRequest('/shared/switchMedia.php?mediaPref='+newType,catchSwitchMediaNoReload);
}


function catchSwitchMedia(req)
{
    var text = req.responseText;
    window.location.reload();
}

function catchSwitchMediaNoReload(req)
{
    var text = req.responseText;
}


function swapEmbedNCOD(nr)
{
    if(document.getElementById('NCODEmbedTextfieldStr_'+nr+''))
    {
	if(document.getElementById('NCODEmbedTextfieldStr_'+nr+'').style.visibility=='' || document.getElementById('NCODEmbedTextfieldStr_'+nr+'').style.visibility!='visible')
	{
	    document.getElementById('NCODEmbedTextfieldStr_'+nr+'').style.visibility='visible';
	    document.getElementById('NCODEmbedTextfieldStr_'+nr+'').style.display='inline';
	}else{
	    document.getElementById('NCODEmbedTextfieldStr_'+nr+'').style.visibility='hidden';
	    document.getElementById('NCODEmbedTextfieldStr_'+nr+'').style.display='none';
	}
    }
}

function selectTxt(item)
{
    if(document.getElementById(item))
    {
	document.getElementById(item).focus();
	document.getElementById(item).select();
	
    }
}

function buildFlashObj(id,playerUrl,flashUrl,agendaId,key)
{
    start=getSecond(agendaId)+'.00';
        
/*
    objectStr= '<object width="305" height="235" data="'+playerUrl+'flowplayer.commercial-3.1.0.swf?0.45915264269259337" type="application/x-shockwave-flash">';
    objectStr+='<param name="movie" value="'+playerUrl+'flowplayer.commercial-3.1.0.swf?0.45915264269259337" />';
    objectStr+='<param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" />';
    objectStr+='<param name="flashvars" value=\'config={"key":"'+key+'","clip":{"url":"'+flashUrl+'","provider":"lighttpd","start":'+start+',"autoPlay":true},';
    objectStr+='"plugins":{"lighttpd":{"url":"'+playerUrl+'flowplayer.pseudostreaming-3.1.2.swf"},"controls":{"url":"'+playerUrl+'flowplayer.controls-3.1.0.swf",';
    objectStr+='"height":20,"fullscreen":false,"tooltipColor":"#456","tooltips":{"buttons":true,"pause":"Pauzeren","play":"Afspelen","fullscreen":"Volledig Scherm",';
    objectStr+='"fullscreenExit":"Terug naar normaal formaat","mute":"Geluid uit","unmute":"Geluid terug aan"},"backgroundGradient":[0,0],"background":"#000000",';
    objectStr+='"timeColor":"#FFFFFF","scrubber":true}},"logo":{"url":"http://www.notubiz.nl/shared/img/flowplayer_NBLOGO.png","top":20,"right":20,"opacity":1,"fullscreenOnly":true,';
    objectStr+='"displaytime":0,"linkUrl":"http://www.notubiz.nl"},"playlist":[{"url":"'+flashUrl+'","provider":"lighttpd","start":'+start+',"autoPlay":true}]}\' />';
    objectStr+='</object>';
*/

    objectStr= '<object width="305" height="235" data="'+playerUrl+'flowplayer.commercial-3.1.5.swf?0.45915264269259337" type="application/x-shockwave-flash">';
    objectStr+='<param name="movie" value="'+playerUrl+'flowplayer.commercial-3.1.5.swf?0.45915264269259337" />';
    objectStr+='<param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" />';
    objectStr+='<param name="flashvars" value=\'config={"key":"'+key+'",';
    //objectStr+='contextMenu: [{"Powered by NotuBiz" : function() {location.href = "http://www.notubiz.nl";}}],';
    objectStr+='"contextMenu": [{"Powered by NotuBiz"}],'; // : function() {location.href = "http://www.notubiz.nl";}}],';
    objectStr+='"clip":{"url":"'+flashUrl+'","provider":"rtmp","start":'+start+'},';
    objectStr+='"plugins":{"rtmp":{"url":"flowplayer.rtmp-3.1.3.swf","netConnectionUrl":"rtmp://flash2.notubiz.nl/nbvod"},"controls":{"url":"'+playerUrl+'flowplayer.controls-3.1.0.swf",';
    objectStr+='"height":20,"fullscreen":false,"tooltipColor":"#456","tooltips":{"buttons":true,"pause":"Pauzeren","play":"Afspelen","fullscreen":"Volledig Scherm",';
    objectStr+='"fullscreenExit":"Terug naar normaal formaat","mute":"Geluid uit","unmute":"Geluid terug aan"},"backgroundGradient":[0,0],"background":"#000000",';
    objectStr+='"timeColor":"#FFFFFF","scrubber":true}},"logo":{"url":"http://www.notubiz.nl/shared/img/flowplayer_NBLOGO.png","top":20,"right":20,"opacity":1,"fullscreenOnly":true,';
    objectStr+='"displaytime":0,"linkUrl":"http://www.notubiz.nl"}}\' />';
    objectStr+='</object>';

    if(document.getElementById(id))
    {
	document.getElementById(id).value=objectStr;
    }
    //alert(objectStr);
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}


function openInNewWindow() {
    var newWindow = window.open(this.getAttribute('href'), '_blank');
    newWindow.focus();
    return false;
}


function getNewWindowLinks() {

	if (document.getElementById && document.createElement && document.appendChild) {
		var links = document.getElementsByTagName('a');

		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (/\bnon\-target\b/.exec(link.className)) {
				link.onclick = openInNewWindow;
			}
		}

	}
}

addEvent(window, 'load', getNewWindowLinks);