
var j = jQuery.noConflict();

function Site() {
    var I = this;
    //BEFORE DOM IS READY

   
    //WHEN DOM IS READY
    j(document).ready(function() {
        //browser-specific intialization
        I.browserInit();
        //highlight active links in nav and maybe more
        I.handleNav();
        //remove specific empty elements
        I.removeEmpty();
        //set first-child/last-child classes
        I.firstAndLastChildren();
    });

}

//browser-specific intialization
Site.prototype.browserInit = function() {
    if (j.browser.msie) {

    } else if (j.browser.safari) {

    }
}

//highlight active links in nav and maybe more
Site.prototype.handleNav = function() {
    
    var navHighlighter = new tbelt.url.Highlighter({
        url: document.location.href,
        manualMatches: [
            [/event\/?$/, "/event/admin/event/", "/event/admin/post/", "/event/admin/link/"]
        ],
        alterElements: [{ element: "each", className: "active"}]
    });
    //highlight main nav
    var mainNavLinks = j("div#siteNav a");
    navHighlighter.options.links = mainNavLinks;
    navHighlighter.highlight();

}

//remove specific empty elements
Site.prototype.removeEmpty = function() {
    j("li").filter(":empty").remove();
    
    j("ul").each(function(i, ul) {
        if((/^\s*?$/).test(ul.innerHTML)){
            j(ul).remove();
        }
    });
}

//set first-child/last-child classes
Site.prototype.firstAndLastChildren = function() {
    var firstChildren = j(".blog-actions > ul > li:first-child, .entry-actions > li:first-child, .box-actions > li:first-child, .action-bar > ul > li:first-child");
    firstChildren.addClass("first-child");
    
    var lastChildren = j("div#nothing");
    lastChildren.addClass("last-child");
}

var site = new Site();
