function setupSlider_inburgeren() {
    var startValue = $(".ui-slider-handle").html();
    $(".slider").slider({
        range: "min",
        min: 1,
        max: 9,
        value: startValue,
        step: 1,
        slide: function(e, ui) {
            //var bg = "url(../Images/slider_bg" + ui.value + ".gif)";
            //$(".slider").css('background-image', bg);
            if (ui.value == '1')
                $(".ui-slider-handle").html('');
            else
                $(".ui-slider-handle").html(ui.value);
            $(".slidervalue").val(ui.value);
        }
    });
    if (startValue == '1')
        $(".ui-slider-handle").html('');
}
function setupSlider_anderekm() {
    var startValue = $(".ui-slider-handle").html();
    $(".slider").slider({
        range: "min",
        min: 1,
        max: 9,
        value: startValue,
        step: 1,
        slide: function(e, ui) {
            //var bg = "url(../Images/slider_bg" + ui.value + ".gif)";
            //$(".slider").css('background-image', bg);
            if (ui.value == '1')
                $(".ui-slider-handle").html('');
            else
                $(".ui-slider-handle").html(ui.value);
            $(".slidervalue").val(ui.value);
        }
    });
    if (startValue == '1')
        $(".ui-slider-handle").html('');
}

function showTargetgroup() {
    $(".targetgroup").hide();
    var tg = $(".zoekAls").val();
    $(".targetgroup_" + tg).show();

    $(".ikzoek").show();
    $(".selections select").removeAttr("disabled");
    $(".shorterSelections input.standardSubmit").removeAttr("disabled");
    $("#postcodeBox").show();
    $(".selections select").show();
    $("#extendedsearchSubmit").show();

}

function hideTargetgroup() {
    $(".targetgroup").hide();
    $(".ikzoek").hide();
    $(".selections select").hide();
    $(".selections select").attr("disabled");
    $(".shorterSelections input.standardSubmit").attr("disabled");
    $("#postcodeBox").hide();
    $("#extendedsearchSubmit").hide();
}

$(document).ready(function() {

    $("p a[href$='.pdf']").addClass("pdf");

    if ($(".contentPopup").length > 0) {
        //$(".contentPopup").hide();
        $(".contentPopup").fancybox({
            'hideOnContentClick': true
        });

        /*$(".loadPopupje").click(function(){
        var thisId = $(this).attr("href");
        alert(thisId);
        $(thisId).dialog();
        return false;
        });*/
    }

    if ($(".inburgeren").length > 0) {
        setupSlider_inburgeren();
    }
    if ($(".anderekm").length > 0) {
        setupSlider_anderekm();
    }

    if ($(".item-switcher").length > 0) {
        $(".item-switcher").itemswitcher({ onSwitch: function(object, options) {
            doSifr();
        }
        });
    }

    /*
    Here the links in the trackLinks block are tracked using Analystics
    */
    $(".trackLinks a").each(function() {
        $(this).click(function() {
            pageTracker._trackEvent('WAI licentienemers', ($(this).attr('href')).replace('mailto:', ''));
        });
    });
    $(".trackLinksKeurmerk a").each(function() {
        if ($(this).attr('href').indexOf('mailto') < 0) {
            $(this).click(function() {
                alert("test");
                pageTracker._trackEvent('uitgaande link', 'workshopaanmeldformulier');
            });
        }
    });

    $.pseudoFocus();


    if ($('a.email').length > 0) {
        $('a.email').nospam({
            replaceText: true
        });
        var aemail = true;

        setTimeout(function() {
            jQuery.each(jQuery.browser, function(i, val) {
                if (i == "msie" && jQuery.browser.version.substr(0, 1) == "7.0")

                    if (aemail == true) {
                    var newMail = $('a.email').html();
                    var mailLength = newMail.length;
                    alert(mailLength);
                    mailLength = mailLength - 2;
                    alert(mailLength);
                    newMail = newMail.substr(0, mailLength);
                    $('a.email').html(newMail);
                    aemail = false;
                }
            });
        }, 1
		);
    }

    /*
    if($('body:not(.keurmerk) a.email').length > 0) {
    $('a.email').nospam({
    replaceText: true});
    var aemail = true;
			
			setTimeout(function(){
    jQuery.each(jQuery.browser, function(i, val) {
    if(i=="msie" && jQuery.browser.version.substr(0,1)=="7.0")
    alert("before");
    if(aemail == true){
    var newMail = $('a.email').html();
    newMail = newMail.substr(0,18);
    $('a.email').html(newMail);
    aemail = false;
    }
    });
    },1
    );
    }
    */

    if ($("#tabContainer").length > 0) {

        $('#tabButtons > ul').tabs();


        var param = parseInt($('#selectedtab').val());
        if (param > -1)
            $('#tabButtons > ul').tabs('select', param);
    }

    $(".tostep1").click(function() {
        $("#submittab").val(0);
        $(this).closest("form").submit();
        //$("#tabButtons > ul").tabs('select', 0);
        return false;
    });

    $(".tostep2").click(function() {
        $("#submittab").val(1);
        $(this).closest("form").submit();
        return false;
    });


    // Form foldout 

    if ($("#postadresSet").length > 0 && $("#openpostadres").val() != 1) {
        $("#postadresSet").hide();
    }

    if ($("input#postadres_ja").focus(function() {
        $("#postadresSet").show(200);
    }));

    if ($("input#postadres_nee").focus(function() {
        $("#postadresSet").hide(200);
        $("#factuuradresSet").hide(200);
    }));

    if ($("#factuuradresSet").length > 0 && $("#openfactuuradres").val() != 1) {
        $("#factuuradresSet").hide();
    }

    if ($("input#factuuradres_ja").focus(function() {
        $("#factuuradresSet").show(200);
    }));

    if ($("input#factuuradres_nee").focus(function() {
        $("#factuuradresSet").hide(200);
    }));

    // Form validatie

    if ($(".WaiForm").length > 0) {
        $(".WaiForm").validate();
    }

    // Watermarks

    if ($(".zoektermwatermark").length > 0) {
        $(".zoektermwatermark").Watermark("bedrijfsnaam of trefwoord", "#666");
    }

    if ($("#location, #zoeklocatie").length > 0) {
        $("#location, #zoeklocatie").Watermark("plaats of postcode", "#666");
    }
    /* class variant*/
    /*
    if($("#bedrijfsnaam, .zoekterm").length > 0) {
    $("#bedrijfsnaam, .zoekterm").Watermark("bedrijfsnaam of trefwoord", "#666");
    }
    */

    if ($(".location, .zoeklocatie").length > 0) {
        $(".location, .zoeklocatie").Watermark("plaats of postcode", "#666");
    }

    if ($("#bedrijfsnaam2").length > 0) {
        $("#bedrijfsnaam2").Watermark("bedrijfsnaam of trefwoord", "#666");
    }

    if ($("#location2").length > 0) {
        $("#location2").Watermark("plaats of postcode", "#666");
    }

    //tooltip 

    if ($("a.tooltip").length > 0) {
        $("a.tooltip").tooltip({
            bodyHandler: function() {
                return $($(this).attr("href")).html();
            },
            showURL: false
        });
    }

    if ($(".accordion").length > 0) {
        $(".accordion").accordion(
		{
		    autoHeight: false,
		    active: 0,
		    alwaysOpen: true
		});

        $(".ui-accordion-header").click(function() {
            $(this).next().fadeIn();
        });

    }

    if ($(".inklaplijst").length > 0) {
        $(".inklaplijst").accordion(
		{
		    active: false,
		    autoHeight: false,
		    alwaysOpen: true,
		    header: 'h5'
		});
    }

    if ($(".vragenlijst").length > 0) {
        $(".vragenlijst").accordion(
		{
		    autoHeight: false,
		    active: false,
		    alwaysOpen: true,
		    header: 'h3'
		});
    }


    // Toggle 


    $(".foldout").hide();

    $(".toggle").toggle(function() {
        $(this).parent().find(".foldout:first").fadeIn(200);
        $(this).text("sluit venster");
        $(this).addClass("toggleActive");
        return false;

    }, function() {
        $(this).parent().find(".foldout:first").fadeOut(200);
        $(this).text("Help mij met zoeken");
        $(this).removeClass("toggleActive");
        return false;
    });

    // postcodeRange	

    $(".postcodeRange").hide();

    $("#zoeklocatie").keypress(function(event) {
        if ($(this).val().length < 1) {
            $(".postcodeRange").hide();
        } else if (event.keyCode == '8' && $(this).val().length < 3) {
            $(".postcodeRange").hide();
        } else if ($(this).val().match(/^[0-9]+$/)) {
            $(".postcodeRange").show(400);
        }
    }, function() {
        $(".postcodeRange").hide();
    });

    $("#alleenWAI").click(function() {
        ($(this)).closest("form").submit();
    });

    $(".tagcloudword").click(function() {
        var keyword = $(this).text();
        $("#zoekterm").val(keyword);
        ($(this)).closest("form").submit();
    });


    $("#postcodeBox").hide();
    $(".selections select").attr("disabled", "disabled");
    $(".shorterSelections input.standardSubmit").attr("disabled", "disabled");
    $(".ikzoek").hide();
    $("#extendedsearchSubmit").hide();

    $(".targetgroup").hide();
    var tg = $(".zoekAls").val();
    $(".targetgroup_" + tg).show();
    if (tg != "geen") {
        showTargetgroup();
    }

    $("#extendedsearchSubmit").click(function() {
        $("#extendedsearch").val("1");
        return true;
    });

    $(".formsubmitlink").click(function() {
        $("#extendedsearch").val("1");
        $(this).closest("form").submit();
        return false;
    });

    if ($(".zoekAls").length > 0) {

        $("#rangeZoek").Watermark("plaats of postcode", "#666");

        //$("#zoekAls").selectbox();

        //$(".selectbox-wrapper li").click(function() { 
        $(".zoekAls").change(function() {


            if ($(".zoekAls").val() == "geen") {
                hideTargetgroup();
            } else {
                showTargetgroup();
            }

            // Dienstverlener heeft alleen diensten
            if ($(".zoekAls").val() == "dienstverlener" || $(".zoekAls").val() == "geen")
                $(".ikzoekbedrijf").hide();
            else
                $(".ikzoekbedrijf").show();



            var selectedValue = $(this).text();

        });

    }

    $(".foldoutWAI").hide();

    $(".waiToggle").toggle(function() {
        $(this).parent().find(".foldoutWAI:first").fadeIn(200);
        $(this).addClass("waiToggleActive");
        return false;

    }, function() {
        $(this).parent().find(".foldoutWAI:first").fadeOut(200);
        $(this).removeClass("waiToggleActive");
        return false;
    });

    $(".close").click(function() {
        $(".waiToggle").click();
        return false;
    });

    $(".publicatiedetail").hide();
    $(".publicatiedetail").css({
        "position": "absolute",
        "right": "0",
        "top": "0",
        "width": "225px"
    });
    $(".publicatielijst li a.item-leader").click(function() {
        $(".publicatiedetail").hide();
        $(this).parent().find(".publicatiedetail").show();
        $("a.item-leader").removeClass("current");
        $(this).addClass("current");
        return false;
    });


	$("h3:contains('Ausems \& Kerkvliet, arbeidsmedisch adviseurs is in het bezit van het Blik op Werk Keurmerk')").after("<p>Ausems & Kerkvliet, arbeidsmedisch adviseurs heeft de volgende resultaten behaald (in vergelijking tot de normen van het Blik op Werk Keurmerk).</p>");

});




