function Wowd() {

    this.curr = null;
    this.currView = '';

    this.run = function(view) {
        this.currView = view;
        if (this.currView == 'hot') {
            $("#menu_hotlist").addClass('menusel');
            this.curr = hot;
            hot.onShow(false);
        } else if (this.currView == 'search') {
            $("#menu_search").addClass('menusel');
            this.curr = search;
            search.onShow();
            search.run();
        } else if (this.currView == 'home') {
            hot.onShow(true);
        } else if (this.currView == 'other') {
            $(".sortopt").hide();
        }
    }

    this.goToHotlist = function(category) {
        if (category != null)
            window.location = 'index.jsp?category=' + category;
        else if (this.currView == 'search')
            window.location = 'index.jsp?category=' + search.category;
        else if (this.currView != 'hot')
            window.location = 'index.jsp?category=All';
    }

    this.goToSearch = function(category) {
        if (this.currView == 'hot')
            window.location = 'index.jsp?search&category=' + hot.category;
        else if (this.currView != 'search')
            window.location = 'index.jsp?search';
    }

    this.goToCategory = function(category) {
        if ($('#search_box').val().trim() == search.htqString && search.tags.length == 0)
            hot.goToCategory(category);
        else if ($('#search_box').val().trim() == '' && search.tags.length == 0)
            hot.goToCategory(category);
        else
            search.goToCategory(category);
    }

    this.runSearch = function() {
        search.runSearch();
        return false;
    }

    this.init = function() {
        hot.init();
        search.init();

        if (window.location.href.indexOf('?search') >= 0)
            wowd.run('search');
        else if (window.location.href.indexOf('category') >= 0)
            wowd.run('hot');
        else if (window.location.href.indexOf('index.jsp') >= 0 && window.location.hash != '')
            location.href = 'index.jsp?category=All' + window.location.hash;
        else if (window.location.href.indexOf('index.jsp') >= 0 || window.location.href.indexOf('jsp') < 0)
            wowd.run('home');
        else
            wowd.run('other');
    }
}

var wowd = new Wowd();

$(document).ready(function() {
    wowd.init();
});
