Site = {
    server: 'http://a:3060/', // must include trailing slash 
    toolkit: {
        cacheImage: function(opts) {
        // opts.src: path to image
            var a = new Image();
            a.src = opts.src;
            return a;
        },
        isDescendant: function(a, b) {
            // is a descendant of b?
            var p = $(a).parents();
            var ret = false;
            p.each( function(i) { 
                if (b == p[i]) ret = true;
            });
            return ret;
        }
    }
};

$(function() {

    // Make main-content as tall as the tallest of its // child columns (can't
    // set overlow to anything other than visible because of subnav's position
    var ch = [ 
        $('#main-content .left-column').height(),
        $('#main-content .middle-column').height(),
        $('#main-content .right-column').height()
    ];

    var h = Math.max( ch.pop(), ch.pop(), ch.pop() );

    $('#main-content').css('height', h + 'px'); 

});

// only run on homepage
$(function() {
    if (!$('BODY.homepage').length > 0) return false;

    Site.NewsTicker = function () {

        var
        _element, // ref to UL containing news items
        _items,
        _number_of_items,
        _item_height,
        _current, // current item (indexed off 0)
        _current_Y // Y position of current item
        ;

        function _init() {
            _element = $('UL.news');
            _items = $('UL.news').children();
            _number_of_items = _items.length;
            if (_number_of_items == 0)
                throw new Error('NewsTicker: no news items');
            _item_height = $(_items[0]).height(); 
            _current = 0;
            _currentY = 0;
            _schedule_next();
        }
        
        function _get_next() {
            if (_current == _number_of_items - 1) { 
                _current = 0; _current_Y = 0; 
            }
            else { _current = _current + 1; _current_Y =  _current * 25; }
            _transition();
        }

        function _transition() {
            var e = $(_element);
            e.queue(function() { $(this).fadeOut(1500); $(this).dequeue(); });
            e.queue(function() { 
                    $(_items).each( function(i) {
                        if (i == _current) {$(this).removeClass('display-none')}
                        else { $(this).addClass('display-none') }
                    });
                    $(this).dequeue(); 
            });
            e.queue(function() { 
                    $(this).fadeIn(1500, function() { _schedule_next(); }); 
                    $(this).dequeue(); 
            });
        }

        function _schedule_next() { var t = setTimeout(_get_next, 5000); }

        return { init: function(opts) { _init(opts) } }

    }();
   
    Site.NewsTicker.init();

    // call json file, parse it, and populate list
    /*
    $.getJSON(Site.server + "assets/js/news.js", function(json){
        $.each(json.news_items, function() {
            var html_string = '<li class="display-none">' + this.copy 
                + ' - <a href="' + this.url + '">click here</a></li>';
            $('UL.news').append(html_string);
        });
        $('UL.news > LI:first').removeClass('display-none');
        Site.NewsTicker.init();
    });
    */

});

