$(document).ready(function() {
	/* 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'>Plus que <strong>"+left.toString()+"</strong> caract&egrave;res</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;
	}

	/* Tab widgets initialiseren */
	$('.tabs-widget > ul').tabs({ fx: { opacity: 'toggle', duration: 'fast' } });  


  /* ============= */
  /* Image Rotator */
  /* ============= */

  /* Fix things */
	$('div.image-rotator ul:first').addClass('photos');
	$('div.image-rotator li.prev').after('<li class="info">...</li>');
	
	
	/* place Image rotator outside of #Article-side if it is set to Full-width*/

	$('div.article-side').before($('div.image-rotator.full-width'));

	$('div.article-side').before($('div.photo.full-width'));

	
	/* 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 initial info */
	$('.image-rotator li.info').text('1 / '+countImages);

	/* 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');

	/* 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']);
		};
		
	
    /* Update status */
	  $info = (nextImage+1)+' / '+countImages;
	  $('.image-rotator li.info').text($info);
		/* Ignore anchor */
		return false;
		
	
	});
	$('.image-rotator').show();


	/* 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(); */
});

/* For Adhese */
// ==UserScript==
// @name           Taggings DSO total
// @namespace      tagging total
// ==/UserScript==
 
/*added by mke 27/08/2009 */
var verkeersinfo = window.location.href.indexOf("extra/verkeer");
if (verkeersinfo > -1)
{
document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_verkeer'<\/scr"+"ipt>");
} 
// ==UserScript==
// @name           Taggings DSO total
// @namespace      tagging total
// ==/UserScript==
 
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;
}
var hash = getUrlVars();
var verkeersinfo = window.location.href.indexOf("extra/verkeer");
var gid = hash['kanaalid'];
if (gid==808 || verkeersinfo > -1)
{
//alert ("hello traffic jam"); 
document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_verkeer'<\/scr"+"ipt>");
}
var weerinfo = window.location.href.indexOf("extra/weer");
if (weerinfo > -1)
{
document.write ("<scr"+"ipt language=javascript>var adhese_extra ='dso_weer'<\/scr"+"ipt>");
} 