$(document).ready(function() {

	// menu (mouseover)
	$("#menu").find("li").not(".search").not(".bg-menutab-stroke").not(".bg-menutab-a").mouseover(function() {
		$(this).addClass("sprite bg-menutab-o");
		$(this).find("div").each(function() { $(this).addClass($(this).attr("id") + "-o"); });
	});
	$("#menu").find("li").not(".search").not(".bg-menutab-stroke").not(".bg-menutab-a").mouseout(function() {
		$(this).removeClass("sprite bg-menutab-o");
		$(this).find("div").each(function() { $(this).removeClass($(this).attr("id") + "-o"); });
	});
	$("#menu").find(".search").mouseover(function() { $(this).addClass("sprite bg-menutab-search-a"); });
	$("#menu").find(".search").mouseout(function() { $(this).removeClass("sprite bg-menutab-search-a"); });
	$("#menu").find("INPUT").blur(function() { setTimeout(closeSearchResults, 100); });

	$(".search-results-div").mouseover(function() { $('#menu .search').addClass('sprite bg-menutab-search-a'); });
	$(".search-results-div").find("li").mouseover(function() { $(this).removeClass("sprite bg-menutab-o"); if (!$(this).hasClass("header")) $(this).addClass("bg-menutab-search-o"); });
	$(".search-results-div").find("li").mouseout(function() { $(this).removeClass("sprite bg-menutab-o"); if (!$(this).hasClass("header")) $(this).removeClass("bg-menutab-search-o"); });

	// buttons (mouseover)
	$(".btn-big").mouseover(function() { $(this).addClass("btn-big-o"); });
	$(".btn-big").mouseout(function() { $(this).removeClass("btn-big-o"); });
	$(".btn-medium").mouseover(function() { $(this).addClass("btn-medium-o"); });
	$(".btn-medium").mouseout(function() { $(this).removeClass("btn-medium-o"); });
	$(".btn-small").mouseover(function() { $(this).addClass("btn-small-o"); });
	$(".btn-small").mouseout(function() { $(this).removeClass("btn-small-o"); });
	$(".btn-aanmelden").mouseover(function() { $(this).addClass("btn-aanmelden-o"); });
	$(".btn-aanmelden").mouseout(function() { $(this).removeClass("btn-aanmelden-o"); });
	$(".btn-meer-info").mouseover(function() { $(this).addClass("btn-meer-info-o"); });
	$(".btn-meer-info").mouseout(function() { $(this).removeClass("btn-meer-info-o"); });
	$(".btn-lees-meer").mouseover(function() { $(this).addClass("btn-lees-meer-o"); });
	$(".btn-lees-meer").mouseout(function() { $(this).removeClass("btn-lees-meer-o"); });
	$(".btn-naar-de-website").mouseover(function() { $(this).addClass("btn-naar-de-website-o"); });
	$(".btn-naar-de-website").mouseout(function() { $(this).removeClass("btn-naar-de-website-o"); });
	$(".btn-msn").mouseover(function() { $(this).addClass("btn-msn-o"); });
	$(".btn-msn").mouseout(function() { $(this).removeClass("btn-msn-o"); });
	$(".btn-hyves").mouseover(function() { $(this).addClass("btn-hyves-o"); });
	$(".btn-hyves").mouseout(function() { $(this).removeClass("btn-hyves-o"); });
	$(".btn-contact-verzenden").mouseover(function() { $(this).addClass("btn-contact-verzenden-o"); });
	$(".btn-contact-verzenden").mouseout(function() { $(this).removeClass("btn-contact-verzenden-o"); });

	// leden (expand/collapse)
	$(".leden .more").click(function() {
		// if open, close it
		if ($(this).parents("li").hasClass("open")) {
			$(this).parents("li").removeClass("open");
			$("#full-" + $(this).parents("li").attr("id")).css("display", "none");
			$(this).text("meer info");
		} else {
			// close all
			$(this).parents("ul").find("li").each(function() {
				$(this).removeClass("open");
				$("#full-" + $(this).attr("id")).css("display", "none");
				$(this).find(".more").text("meer info");
			});

			// open selected
			$(this).parents("li").toggleClass("open");
			$("#full-" + $(this).parents("li").attr("id")).css("display", "block");
			$(this).text("sluiten");
		}
	});

	// leden contact
	$(".lid-contact-btn").click(function() {
		var id = $(this).attr("id").substring(16);

		// validatie
		if (submit_onclick("frm-lid-" + id, false)) {
			var dataString =
				"toEmail=" + $("#to-" + id).val() +
				"&fromName=" + $("#name-" + id).val() +
				"&fromEmail=" + $("#email-" + id).val() +
				"&subject=" + $("#subject-" + id).val() +
				"&message=" + $("#message-" + id).val();
			$.ajax({
				type: "GET",
				url: PATH_LANG + "xml/LidContact",
				data: dataString,
				success: function(data) {
					if (data == "TRUE") {
						$("#lid-contact-response-" + id).css("color", "green");
						$("#lid-contact-response-" + id).html("Uw bericht is verstuurd.");
						return true;
					} else {
						$("#lid-contact-response-" + id).css("color", "red");
						$("#lid-contact-response-" + id).html("Uw bericht kon niet verstuurd worden. Probeer het nogmaals.");
					}
				},
				error: function() {
					$("#lid-contact-response-" + id).css("color", "red");
					$("#lid-contact-response-" + id).html("Er is een overwachte fout opgetreden. Uw bericht is niet verstuurd.");
				}
			});
		}
	});

	// contact
	$(".btn-contact-verzenden").click(function() {
		// validatie
		if (submit_onclick("frmContact", false)) {
			$(".btn-contact-verzenden").hide();
			$("#frmContact-response").css("color", "#5E5E5E");
			$("#frmContact-response").html("Bezig met versturen...");

			var dataString =
				"fromName=" + $("#name").val() +
				"&fromEmail=" + $("#email").val() +
				"&phone=" + $("#phone").val() +
				"&subject=" + $("#subject").val() +
				"&message=" + $("#message").val();
			$.ajax({
				type: "GET",
				url: PATH_LANG + "xml/Contact",
				data: dataString,
				success: function(data) {
					if (data == "TRUE") {
						$("#frmContact-response").css("color", "green");
						$("#frmContact-response").html("Uw bericht is verstuurd.");
						return true;
					} else {
						$(".btn-contact-verzenden").show();
						$("#frmContact-response").css("color", "red");
						$("#frmContact-response").html("Uw bericht kon niet verstuurd worden. Probeer het nogmaals.");
					}
				},
				error: function() {
					$(".btn-contact-verzenden").show();
					$("#frmContact-response").css("color", "red");
					$("#frmContact-response").html("Er is een overwachte fout opgetreden. Uw bericht is niet verstuurd.");
				}
			});
		}
	});

	// form input
	$("#frmContact").find("input").focus(function() { if (!$(this).hasClass("icon-error")) $(this).addClass("sprite bg-input-a"); });
	$("#frmContact").find("input").blur(function() { if (!$(this).hasClass("icon-error")) $(this).removeClass("sprite bg-input-a"); });
	$(".frm-lid").find("input").not("icon-error").focus(function() { $(this).addClass("sprite bg-input-a"); });
	$(".frm-lid").find("input").not("icon-error").blur(function() { $(this).removeClass("sprite bg-input-a"); });

	// poll
	$(".poll-answer").click(function() {
		var data = $(this).attr("id").split("-");
		var pollId = data[3];
		var pollAnswerId = data[2];

		$(".poll-buttons").css("display", "none");
		$.ajax({
			type: "GET",
			url: PATH_LANG + "xml/Poll",
			data: "pollId=" + pollId + "&pollAnswerId=" + pollAnswerId,
			dataType: "html",
			success: function(html) {
				$('.poll-results').html(html);
				$(".poll-results").css("display", "block");
			}
		});
	});

	if ($.browser.msie && parseInt(jQuery.browser.version) == 6)
		$("#browsercheck").click();

})

var to_search = null;
function search() {
    clearTimeout(to_search);
    to_search = setTimeout("goSearch()", 750);
}

function goSearch() {
	$('#menu .search').addClass('sprite bg-menutab-search-a');
	$('.search-results-div').css('display', 'block');
	$('#loadingicon').css('display', 'block');

	$.ajax({
		type: "GET",
		url: PATH_LANG + 'xml/Search?s=' + $('#s').val(),
		data: {},
		dataType: "html",
		success: function(html) {
			$('.search-results-div').html(html);
			$('#loadingicon').css('display', 'none');
		}
	});
}

function closeSearchResults() {
	$(".search-results-div").css("display", "none")
	$("#menu .search").removeClass("sprite bg-menutab-search-a");
}

function swapClassName(obj, className){obj.className = className;}

//checkt een checkbox.....
function checkBox(checkBox, check){document.getElementById(checkBox).checked = check;}

function replaceText(obj, strReplace, strDefault, clear)
{	

	switch(clear)
	{
		case true:obj.value = (obj.value==strDefault) ? strReplace : obj.value;break;
		default:obj.value = (obj.value=="") ? strDefault : obj.value;break;
	}
}

function mOn(obj) {
	var ext = obj.src.slice(-3)
	if(obj.src.indexOf('-on.'+ ext)==-1)
	{
		//obj.src=obj.src.replace('.'+ ext,'-on.'+ ext)
	}
}
function mOut(obj) {
	var ext = obj.src.slice(-3)
	//obj.src=obj.src.replace('-on.'+ext,'.'+ext)
}
