jQuery.fn.extend({
	highlight: function(search, insensitive, hls_class){
	  var regex = new RegExp("(<[^>]*>)|(\\b"+ search.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1") +")", insensitive ? "ig" : "g");
	  return this.html(this.html().replace(regex, function(a, b, c){
		return (a.charAt(0) == "<") ? a : "<strong class=\""+ hls_class +"\">" + c + "</strong>";
	  }));
	}
});
  
$(document).ready(function() {	
    $('div#box-tabs > div.interior > ul').tabs();
	
	var vacChildren = $("#vacatureCarousel").children().length;
	var randomStart = Math.floor(Math.random()*vacChildren);
	if(vacChildren > 3){
		$('#vacatureCarousel').cycle({ fx:'scrollLeft', timeout: 7000, delay:-2500, next:'.next', startingSlide: randomStart});
	}else{
	 	$('#vacatureCarousel').cycle({ fx:'scrollLeft', timeout: 0, next:'.next',startingSlide: randomStart});
	}
		
	var searchText = $('p span.hidden').text();
	if($("input#s").val() == ''){$("input#s").val(searchText);} 
    $("input#s").focus(function() {		
		if($(this).val() == '' || $(this).val() == searchText){$(this).val('');}
    });
    $("input#s").blur(function() {
		var searchText = $('p span.hidden').text();
		if($(this).val() == '' || $(this).val() == searchText){$(this).val(searchText);}
    });
	
    if(typeof(hls_query) != 'undefined'){
      $(".postgroup").highlight(hls_query, 1, "hls");
    }

	$('#vacatureCarousel li').click(function() {
		var goTo = $(this).find("h4 a").attr("href");
		if(goTo && goTo!=''){window.location = goTo;}
    });
	
    $(".submenu ul li").hover(
		function() {
		  $(this).addClass('active');
		},
		function() {
		  $(this).removeClass('active');
		}
    );
	$('.submenu ul li').click(function() {
		var goTo = $(this).find("a").attr("href");
		if(goTo && goTo!=''){window.location = goTo;}
    });
	
	$("#vacatures-tabel").tablesorter({ 
		// sort on the first column order asc 
		//sortList: [[0,0]], 
		headers: { 3: {sorter: false} },
		widgets: ['zebra']
    });
	if($("#pager").length > 0){
		$("#vacatures-tabel").tablesorterPager({container: $("#pager")}); 
	}

});
