$(document).ready(function(){
	$('#searchform').seacrhDh();
});

if(jQuery) (function(c){
	$.fn.seacrhDh = function(params){
		var conf = $.extend({
			textInput:'#fullText',
			valueDef:'span'
		}, params);
		return this.each(function(){
			var c=conf,o=$(this),i=o.find(c.textInput),t=o.find(c.valueDef).html();
			if(t==null){t='Stel uw vraag'};
			if(i.val()==''){i.val(t)};
			o.submit(function(){
				if((i.val()==t)||(i.val()=='')){
					return false;
				}
			});
			i.blur(function(){
				if(i.val()==''){
					i.val(t);
				}
			});
			i.focus(function(){
				if(i.val()==t){
					i.val('');
				}
			});
		})
	}
})(jQuery);

// Events binden
var bindFocusEvents = function() {
    //fullText
    //	var fullText = document.getElementById("fullText");
    //	if (fullText) {
    //		fullText.onfocus = function() {
    //			if (fullText.value == "Stel uw vraag") {
    //				fullText.value = "";
    //				fullText.style.color="#646464";
    //			}
    //		};
    //		fullText.onblur =  function() {
    //			if (fullText.value === "") {
    //				fullText.value = "Stel uw vraag";
    //				fullText.style.color="#646464";
    //			}
    //		};
    //	}

    //postcode
	
	function clearSearchBox(trefwoord) {
		if (trefwoord) {
			trefwoord.onfocus = function() {
				if (trefwoord.value == "trefwoorden") {
					trefwoord.value = "";
					trefwoord.style.color = "#999";
				}
			};
			trefwoord.onblur = function() {
				if (trefwoord.value === "") {
					trefwoord.value = "trefwoorden";
					trefwoord.style.color = "#999";
				}
			};
		}
	}
	
	clearSearchBox(document.getElementById("zoekallewoorden"));
	clearSearchBox(document.getElementById("zoekeenvandewoorden"));
	clearSearchBox(document.getElementById("zoeknietdewoorden"));
	
	
};

var bindLayerEvents = function() { 
	//layerbutton1
	var layerbutton1 = document.getElementById("layerbutton1");
	if (layerbutton1) {
		layerbutton1.onclick = function() {
			document.getElementById("videoLayer").style.display = "block";
			return false;
		};
	}

	//layerbutton2
	var layerbutton2 = document.getElementById("layerbutton2");
	if (layerbutton2) {
		layerbutton2.onclick = function() {
			document.getElementById("videoLayer").style.display = "none";
			return false;
		};
	}
};

var changeClasses = function() {
	var agendaSearch = document.getElementById("zoekCriteria");
	if (agendaSearch)
	{
		$("#zoekCriteria").removeClass("static");
		$("#zoekCriteria").addClass("dynamic");
	}
	var filtersearchListing = document.getElementById("filterSearchOptions");
	if (filtersearchListing)
	{
		$("#filterSearchOptions").removeClass("static");
		$("#filterSearchOptions").addClass("dynamic");
	}
	var tellaFriend = document.getElementById("tellAFriend");
	if(tellaFriend)
	{
		$("#tellAFriend").removeClass("tellaFriendStatic");
		$("#tellAFriend").addClass("tellaFriend");
		$('.stuurdoor').show();
	}
	var dynamise = document.getElementById("dynamise");
	if (dynamise)
	{
		$("#dynamise").removeClass("static");
		$("#dynamise").addClass("dynamic");
	}
	var filterSearchOptions = document.getElementById("filterSearchOptions");
	if (filterSearchOptions)
	{
		$("#filterSearchOptions").removeClass("static");
		$("#filterSearchOptions").addClass("dynamic");
	}

	var addSocial = document.getElementById("addSocial");
	if (addSocial)
	{
		$("#addSocial").removeClass("static");
		$("#addSocial").addClass("dynamic");
	}
	$('.hidden').hide();
	
	if($("#zoekwoorden"))
	{
	    $("#zoekwoorden").focus(function(){
	            blurfocus($(this), 'trefwoorden', '');
	    });
	    $("#zoekwoorden").blur(function(){
	            blurfocus($(this), '', 'trefwoorden');
	        });       
	}
}

// Maak de antwoorden van de gevonden vragen onzichtbaar
function makeChildrenInvisible() 
{
    if($(".zoekscherm"))
    {
        $(".zoekscherm").each(function() {
            $(this).children("li").each(function() {
                var oListItem = $(this);
				var aSelects = oListItem.find('select');
				if (aSelects.length > 0)
				{
					oListItem.find("div").hide();
                	aSelects.change(function() {
						var oSelect = $(this);
						oSelect.parent().find('div').hide();
						oSelect.parent().find('div#' + oSelect.val()).show();
					});
					
					oListItem.find("a.question").click(function(event) {
						event.preventDefault();
						oListItem.find('div#' + $(aSelects.get(0)).val()).toggle();
					});
				}
				else
				{
					oListItem.find("p").hide();
                	oListItem.find("a.question").click(function(event) {
						event.preventDefault();
						enlargeItem($(this).parent());
					});
				}
            });
        });
    }
}

function fadeLogos() {
	if($('#imagefader_logos').length > 0)
	{
		$('#imagefader_logos').innerfade({
			speed: 'slow',
			timeout: 4000,
			type: 'sequence'
		});
	}
}

// Pagina is geladen
$(function() {
    bindFocusEvents();
    bindLayerEvents();
    changeClasses();
    fadeLogos();
    makeChildrenInvisible();
});

