/* nav */
function findPos(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
                curleft = obj.offsetLeft
                curtop = obj.offsetTop
                while (obj = obj.offsetParent) {
                        curleft += obj.offsetLeft
                        curtop += obj.offsetTop
                }
        }
        return [curleft,curtop];
}
function Nav(tab_id) {
        this.tab_id=tab_id;
        this.tab= document.getElementById(this.tab_id);
        this.nav= document.getElementById('nav');
        this.tick= document.getElementById('tick_mark');
        if (!this.tab || !this.tick || !this.nav) {
                return;
        }
        this.old_pos=0;
        this.image_prefix='/i/mark';
        this.image=0;
        this.image_suffix='.gif';
        this.anim_step=0;
        this.tab= document.getElementById(this.tab_id);

        this.reposition= function() {
                if ('IE6'==browser) {
                        /* insane browser, absolute pos */
                        var nav_pos=findPos(this.nav)[1]-10;
                        this.tick.style.display= 'inline';
                        this.tick.style.top= nav_pos+'px';
                }
                var tick_pos= findPos(this.tab)[0]+ this.tab.scrollWidth/2 - 10;
                if (this.old_pos!=tick_pos) {
                        this.tick.style.left=tick_pos+'px';
                        this.old_pos=tick_pos;
                }
                window.setTimeout('nav.reposition()', 200);
        }
        this.animate= function(step) {
                if (this.interval) {
                        clearInterval(this.interval);
                }
                this.anim_step=step;
                this.interval= setInterval('nav.animate_step()', 100);
        }
        this.animate_step= function() {
                var next_image=Math.min(4,Math.max(0,this.image+this.anim_step));
                if (0==next_image || 4==next_image) {
                        clearInterval(this.interval);
                        this.interval=false;
                }
                if (this.image!=next_image) {
                        this.image=next_image;
                        var tick= document.getElementById('tick_mark');
                        tick.src=this.image_prefix+this.image+this.image_suffix;
                }
        }
        /* preload images */
        if (document.images) {
                var preload_image = new Image();
                for (var i=0; i<5; i++) {
                        preload_image.src = this.image_prefix+i+this.image_suffix;
                }
        }
}
function hidenav() {
        if (nav && nav.animate) {
                nav.animate(-1);
        }        
}
function shownav() {
        if (nav && nav.animate) {
                nav.animate(1);
        }
}

/* "antispam" */
function email_cat(a,b,c) {
        return a+String.fromCharCode(0x40)+b+String.fromCharCode(0x2e)+c;
}
function mail_to(a) {
        document.write('<a href="mailto:'+a+'">'+a+'</a>');
}
function pad(d,pad) {
        var s=''+d;
        while (s.length<pad) {
                s='0'+s;
        }
        return s;
}
var timezoneoffset=-(new Date()).getTimezoneOffset();
var timezoneoffset_millis=60000*timezoneoffset;
var timezoneoffset_string=(timezoneoffset>=0? '+'+pad(Math.floor(timezoneoffset/60),2)+pad(timezoneoffset%60,2):'-'+pad(Math.floor(-timezoneoffset/60),2)+pad(-timezoneoffset%60,2));

function localtime(datestr, format) {
        var d= new Date();
        d.setTime(Date.parse(datestr)+timezoneoffset_millis);
        return strftime(d,format);
}
function strftime(date, format) {
        var s=format;
        s=s.replace('%Y', date.getFullYear());
        s=s.replace('%m', pad(date.getMonth()+1,2));
        s=s.replace('%d', pad(date.getDate(),2));
        s=s.replace('%H', pad(date.getHours(),2));
        s=s.replace('%I', pad(date.getHours()%12,2));
        s=s.replace('%p', Array('am','pm')[Math.floor(date.getHours()/12)]);
        s=s.replace('%M', pad(date.getMinutes(),2));
        s=s.replace('%S', pad(date.getSeconds(),2));
        return s;
}
