(function () {
    if (typeof TONBO !== 'undefined') { return; }

    TONBO = {
        imgs: {}
    };

    var T = TONBO;

    T.init = function (pfx, sfx, imgs, fixed) {
        var src = [];
        // compute page images src and preload them
        $.each(imgs.split(','), function (i) {
            T.imgs['p'+i] = (pfx || '') + this + (sfx || '');
            if (document.images) {
                (new Image()).src = T.imgs['p'+i];
            }
        });
        // toggle up-/dn- class on non fixed element ("this" is the dom element)
        function upDn(a,b,which) {
            if (this.className.indexOf('fixed') < 0) {
                var m = this.className.match(/(up|dn)-([\w-]+)/);
                $(this).removeClass(m[0]).addClass({up:'dn',dn:'up'}[which || m[1]] + '-' + m[2]);
            }
        };
        $(document).ready(function () {
            // add pages dots
            var html = [];
            $.each(T.imgs, function (id) {
                html.push('<a id="',id,'" href="javascript:void(0);"><img class="nav page up-dot" src="../img/_spacer.gif"></a><img class="sep" src="../img/_spacer.gif">');
            });
            $('.pages').html(html.join(''));
            // set dots hover events
            $('.pages a').hover(function () {
                $('.pages a img').each(function () {
                    $(this).addClass('up-dot').removeClass('dn-dot fixed');
                });
                $('#currPage')[0].src = T.imgs[this.id];
                upDn.call(this.firstChild,0,0,'up');
                $(this.firstChild).addClass('fixed');
            });
            // set fixed navigation elements and set their css to dn-
            $(fixed).each(function () {
                this.parentNode.href = 'javascript:void(0);';
                upDn.call(this,0,0,'up');
                $(this).addClass('fixed');
            });
            // set navigation hover highlight event
            $('.nav').hover(upDn, upDn);
        });
    };
})();

