$(document).ready(function() {

    // replace select menus and checkboxes
    $("input[type=checkbox]").checkBox();
    $("input[type=radio]").checkBox();
    $(".purple-form form select").sSelect({ddMaxHeight: '200px'});

    // registration form
    (function() {
        $('.purple-form .validation-summary-errors ul, #forgotten-pasword .validation-summary-errors ul').wrap('<div class="col1"></div>').parent().after('<div class="col2"><ul></ul></div>');
        if ($('.validation-summary-errors ul li').length > 4) {
            $('.validation-summary-errors ul:first li:gt(3)').appendTo('.validation-summary-errors .col2 ul');
        }
    })();

    // learn button click
    $('div.activities-panel a.button-learn').click(function() {
        $(this).siblings(".education-panel").show();
        return false;
    });

    // close button click
    $('div.education-panel a.button-close-panel').click(
		function() {
		    $(this).parent().hide();
		    return false;
		}
	);

    (function() {
        // adjust header position when viewport high enough
        var header = document.getElementById("page-frame");

        function measureHeight() {
            if (header != null) {
                var headerpos = header.offsetTop;
                if (headerpos > 30) {
                    $("#header").addClass("header-tall");
                } else {
                    $("#header").removeClass("header-tall");
                }
            }

        }

        measureHeight();
        window.onresize = measureHeight;

    })();

	$('a.open-iframe').click(
		function() {
			$("iframe#library-intro-popup").attr("src", $(this).attr("href"));
			$('iframe#library-intro-popup').show();
			return false;
		}
	);

	function closeIframePopup() {
		$('iframe#library-intro-popup').hide();
	};

});
