$(document).ready(function() {

    $(document).ready(function() {
        $('.homepageSearch input:checkbox').checkbox({ cls: 'homepage-checkbox', empty: '/images/icons/empty.png' });
        $('.level1Search input:checkbox').checkbox({ cls: 'level1-checkbox', empty: '/images/icons/empty.png' });
    });	
    
    $('h3.refineInactive').click(function(event) {
        event.preventDefault();
        $(this).next('.searchFilterContainer').slideToggle("fast");
        $(this).toggleClass("refineActive");
    });

    $('h4.IndustryLevel1,h4.IndustryHomepage').click(function(event) {
        event.preventDefault();
        if ($(this).is(".IndustryHomepage")) {
            $(this).toggleClass("IndustryHomepageSelected");
        }
        else {
            $(this).toggleClass("IndustryLevel1Selected");
        }
        $(this).next('div').slideToggle(200);
    });

    $('h5.SectorLevel1, h5.SectorHomepage').click(function(event) {
        event.preventDefault();
        if ($(this).is(".SectorHomepage")) {
            $(this).toggleClass("SectorHomepageSelected");
        }
        else {
            $(this).toggleClass("SectorLevel1Selected");
        }
        $(this).next('div').slideToggle(200);
    });

    $('.level1SearchHeader a').click(function(event) {
        event.preventDefault();
        $(this).parent().next(".level1SearchContent").slideToggle("fast");
        $(this).parent().toggleClass("level1SearchHeaderActive");
    });

    $('.homepageSearchHeader a').click(function(event) {
        event.preventDefault();
        $(this).parent().next(".homepageSearchContent").slideToggle("fast");
        $(this).parent().toggleClass("homepageSearchHeaderActive");
    });

    function categorySelection() {
        var intTotalSelected = 0;
        var intIndustrySelected = 0;
        $('#categoryContainer').children().each(function() {
            if ($(this).attr('tagName') == 'DIV') {
                var containerDivs = $(this).find("div.categoryCBL");
                containerDivs.each(function() {
                    var checkboxes = $(this).find("INPUT[type='checkbox']");
                    $(checkboxes).each(function() {
                        if ($(this).attr('checked')) {
                            intTotalSelected++;
                            intIndustrySelected++;
                            $(this).next().css({ fontWeight: "bold" });
                        }
                        else {
                            $(this).next().css({ fontWeight: "normal" });
                        }
                    });
                });
                if (intIndustrySelected > 0) {
                    $(this).prev().find("span.industryCount").html(intIndustrySelected + " selected");
                }
                else {
                    $(this).prev().find("span.industryCount").html("");
                }
                intIndustrySelected = 0;
            }
        });

        if (intTotalSelected > 0) {
            $("#categoryCount").html(intTotalSelected + " selected");
        }
        else {
            $("#categoryCount").html("&nbsp;");
        }
    }

    $("#categoryContainer").click(function() {
        categorySelection();
    });

    function filterCounts(section) {
        var intSelected = 0;
        var checkboxes = $(section).find("INPUT[type='checkbox']");
        $(checkboxes).each(function() {
            if ($(this).attr('checked')) {
                $(this).next().css({ fontWeight: "bold" });
                intSelected++;
            }
            else {
                $(this).next().css({ fontWeight: "normal" });
            }
        });
        if (intSelected > 0) {
            $(section).prev().find("span.selectionCount").html(intSelected + " selected");
        }
        else {
            $(section).prev().find("span.selectionCount").html("");
        }
    }

    $(".searchFilterContainer").click(function() {
        filterCounts($(this));
    });

    $(".searchFilterContainer").each(function() {
        filterCounts($(this));
    });

    categorySelection();

});


// SEARCH OPTIONS

$(document).ready(function(){
	$('.searchOptions').hide();
	$("p.linkEverything").click(function () {
		$('.searchOptions').toggle();
	});
	$(".searchOptions h4").click(function () {
		$('.searchOptions').toggle();
	});
});

$(document).ready(function() {
    $(".latestVacancyTabs").tabs({ fxFade: true, fxSpeed: 'fast' });
});
