$(document).ready(function () {
	$('.special').oneShowHide({numShown:4});
	splitInto2Columns(".js_kolom_2");
});

function splitInto2Columns(listClass) {
	var blocks = $(listClass);
	for (var i=0; i < blocks.length; i++){
		//var originalList = $(listClass).addClass("unit size12");
		var originalList = $(blocks[i]).addClass("unit size12");
		//clone it but hide it
		var cloneList = originalList.clone().insertAfter(originalList).css('display','none');
		//remove left even and right odd items 
		$(cloneList.children(".js_cel:even")).remove();
		$(originalList.children(".js_cel:odd")).remove();
		//show it
		cloneList.css('display','block');
	}
}

(function($){  
	$.fn.extend({
		oneShowHide: function(options) {  

			//Set the default values, use comma to separate the settings 
			var defaults = {  	
				numShown: 10,  
				showText : '+',  
				hideText : '-'  
			}  
			var bStatus = "hidden"; 
			var options =  $.extend(defaults, options);  

			return this.each(function() {  
				var o = options;  
				var obj = $(this);
				// Determine the length of items here and calculate the number hidden
				var pLength = obj.children().length;
				var numHidden = pLength - o.numShown;
				var pList = obj.children();

				// Setup Show/Hide Link
				if (numHidden == 1){
					var sGebeurtenis = "gebeurtenis";
				} else {
					var sGebeurtenis = "gebeurtenissen";								
				}
				
				o.showText =  '<a href=\"javascript://\">Nog ' + numHidden + ' ' + sGebeurtenis + '</a><a href=\"javascript://\" class="bd-icons bgbefore plus no-decoration">&nbsp;</a>';
				o.hideText =  '<a href=\"javascript://\" class="bd-icons bgbefore min no-decoration">&nbsp;</a>';
				var shLink = "<div class='right view'>" + o.showText + "</div>";

				if (pLength > o.numShown) {
					$(shLink).insertAfter(obj); 
				}

				pList.each(function(index){
					if (index < o.numShown) {
						$(pList[index]).show(); 
					}	else {
						$(pList[index]).hide();
						$(pList[index]).addClass('hide_lm');
					} 
				}); 

				//splitsen in 2 kolommen en de juiste presenteren
				//clone it but hide it
				var cloneList = obj.clone().insertAfter(obj).css('display','none');
				//remove left even and right odd items 
				$(cloneList.children(":even")).remove();
				$(obj.children(":odd")).remove();
				$(obj).wrap("<div class=\"unit size12\"></div>");
				$(cloneList).wrap("<div class=\"unit size12\"></div>");
				//show it
				cloneList.css('display','block');

				// This is where I toggle the text
				$("div.view").live("click", function(e){
					if (bStatus == "hidden") {
						$(this).html(o.hideText);
						bStatus = "show"; 
					} else {
						$(this).html(o.showText);
						bStatus = "hidden"; 
					}
					$('.hide_lm').toggle();
					return false;
				});                
			});
		} 
	}); 
})($);

