/**
 * Zentropy javascript core
 *
 * - Provides frequently used extensions to base javascript objects
 * - jQuery browser detection tweak
 * - Define functions used in events
 */

// Add String.trim() method
String.prototype.trim = function(){
	return this.replace(/\s+$/, '').replace(/^\s+/, '');
}

// Add Array.indexOf() method
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (obj, fromIndex) {
    if (fromIndex == null) {
      fromIndex = 0;
    } else if (fromIndex < 0) {
      fromIndex = Math.max(0, this.length + fromIndex);
    }
    for (var i = fromIndex, j = this.length; i < j; i++) {
      if (this[i] === obj){
        return i;
      }
    }
    return -1;
  };
}

// jQuery Browser Detect Tweak For IE7
jQuery.browser.version = jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 && window["XMLHttpRequest"] ? "7.0" : jQuery.browser.version;

// Console.log wrapper to avoid errors when firebug is not present
// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function() {
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if (this.console) {
    console.log(Array.prototype.slice.call(arguments));
  }
};

// init object
var Zentropy = Zentropy || {};

/**
 * Image handling functions
 */
Zentropy.image = { _cache : [] };

// preload images
Zentropy.image.preload = function() {
  for (var i = arguments.length; i--;) {
    var cacheImage = document.createElement('img');
    cacheImage.src = arguments[i];
    Zentropy.image._cache.push(cacheImage);
  }
}
;
(function ($) {
	$(document).ready(function() {
		
		$('.formulaDetail').children('div').hide();
		$('.formulaDetail').children('h3').addClass('closed');
    	$('.formulaDetail').children('h3').click(function() {
    		if($(this).parent().children('div').is(":visible")){
        		$(this).parent().children('div').hide(); 
        		$(this).removeClass('open');
        		$(this).addClass('closed');
    		}
    		else{
        		$(this).parent().children('div').show();
        		$(this).removeClass('closed');
        		$(this).addClass('open');
    		}
    	});
    	
    	$('.archief').click(function() {
    		var display_is = $("#archief").css("display");
    		if(display_is == "none")
    		{
    			$(this).addClass('open');
    			$('#archief').removeClass('closed');
    			$('#archief').addClass('open');
    		}else{
    			$(this).removeClass('open');
    			$('#archief').removeClass('open');
    			$('#archief').addClass('closed');	
    		}
    	});

	});	
})(jQuery);

;
(function ($) {
  Drupal.behaviors.exampleModule = {
    attach: function(context, settings) {

    	$('.calendar').live('click', function() {
    		// define the clicked id
    		if($(this).hasClass('closed')){
    			$(this).attr('class', 'open calendar');
    			$(this).find("td:nth-child(3)").attr('colspan', '2');
    		}
    		else{
    			$(this).attr('class', 'closed calendar');
    			$(this).find("td:nth-child(3)").attr('colspan', '');
    		}
    	});
    	
    	$(".viewArchive").live('click', function () {
    		if($(this).hasClass('viewArchive')){
    		$(this).html(Drupal.t('Hide archive'));
    		$(this).attr('class', 'hideArchive');
            $.ajax	({
                    	url: '/ajax-filter-archive',
                    	success: function(data) {
            				$('#showArchive').html(data);
            			}
            		});
    		}
    		else if($(this).hasClass('hideArchive')){
    			$(this).html(Drupal.t('Show archive'));
    			$(this).attr('class', 'viewArchive');
    			$('.calendarArchive').hide();
    		}
        });
    	
    	$(".hideArchive").live('click', function () {
    		if($(this).hasClass('hideArchive')){
    		$(this).html(Drupal.t('Hide archive'));
    		$(this).attr('class', 'viewArchive');
   			$(this).html(Drupal.t('Show archive'));
   			$('.calendarArchive').hide();
    		}
        });
    	
    }
  }
})(jQuery);;
;

