$(document).ready(function() {

	// Setup Download tracking
	$("a.track_download").click(function() {
	  var v = $(this).html().replace(/[\s\"\'\/]+/ig, "_");  
          _gaq.push(['_trackPageview', "/downloadsnl/"+v ] );
	});

						   
	// Jquery breedte checken en fixen	
	$.fn.width = function() {
		var $browser = document.documentElement.clientWidth;
		if($browser>915){
			$("body").css('overflow-x', 'hidden');
		}
		else {
			$("body").css('overflow-x', 'visible');
		}
	}
	
	// Jquery top	
	$("ul.dropdown li a:first").addClass("top");
	$("ul.dropdown li:first").hover(
		function(){$(this).addClass("active");},
		function(){$(this).removeClass("active");}
	);	
	
	// Jquery nieuws items
	jQuery.fn.hovers = function() {
		$(this).hover(
			function(){
				var $this = $(this);
				var $new = $this.attr('rel');
				var $old = $($this).children("img").attr('src');	
				$($this).attr('rel',$old);
				$($this).children("img").attr('src',$new);			
			},
			function(){		
				var $this = $(this);
				var $new = $this.attr('rel');
				var $old = $($this).children("img").attr('src');	
				$($this).attr('rel',$old);
				$($this).children("img").attr('src',$new);	
			}
		);
	}
	$('ul.news li a').hovers();
	$('ul.beurzen li a').hovers();
	
		$("tbody tr:last-child td").css('border', '0');
	
	if($('#accordion').size() > 0){
	  $('#accordion').accordion({
			 selectedClass: 'open',
			 autoHeight: false
		});
		$('#accordion h3:first small').html('');
		
		$('#accordion h3').bind('click', function(event, ui) {		  
      $('#accordion h3 small').html('Meer informatie');      		  
      $(this).find("small").html(''); 

      $("body").width();
     });  
	}
	
 $(window).resize( function() {$("body").width();});
	
$('.overzicht ul li a').hover( 
               function() { $(this).parents().prev('strong').css('color',  '#436a8f'); },
               function() { $(this).parents().prev('strong').css('color',  '#767676') }
);
	
	
// Slideshow	
$('#next').hide();
$('#prev').hide();
	
  if ($('.images div').size() > 0 ) {
  	$('.images div').cycle({ 
  		 fx:     'fade', 
  		 speed:  'slow',
  		 next:   '#next', 
  		 prev:   '#prev',        
  		 after:	onAfter
       });
}
		
	function onAfter(curr,next,opts) {
		if(opts.slideCount>1){
			$('#next').show();
			$('#prev').show();
			$('#slideshow').css({
                                'padding-left':'0', 
                                'width': '480px'
                           });
			var caption = '' + (opts.currSlide + 1) + '/' + opts.slideCount;
			$('#pages').html(caption);
		}
	}
	
    // Usage
   var detective = new Detector();
   if(detective.test('Myriad Pro')==false)
      $('*').css("font-family","Arial");									

});

Shadowbox.init({
	//skipSetup: 			true,
	language:   			"en",
	players:    			["img","flv","iframe"],
	displayNav:         	true,
	handleUnsupported:  	"remove",
	autoplayMovies:     	true,
	overlayColor:			'#000',	
	overlayOpacity: 		'0.6' 
});

function showShadowBoxPopup(urlToShow, width, height){
	
	if(width == undefined){
		width = 350;
		}
	if(height == undefined){
		height = 350;
		}

    // open a welcome message as soon as the window loads
    Shadowbox.open({
        content:    urlToShow,
        player:     "iframe",
        title:      "",
        height:     height,
        width:      width
    });
	 
 };

$(document).ready(function() {
  var is_required = "is verplicht.";
  $('#ajax_form').hide();
  $('#contact_form').submit(function(e) {
    var errors = [];
    if ($('#contact_person').val().replace(' ', '').length == 0) {errors.push($('#contact_person').prev('label').text());}  
    if ($('#email').val().replace(' ', '').length == 0) {errors.push($('#email').prev('label').text());}
    if ($('#phone_number').val().replace(' ', '').length == 0) {errors.push($('#phone_number').prev('label').text());}
    if ($('#message').val().replace(' ', '').length == 0) {errors.push($('#message').prev('label').text());}
    if (errors.length) {
      $('#ajax_form_errors ul').children().remove();
      for (i in errors) {
        $('<li>').text(errors[i].replace('*', '') + ' ' + is_required).appendTo('#ajax_form_errors ul');
      }
      $('#ajax_form_errors').css({marginBottom: '15px'});
      $('#ajax_form').fadeIn('fast');
      return false;
    }
});
});

