//$("body").hide();
(function($) { 
    
    var h_clearform = function(id) {
        $(':input', id)
            .not(':button, :submit, :reset, :hidden')
            .val('')
            .removeAttr('checked')
            .removeAttr('selected');
    }

    var init_login = function() {
        if ($("#login-box").length) {
            $("#login-box").submit(function(event) {
                event.preventDefault();
                var submission_url = $("#login-box").attr("action").replace(ajaxurl,ajaxurl+"a/");
                $.post(submission_url, $("#login-box").serialize(), function(r) {
                    responseJSON = $.parseJSON(r);
                    $("#login-message").removeClass().addClass(responseJSON.status).html(responseJSON.message);
                    setTimeout(function() { window.location = ajaxurl+"login"; }, 2000);
                });
            });
        }
    }

    var init_buttons = function() {
        $("button, [type=submit], .button").button();
        $("#sidebar #login").button({ icons: { primary: "ui-icon-key" } });
        $("#sidebar #dashboard").button({ icons: { primary: "ui-icon-gear" } });
    }
    
    var init_frontend_add = function() {
        $("[name=fe-add]").submit(function(event) {
            event.preventDefault();
            var submission_url = $("[name=fe-add]").attr("action").replace(ajaxurl,ajaxurl+"a/");
            $.post(submission_url, $("[name=fe-add]").serialize(), function(r) {
                responseJSON = $.parseJSON(r);
                $("#fe-added-box").html(responseJSON.html);
            });
            h_clearform("[name=fe-add]"); // reset
        });
    }

    var init = function() {
    	zob_type=$("#zob_type").val(); // gets the currently active zob_type
        init_buttons();
        init_login();
        init_frontend_add();        
    };
    $(init);
    //$("body").fadeIn(); // removes the flash of unstyled forms (mostly)
    
    //dynamic date line height adjustment for the schedule sidebar
    $( '.event-schedule .detail', '#sidebar-agenda' ).each( function() {
    	h = Number( $(this).css( 'height' ).substr( 0, $(this).css( 'height' ).indexOf( 'px' ) ) );
    	p = Number( $(this).css( 'paddingTop' ).substr( 0, $(this).css( 'paddingTop' ).indexOf( 'px' ) ) * 2 );
    	$( this ).prev( 'li' ).css({ 'line-height':h+p+'px' });
    });
})(jQuery);

