(function ($) {

	// popup on filter on kalender-page
	Drupal.behaviors.filterpopup = {
		attach: function(context, settings) {
			
				$('#block-wmcustom-wmcustom-exposedfilter .form-checkboxes label').hover(
					function () {
						$(this).addClass('over');
					}, 
					function () {
						$(this).removeClass('over');
					}
				);
			
    }
  }

	// labels in newsletter / search showhide
	Drupal.behaviors.showhidelabels = {
		attach: function(context, settings) {
			
			$('#block-search-form input.form-text, #block-wmcustom-wmcustom-campaigncommander input.form-text').each(function (i) {
				$(this).parents('.form-item').find('span').remove();
				$tekst = $(this).parents('.form-item').find('label').html().split(':');		
				$(this).parents('.form-item').find('label').hide();		
				$(this).attr("labeltext",$tekst[0]);
				$(this).val($tekst[0]);
			});
			
			
			$('#block-search-form input.form-text, #block-wmcustom-wmcustom-campaigncommander input.form-text').focus(function () {
				if($(this).val() == $(this).attr('labeltext')) {
					$(this).val('');
					$(this).addClass('form-text-focus');
				}											   
			});
			
			$('#block-search-form input.form-text, #block-wmcustom-wmcustom-campaigncommander input.form-text').keypress(function () {
				if($(this).val() == $(this).attr('labeltext')) {
					$(this).val('');
				}											   
			});
			
			$('#block-search-form input.form-text, #block-wmcustom-wmcustom-campaigncommander input.form-text').blur(function () {
				if($(this).val() == '') {
					$(this).val($(this).attr('labeltext'));
					$(this).removeClass('form-text-focus');
				}											   
			});	
			
    }
  }
  
  // maakt blog blokken even groot voor float
  
  Drupal.behaviors.blockheight = {
		attach: function(context, settings) {
						
			  var currentTallest = 0,
				 currentRowStart = 0,
				 rowDivs = new Array(),
				 $el,
				 topPosition = 0;
			
			 $('.section-blog #main #block-views-blog-block-1 .view-id-blog .view-content .views-row').each(function() {
			
			   $el = $(this);
			   topPostion = $el.position().top;
			
			   if (currentRowStart != topPostion) {
			
				 // we just came to a new row.  Set all the heights on the completed row
				 for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
				   rowDivs[currentDiv].height(currentTallest);
				 }
			
				 // set the variables for the new row
				 rowDivs.length = 0; // empty the array
				 currentRowStart = topPostion;
				 currentTallest = $el.height();
				 rowDivs.push($el);
			
			   } else {
			
				 // another div on the current row.  Add it to the list and check if it's taller
				 rowDivs.push($el);
				 currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
			
			  }
			
			  // do the last row
			   for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
				   rowDivs[currentDiv].height(currentTallest);
			   }

			 });
		}
  }
  
  Drupal.behaviors.fbcommentcount = {
    attach: function(context, settings) {
      $('.fb_comment_count').each(function() {
        var path = $(this).attr('url');
        var id = $(this).attr('id');
        $.ajax({
          url: "http://graph.facebook.com/?ids=" + path,
          dataType: "jsonp",
          success: function(data) {
            if(data[path] != undefined && data[path].comments != undefined) {
              $('#'+id).html(data[path].comments);
            } else {
              $('#'+id).html('0');
            }

          }
        });
      });
    }
  }
  
	// target blank on facebook page
	Drupal.behaviors.targetBlank = {
		attach: function(context, settings) {
			$('.externallink a').attr('target', '_blank');	
			$('.view-blog-for-facebook .field-name-field-blog-picture a').attr('target', '_blank');
    }
  }  
	
	
})(jQuery);;

