var intervalID;
var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

function artWork() {
  if(!isIE6){
	breedte = getWidth();
	
	avBreedte = (Math.round(breedte/2));
	opgeteld = avBreedte*2;

	if(navigator.userAgent.indexOf('MSIE')>-1){
		document.getElementById('bck_right').style.width = (avBreedte-1) + 'px';	
	}

	document.getElementById('bck_left').style.background = 'url(http://weblogs.nos.nl/wp-content/themes/nos/gfx/bck_artwork_l.gif) right no-repeat';	
	document.getElementById('bck_right').style.background = 'url(http://weblogs.nos.nl/wp-content/themes/nos/gfx/bck_artwork_r.gif) left no-repeat';	
	contenthoogte = document.getElementById('container').offsetHeight+150;
	document.getElementById('bck').style.height = contenthoogte + 'px';
	}

	
}

function check_artWork() {
	intervalID = setInterval("run_artWork()", 10);
}

function run_artWork() {
  clearInterval(intervalID);
  artWork();
}

function getWidth() {
  if(!isIE6){
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		return frameWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		return frameWidth;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		return frameWidth;
	}
	else return;
	}
}


function addEvent( obj, type, fn ) {
  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] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

addEvent(window,"resize",artWork);

function fillBackground() {
  if(!isIE6){
	hoogte = document.getElementById('container').offsetHeight;
	document.getElementById('bck').style.height = hoogte + 'px';
 }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function sitestat(ns_l) {
	ns_l+="&ns__t="+new Date().getTime();ns_pixelUrl=ns_l;
	ns_0=top.document.referrer;
	ns_0=(ns_0.lastIndexOf("/")==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf("/"),0):ns_0;
	if(ns_0.length>0)ns_l+="&ns_referrer="+escape(ns_0);
	if(document.images) {
		ns_1=new Image();ns_1.src=ns_l;
	} else
	document.write("<img src="+ns_l+" width=\"1\" height=\"1\" />");
}

function callSifr(){
	if(typeof sIFR == "function"){
						sIFR.replaceElement("#pagtitel h1" , named({sFlashSrc: "http://weblogs.nos.nl/wp-content/themes/nos/sifr/sifr.swf", sColor: "#ffffff", sWmode: "transparent"}));
						sIFR.replaceElement("#pagtitel h2" , named({sFlashSrc: "http://weblogs.nos.nl/wp-content/themes/nos/sifr/sifr.swf", sColor: "#1f3d64", sWmode: "transparent"}));	
						sIFR.replaceElement("#colB .kop h2" , named({sFlashSrc: "http://weblogs.nos.nl/wp-content/themes/nos/sifr/sifr_colb.swf", sColor: "#ffffff", sWmode: "transparent", textalign: "center",sFlashVars:"textalign=center&offsetTop=1&letterSpacing=5"}));										
						}
}

/* 500 woorden reactie limiet */

$(document).ready( function(){

//$('body').delegate('form#commentform textarea','keypress', function(){
	
	$('#commentform textarea').keypress (function(){
	
		var total_words=this.value.split(/[\s\.,\?]+/).length;
	
		if(total_words < 500) {
			$('div.artikel .sub .word_count').html('Aantal woorden nog beschikbaar:<span>'+(500 - total_words)+'</span>');
			$('#commentform #submit').attr('disabled', false);
			$('#commentform #submit').removeClass('disabled');			
		} else {
			$('div.artikel .sub .word_count').html('Aantal woorden nog beschikbaar:<span class="overmax">'+(500 - total_words)+'</span>');		
			$('#commentform #submit').attr('disabled', true);
			$('#commentform #submit').addClass('disabled');		
		}
		 
	});

});
