$(document).ready(function() {
	$("input[name$=chkAccept]").each(function() {
	    if (  this.checked == false )
	    {	   	    
	         $("input[name$=btnSubmitArticleReaction]").toggle();   //.attr("disabled", "disabled");  
	    }
	});
	
	 $("input[name$=chkAccept]").click(function() {    
            var checked_status = this.checked;
            if (checked_status == true)
			{
                $("input[name$=btnSubmitArticleReaction]").toggle(); //.removeAttr("disabled");
            }
            else
			{
                $("input[name$=btnSubmitArticleReaction]").toggle(); //  .attr("disabled", "disabled");
            }   
     });

	/* FUNCTIONS */
	/* Character counter */	
	jQuery.fn.counter = function() {
	  $(this).each(function() {
  
	    var max = $(this).attr('maxlength');
	    var val = $(this).attr('value');
	    var cur = 0;
	    if(val)
	    	cur = val.length;
	    var left = max-cur;
	    $(this).after("<div class='counter'>Nog <strong>"+left.toString()+"</strong> tekens over</div>");
	    var c = $(this).next(".counter"); 
	    $(this).keyup(function(i) {
	      var max = $(this).attr('maxlength');
	      var val = $(this).attr('value');
	      var cur = 0;
	      if(val)
	        cur = val.length;
	      var left = max-cur;

	      if (left < 0)
	      {
		i.preventDefault();
		left = 0;
	      }
	      $(this).next(".counter").find('strong').text(left.toString());
	      return this;
	    });
	    $(this).keypress(function(i) {
	      var max = $(this).attr('maxlength');
	      var val = $(this).attr('value');
	      var cur = 0;
	      if(val)
	        cur = val.length;
	      var left = max-cur;
		  
		  var key = i.which;
		  if(key >= 33 || key == 13)
		  {
			  if (left < 0 )
			  {
				i.preventDefault();
			  }
		  }
	      return this;
	    });
	  });
	  return this;
	}
	/* Justify height of columns */
	jQuery.fn.vjustify=function() {
	    var maxHeight=0;
	    this.each(function(){
	        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
	    });
	    this.each(function(){
	        $(this).height(maxHeight + "px");
	        if (this.offsetHeight>maxHeight) {
	            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
	        }
	    });
	};

	/* Tab widgets initialiseren */
	$('.tabs-widget > ul').tabs({ fx: { opacity: 'toggle', duration: 'fast' } });  
	/* Create objects */
	var $baseImage = $('div.image-rotator ul:eq(0) li:eq(0) img');
	var $otherImages = $('div.image-rotator ul:eq(0) li:gt(0) img');
	/* Hide all images, except the first one */
	$otherImages.hide();
	/* Create array with baseImage values */
	var baseImageProperties = [];
	baseImageProperties['src'] = $baseImage.attr('src');
	baseImageProperties['alt'] = $baseImage.attr('alt');
	baseImageProperties['title'] = $baseImage.attr('title');
	/* Create variabeles */
	var countImages = $('div.image-rotator ul:eq(0) li').length;
	var nextImage = 0;
	var loopImages = false;
	/* Set container width to be the same as the image */
	$('div.image-rotator').css('width',$('div.image-rotator img:eq(0)').css('width'));
	$('div.image-rotator.full-width').css('width','568px');
	/* Set initial caption */
	$('.image-rotator .caption').text($baseImage.attr('alt'));
	$('.image-rotator .copyright').text($baseImage.attr('title'));
	/* Dim Previous button initially */
	$('.image-rotator li.prev').toggleClass('dimmed');
	/* Show if loaded */
	$('.article-detail .image-rotator').toggle();
	/* Bind onClick handler to Next and Previous links */	
	$('div.image-rotator li a').bind('click', function() {
		/* Disable dimmed Previous and Next buttons if needed */		
		if (!loopImages && $(this).parent('li').hasClass('dimmed'))
			return false;
		/* Has the Next or the Previous been clicked? */
		if ($(this).parent('li').hasClass('next'))
			next = true;
		else
			next = false;
		/* Determine position of next or previous image */
		if (nextImage == 0)
			if (next) nextImage = nextImage + 1;
			else nextImage = countImages - 1;
		else if ( (nextImage > 0) && (nextImage < (countImages - 1)) )
			if (next) nextImage = nextImage + 1;
			else nextImage = nextImage - 1;
		else if ( nextImage == (countImages - 1))
			if (next) nextImage = 0;
			else nextImage = nextImage -1;
		/* Change button states */	
		$('.image-rotator li').removeClass('dimmed');
		next = false;
		prev = false;		
		if (nextImage == 0)
			prev = true;
		else if (nextImage == (countImages - 1) )
			next = true;
		if (next)
			$('.image-rotator li.next').toggleClass('dimmed');
		else if (prev)
			$('.image-rotator li.prev').toggleClass('dimmed');
		/* Create object for required <li> */
		$nextImage = $('div.image-rotator ul:eq(0) li:eq('+nextImage+')');
		/* Replace image */
		if (nextImage != 0)
			$baseImage.fadeOut(125,function() {
				$baseImage.attr('src',$nextImage.find('img').attr('src'));
				$baseImage.fadeIn(125);
			});
		else
			$baseImage.fadeOut(125,function() {
				$baseImage.attr('src',baseImageProperties['src']);
				$baseImage.fadeIn(125);
			});
		/* Replace caption and copyright message */
		if (nextImage != 0) {
			$('.image-rotator p.caption').text($nextImage.find('img').attr('alt'));
			$('.image-rotator p.copyright').text($nextImage.find('img').attr('title'));
		}
		else {
			$('.image-rotator p.caption').text(baseImageProperties['alt']);
			$('.image-rotator p.copyright').text(baseImageProperties['title']);
		};
		/* Ignore anchor */
		return false;
	});
	/* Service navigation */
	$servicenav = 'close';
	$('ul#service-nav li > a')
		.bind('click',function() {
			$(this).parent().parent().find('li > ul').hide('fast');
			$(this).parent().find('ul').toggle('fast');
			if ($(this).css('display') == 'block') {
				$servicenav = 'open';
			}
			else {
				$servicenav = 'close';
			}
		});
	$('ul#service-nav li > a')
		.bind('mouseenter',function() {
			if ($servicenav == 'open') {
				$(this).parent().parent().find('li > ul').hide('fast');
				$(this).parent().find('ul').toggle('fast');	
			}
		});
	$('ul#service-nav li > ul')
		.bind('mouseleave',function() { 
			$(this).toggle('fast');
			$servicenav = 'close';
		})
	/* Add character counter to textarea */	
	$('.comments #your-comment textarea').counter();
  /* Add comma's to footer links */
  $('.ie #footer ul.links li:last-child').addClass('last');
  $('.ie #footer ul.links li:not(.last)').append(', ');
  /* Add video overlays */
 $('#breaking-video .panel li a img').each(function() {
		var src = $(this).attr('src');
		$(this)
			.css('background-image','url('+src+')')
			.attr('src','images/slidebox/video-overlay_85x60.png');
	});
});
/* These functions rely on images being fully loaded, so $(document).ready() won't work */
$(window).load(function() {
	/* Adjust column heights where needed */
	$(".stretch").vjustify();
});

/* ADHESE */
function getUrlVars()
{
	var current_url = window.location.href.toLowerCase(); 
	var vars = [], hash;
	var hashes = current_url.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}


	/* */
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

/*  */

/* VERKEER */
var hash = getUrlVars();
var verkeersinfo = window.location.href.indexOf("extra/verkeer");
var gid = hash['kanaalid'];
if (gid==808 || verkeersinfo > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_verkeer'<\/scr"+"ipt>");
}

/* WEER */
var weerinfo = window.location.href.indexOf("extra/weer");
if (weerinfo > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_weer'<\/scr"+"ipt>");
} 


/* TYPEPAD - DSO */
var dso_batibouw = window.location.href.indexOf("RfOOOPp7hqNOAgj6Xw2exvUKxtO5LgdhkDrttv");
if (dso_batibouw > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_batibouw'<\/scr"+"ipt>");
} 
/* WESTTOER- DSO */
var dso_typepad = window.location.href.indexOf("typepad");
if (dso_typepad > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_typepad'<\/scr"+"ipt>");
} 


/* CANON  - DSO */
var dso_canon = window.location.href.indexOf("canon");
if (dso_canon > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_canon'<\/scr"+"ipt>");
} 

/* CANON - ACTU */
var dso_actu= window.location.href.indexOf("actu24");
if (dso_actu> -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra ='actu_canon'<\/scr"+"ipt>");
} 

/* FONDSENDOSSIER */
var dso_fondsen= window.location.href.indexOf("extra/fondsendossier");
if (dso_fondsen> -1)
{
	document.write ("<scr"+"ipt language=javascript>var kanaal = 1504;<\/scr"+"ipt>");
} 

/* BEURS   CHI-X */
var beurs_chix = window.location.href.indexOf("extra/biz/chi-x");
if (beurs_chix > -1)
{
	document.write ("<scr"+"ipt language=javascript> var adhese_extra ='beurs_chix'; <\/scr"+"ipt>");
} 
var beurs_chix2 = window.location.href.indexOf("20100427_088");
if (beurs_chix2 > -1)
{
	document.write ("<scr"+"ipt language=javascript> var adhese_extra ='beurs_chix'; <\/scr"+"ipt>");
}


/* DOSSIER BLINDENZORG */
var dso_blindenzorg= window.location.href.indexOf("kanaalid=1513");
if (dso_blindenzorg > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra = 'dso_blindenzorg'<\/scr"+"ipt>");
} 

/* DOSSIER BNP PARIBAS */
var dso_bnpparibas= window.location.href.indexOf("kanaalid=1527");
if (dso_bnpparibas > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra = 'dso_bnpparibas'<\/scr"+"ipt>");
} 

/* DOSSIER FESTIVALS 2010 */
var dso_festivals = window.location.href.indexOf("aalId=434");
if (dso_festivals > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra = 'dso_festivals'<\/scr"+"ipt>");
} 




/* WEDSTRIJD WESTHOEK */
var dso_westhoek = window.location.href.indexOf("artikelid=DMF20100526_038");
if (dso_westhoek > -1)
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra = 'dso_westhoek'<\/scr"+"ipt>");
} 

/* ENERGIEGIDS - CREATIVE LAB - 201006 */
if (window.location.href.indexOf("kanaalid=1594") > -1 || window.location.href.indexOf("kanaalid=1593") > -1  || window.location.href.indexOf("kanaalid=1595") > -1  || window.location.href.indexOf("kanaalid=1591") > -1 )
{
	document.write ("<scr"+"ipt language=javascript>var adhese_extra = 'dso_energiegids'<\/scr"+"ipt>");
} 

/* - start - jh paco test - */
$(document).ready(function() {
if  (typeof user_abo == "undefined"){ var user_abo = 0;}
if(user_abo == 0){
		var doc_body = document.getElementsByTagName('body')[0].innerHTML;
		var doc_body_pos = doc_body.indexOf('krijg toegang tot dit artikel');
		if (doc_body_pos > 0) {
				if(GetCookie("paco_wall_count") == null) {
					var visitCount = 1; var d = new Date(); d.setDate(d.getDate() + 14); 
				} else {
					var cookieValue = GetCookie("paco_wall_count"); var ca = cookieValue.split(';');
					 visitCount = parseInt(ca[0])+1; var d = new Date(ca[1]); 	
				}
		var visitCount0 = visitCount + ";" + d;

			var returnhtml = '<img src="http:\/\/ads.adhese.be\/track\/';
			if (visitCount > 49){ returnhtml +=  "33743"; } else if (visitCount > 39){ returnhtml += "33741"; } else if (visitCount > 29){ returnhtml += "33740"; } else if (visitCount > 19){ returnhtml += "33739"; } else if (visitCount > 9){ returnhtml += "33738"; } else if (visitCount > 4){ returnhtml += "33742"; } else { returnhtml += "33737"; }
			returnhtml += '" \/>';
		
		$('body').append(returnhtml);	
		SetCookie("paco_wall_count", visitCount0, d);
		}
}
});

/* - eind - jh paco test - */




