function loadContent(klasse, functie, element, parameters) {	
	var url = 'ajax.php';
	var params = '?call=' + klasse + '/' + functie + '&' + parameters;
	var pos_x = ($("#" + element).width() / 2) - 32;
	var pos_y = ($("#" + element).height() / 2) - 32;
	
	$("#" + element + " div").css("opacity", "0.3");	
	$('#' + element).css({background: "url('images/ajax-loader.gif') no-repeat " + pos_x + "px " + pos_y + "px"});
	
	$.ajax({
	  	url: "index.php" + params,
	  	async: false,
	  	success: function(data) {
			$("#" + element).html(data);
			$("#" + element + " div").css("opacity", "1");
			$('#' + element).css({background: "none"});
	 	}
	});
}

function clearForm(form) {
	// iterate over all of the inputs for the form
	// element that was passed in
	$(':input', form).each(function() {
		var type = this.type;
		var tag = this.tagName.toLowerCase(); // normalize case
		// it's ok to reset the value attr of text inputs,
		// password inputs, and textareas
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = "";
			// checkboxes and radios need to have their checked state cleared
			// but should *not* have their 'value' changed
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		
		// select elements need to have their 'selectedIndex' property set to -1
		// (this works for both single and multiple select elements)
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

function slidingDiv(id,name){
	if ($(id).is(":hidden")) {		
		$("#" + name).addClass("active");
		$(id).slideDown("slow");
	} else {
		$("#" + name).removeClass("active");
		//document.getElementById(name).innerHTML = "+";
		$(id).slideUp("slow");
	}	
}

/*
 * Login script
 */
$(document).ready(function() {
	$("#dik_login_button").click(function(){
		// slide down
		if ($("div#login-panel").css("margin-top") == "-241px") {
			
			$("div#login-panel").animate({
				marginTop: "0px"
			})
		// slide up
		} else {
			$("div#login-panel").animate({
				marginTop: "-241px"
			}, "fast");
		}
	});	
});

function login_ajax_form(formid, postfunction, feedback_id) {
	$('[placeholder]').placeholder('clear');
			
	$('#' + feedback_id).html("<div class='waiting'>Data wordt verstuurd</div>"); 
	$('#' + formid + "_button").css("display", "none");
	
	$.post(	'ajax.php?call=' + postfunction, 
			$('#' + formid).serialize(),
			function(data) {
				var msg_string = "";
				 $('#' + feedback_id).show();
					 
				// on error
				if(data.success == false) {
					// compose error message
					jQuery.each(data, function(i, val) {
						if (i != "success")
							msg_string += val + "\n";
					});
					
					//alert(msg_string);
		
					$('#' + feedback_id).html("<div class='error'>" + msg_string + "</div>");
				// success 
				} else {
					// reset form
					//$('#' + formid).resetForm();
					
					//alert("aanmelden gelukt");
					
					// set success message			
					$('#' + feedback_id).html("<div class='message'>" + data.success_message + "</div>"); 
					window.location = "godik";
				}
				$('#' + formid + "_button").css("display", "block");
			}, 
			"json");
}

$(document).ready(function() {
	$('.search_form').submit(function(e) {
		var target = $(this).attr('action');
		location.href = 'zoeken/' + (target != '' ? target + '/' : '') + encodeURI($('.searchfield', this).val());
		e.preventDefault();
	}).children('.sermon_submit').click(function(e) {
		$(this).parent().submit();
	});
});

function load_mp_player(id, title, speaker, soundfile, rowclass) {
	if (rowclass == 'even_row') bg_color = '#F3F2F2';
	else bg_color = '#F9F9F9';
	
	if ($('#' + id + '_row').is(":hidden")) {
		/* load flash player */
		if (soundfile != "") {							
			$('#' + id).flash( { 
				swf: 'js/player.swf',
				flashvars: {
					soundFile: soundfile,
					playerID: "'" + id + "'",
					quality: 'high',
					titles: title,  
					artists: speaker,  
					autostart: "no",
					animation: "no",
					encode: "no",
					bg: "fcfcfc", 				//Background
					leftbg: "f2f2f2", 			//Speaker icon/Volume control background
					lefticon: "1B7EB3",			//Speaker icon
					voltrack: "d3d3d3",			//Volume track
					volslider: "1B7EB3",		//Volume slider
					rightbg: "f2f2f2",			//Play/Pause button background
					rightbghover: "f2f2f2",		//Play/Pause button background (hover state)
					righticon: "1B7EB3",		//Play/Pause icon
					righticonhover: "30A5E8",	//Play/Pause icon (hover state)
					loader: "fba4a0",			//Loading bar
					track: "FFFFFF",			//Loading/Progress bar track backgrounds
					tracker: "eeeeee", 			//Progress track
					border: "CCCCCC",			//Progress bar border
					skip: "666666", 			//Previous/Next skip buttons
					text: "333333" 				//Text
				},
				width: 450,
				height: 34,
				wmode: 'transparent'
			}); 
			
			$('#' + id).show();
		}
		
		$('#' + id + '_row').slideDown('medium', function() {});
		
		var intro = document.getElementById(id + '_intro');
		intro.style.display = 'none';
	} else {
		$('#' + id + '_row').slideUp('medium', function() {});
		$('#' + id).html('');
		
		var intro = document.getElementById(id + '_intro');
		if (intro != null)	
			intro.style.display = '';
	}
}
