(function($) {
    SITE = {
        common : {
            init     : function() {
                $('a.newwindow').live('click', function(e){
                    e.preventDefault();
                    var url = $(this).attr('href');
                    window.open(url);
                });

                $("#menu-search").focus(function(){
                    $(this).animate({width: 160}, 300);
                });
            },
            finalize : function() {
            }
        },
        home : {
            init     : function() {
                var numSlides = $("#scrollable-items li").length;
                if(numSlides > 6){
                    $("#scrollable-wrapper").jCarouselLite({
                         btnNext: "#scroll-right",
                         btnPrev: "#scroll-left",
                         visible: 6,
                         speed: 100
                     });
                }

                $("#scrollable-wrapper").css('width', 'auto');
            }
        },
        'category' : {
            init : function(){
                var numSlides = $("#scrollable-items li").length;
                if(numSlides > 6){
                    $("#scrollable-wrapper").jCarouselLite({
                         btnNext: "#scroll-right",
                         btnPrev: "#scroll-left",
                         visible: 6,
                         speed: 100
                     });
                }else{
                    $("#scroll-left,#scroll-right").hide();
                }

                $("#scrollable-wrapper").css('width', 'auto');
            }
        }
    };

    UTIL = {
        fire : function(func, funcname, args) {
            var namespace = SITE;  // indicate your obj literal namespace here
            funcname = (funcname === undefined) ? 'init' : funcname;
            if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function') {
                namespace[func][funcname](args);
            }
        },
        loadEvents : function() {
            var bodyId = document.body.id;
            // hit up common first.
            UTIL.fire('common');
            // do all the classes too.
            $.each(document.body.className.split(/\s+/), function(i, classnm) {
                UTIL.fire(classnm);
                UTIL.fire(classnm, bodyId);
            });
            UTIL.fire('common', 'finalize');
        }
    };

    // kick it all off here
    $(document).ready(UTIL.loadEvents);
})(jQuery);
