function substr_count(haystack, needle) {
    var pos = 0, cnt = 0;
	offset = 0;
    length = 0;
    offset--;
 
    while( (offset = haystack.indexOf(needle, offset+1)) != -1 ){
        if(length > 0 && (offset+needle.length) > length){
            return false;
        } else{
            cnt++;
        }
    }
    return cnt;
}

$(document).ready(function() {
	$(".toggle_row").hide();
	 //$(".tablerating").children("tbody").children("tr:first-child").children("td:first-child").toggle(
	 $(".toggler").click(function () {
	   if ($(this).parent().css("background-image").indexOf('gfx/submenu_selectwithsubsub_bg.gif') != -1) {
         $(this).parent().parent().parent().children(".toggle_row").hide();
         $(this).parent().css("background-image","url('gfx/listarrow.gif')");
	   } else {
        $(this).parent().parent().parent().children(".toggle_row").show();
        $(this).parent().css("background-image","url('gfx/submenu_selectwithsubsub_bg.gif')");
	   }
	 });

	$(".link").hover(
      function () {
        $(this).css("text-decoration","none");
      }, 
      function () {
        $(this).css("text-decoration","underline");
      }
    );


    //$(".postit").hide();
    $(".postit").after("<img src='gfx/icon_postit.gif' class='postit_icon' />");
    $(".postit_icon").click(function () {
    	$(".postit:visible").hide();
    	$(this).parent("div").css("overflow","visible");
    	$(this).prevAll("input:text").css("background","#fff299")
      $(this).prev().show();
    });
    $(".postit").click(function () {
    	$(this).parent("div").css("overflow","hidden");
    	$(this).prevAll("input:text").css("background","#fff")
      $(this).hide();
    });
    $(".postit").append("<span class='postit_close'>Close</span>");

	$("dl.accordion").each(
		function() {
			$(this).find("dd:gt(3)").hide();
			$(this).append("<dd class='expand'><a href='javascript:void(0)'>toon alle opties</a></dd>");
		}
	);
		
	$(".expand a").toggle(
		function () {
			$(this).parents("dl.accordion").children("dd").attr('style','display:none;').show();
			$(this).addClass("expanded");
			$(this).html("toon minder opties");
	},
		function() {
			$(this).parents("dl.accordion").children("dd:gt(3)").attr('style','display:block;').hide();
			$(this).parent().show();
			$(this).removeClass();
			$(this).html("toon alle opties");
		}
	);
});