// tools
jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
	    jQuery("<img>").attr("src", arguments[i]);
  }
}


$(document).ready(function(){

	// jQuery-typing
	(function(f){function l(g,h){function d(a){if(!e){e=true;c.start&&c.start(a,b)}}function i(a,j){if(e){clearTimeout(k);k=setTimeout(function(){e=false;c.stop&&c.stop(a,b)},j>=0?j:c.delay)}}var c=f.extend({start:null,stop:null,delay:400},h),b=f(g),e=false,k;b.keypress(d);b.keydown(function(a){if(a.keyCode===8||a.keyCode===46)d(a)});b.keyup(i);b.blur(function(a){i(a,0)})}f.fn.typing=function(g){return this.each(function(h,d){l(d,g)})}})(jQuery);
	
   //toggle answer when question is clicked
   //$('#colq>dd').hide();
   //$('#colq>dt').contents().wrap('<span></span>').parent().click(function(){$(this).parent().next().toggle();});
   
   $('#colq>dl>dt:first').parent().before('<a href="" class="openClose">Open alle antwoorden</a>');
	 $('.openClose').click(function(){
	 		var str = $(this).text();
			if(str=='Open alle antwoorden'){
				$('#colq>dl>dd').show("fast");
				$('.openClose').text('Sluit alle antwoorden');
				$('.openClose').removeClass('uitklap');
				$('.openClose').addClass('inklap');
				_gaq.push(['_trackPageview', '/virtual/qa/open-all']);
			}else{
				$('#colq>dl>dd').hide("fast");
				$('.openClose').text('Open alle antwoorden');
				$('.openClose').removeClass('inklap');
				$('.openClose').addClass('uitklap');
				_gaq.push(['_trackPageview', '/virtual/qa/close-all']);
			}
			$(this).blur();
	 		return false;
	 	});
   
   $('#colq>dl>dt').contents().wrap('<span></span>').parent().click(function(){
   		$('#colq>dl>dd').hide("fast");
   		$(this).parent().next().toggle("fast");
		_gaq.push(['_trackPageview', '/virtual/qa/question']);
   	});
	$('#main .print > a').click(function(){
		$('#colq>dl>dd').show();
		print();
		return false;
	});
	$('#main .leesmeer a ').prepend("lees meer ");
	
	/* MDF 120510: extra initialisation */
	$("#usernameText").focus(function() {
		if ($(this).val() == "Email")
			$(this).val("");
	}).blur(function() {
		if ($(this).val() == "")
			$(this).val("Email");
	});
	$("#passwordText").focus(function() {
		if ($(this).val() == "Wachtwoord")
			$(this).val("");
	}).blur(function() {
		if ($(this).val() == "")
			$(this).val("Wachtwoord");
	});

	// search field	
	$('#searchinput').typing({
	    stop: function (event, $elem) {
			_popsearch();
	    },
	    delay: 30
	});	
	
}); 

function _login(e) {
	var ev = e || window.event;
	if (ev.keyCode == 13) {
		doPostBack("login", "login", null);
		return false;
	} else
		return true;
}

function _search(e) {
	// obsolete
}
function _popsearch() {
	var q = $("#searchinput").val();
	if (q && q.length > 0) {
		$.ajax({
			url: "/searchpopup.html",
			data: {
				"q": q,
				"p": $("#particulierCheck").attr("checked") ? "1" : "0",
				"z": $("#zakelijkCheck").attr("checked") ? "1" : "0",
				"k": $("#kennisCheck").attr("checked") ? "1" : "0",
				"d": $("#dienstenCheck").attr("checked") ? "1" : "0",
				"b": $("#bedrijvenCheck").attr("checked") ? "1" : "0"
			},
			success: function(data, status, request) {
				if (data && data.length > 0) {
					$("#searchresults .results").html(data);
					$("#searchresults").show();
				} else {
					$("#searchresults .results").html("");
					$("#searchresults").hide();
				}
			}
		});
	} else if (q.length == 0) {
		$("#searchdata .results").html("");
		$("#searchresults").hide();
	}
}
function _dosearch() {
	location.href = "/Zoeken.html?q=" + escape($("#searchinput").val());
}

$(document).ready(function() {
	$("#particulierCheck").click(function() {
		_popsearch();
	});
	$("#zakelijkCheck").click(function() {
		_popsearch();
	});
	$("#kennisCheck").click(function() {
		_popsearch();
	});
	$("#dienstenCheck").click(function() {
		_popsearch();
	});
	$("#bedrijvenCheck").click(function() {
		_popsearch();
	});
	$("#container").click(function(e) {
		if (e.target.id != "searchinput" && $(e.target).parents("#searchresults").length == 0)
			$("#searchresults").hide();
	});
});

function _clr(val,txt) {
	var elm = document.getElementById(val);
	if (elm.value == txt)
		elm.value = "";
}

function _rst(val,txt) {
	var elm = document.getElementById(val);
	if (elm.value == "")
		elm.value = txt;
}

function _remainder(elm) {
 	$(elm).parent("p").hide("fast").next("dd").show("fast");
 	$(elm).parent("p").prev("dd").css({"padding-bottom":"0"});
}

