var DokterVanWeering = new (function() {
    this.loadPage = function(url) {
        jQuery('#container').load(url + ' #container', function() {
            jQuery('#commentform').slideUp();
        });
    }
    this.loc = window.location.protocol + '//' + window.location.hostname;

    this.init = function() {
        jQuery('#sidebar>ul>li').addClass('ui-corner-left');
        
        if(window.location.hash.length > 0) {
            var href = window.location.hash.replace('#');
            DokterVanWeering.loadPage(href + (href.indexOf('?') > -1 ? '&' : '?') + 'ajax=1');
        }
        
        jQuery('#container a, #header a').live('click', function(ev) {
            var href = jQuery(this).attr('href');
            if(jQuery.support.hrefNormalized) {
                href = href.replace(DokterVanWeering.loc, '');
            }
            
            // we do wish to keep admin-links valid
            if(href.indexOf('wp-admin') > -1) { return true; }
            
            DokterVanWeering.loadPage(href + (href.indexOf('?') > -1 ? '&' : '?') + 'ajax=1');
            window.location = '#' + href;
            
            if(typeof(ev.preventDefault)!=='undefined') ev.preventDefault();
            if(typeof(ev.stopPropagation)!=='undefined') ev.stopPropagation();
            
            return false;
        });
        
        jQuery('.post h2 .toggle').live('click', function() {
            jQuery(this).parent().siblings('.entry').slideToggle();
            return false;
        });
        
        jQuery('#respond').live('click', function() {
            jQuery(this).siblings('form').slideToggle();
            return false;
        });
        jQuery('#commentform').slideUp();
    };
})();

jQuery(DokterVanWeering.init);
