/* $Id: bm.js 1950 2007-03-28 16:51:28Z josh $ */
var BM = {
    initPage : function() {
        BM.updateSubNav();
        BM.setCommentFields();
    },
    newWinStyle : {
        'imagePop' : [
          'imagePop',
          'scrollbars=yes,resizable=yes,status=yes,toolbar=yes,'
          + 'location=yes,menubar=yes'
          
        ],
        'newsite' : [
          '', //fill to force target name
          'scrollbars=yes,resizable=yes,status=yes,toolbar=yes,'
          + 'location=yes,menubar=yes'
        ],
        'popup' : [
          '', //fill to force target name
          'width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,'
          + 'location=yes,menubar=yes'
        ]
    },
    newWin : function(link,styleName,customStyle) {
        var targ = link.target || 'newsite';
        if (!styleName) styleName = targ;
        var attr = customStyle;
        if (!attr) {
            if (!styleName) styleName = 'newsite';
            attr = BM.newWinStyle[styleName] || BM.newWinStyle.popup;
        }
        targ = attr[0] || targ;
        var newWin = window.open(link.href, targ, attr[1]);
        newWin.focus();
        return false;
    },
    imagePop : function(link,width) {
        if (!width) width = 800;
        width += 50;
        var height = width > 500 ? 600 : width + 100;
        var attr = 'width=' + width + ',height=' + height + ','
          + BM.newWinStyle.imagePop[1];
        BM.newWin(link,'imagePop', ['imagePop', attr]);
        return false;
    },
    activeSubNav : {}, // for subnavigation highlighting
    updateSubNav : function() {
        $H(BM.activeSubNav).keys().each( function(slug) {
            $$('li.bmn_sec-' + slug).each( function(li) {
                Element.addClassName(li,'bmn_active');
            });
        });
    },
    dispTip : function(tips) {
        if (!tips || !tips.length) return;
        var i = (60 / tips.length);
        var d= new Date(); var s= d.getSeconds();
        var show = Math.floor(s/i);
        if (show >= tips.length) show = show -1;
        $$('div.bmw_tip' + tips[show]).each(function(tip) {
          tip.style.display = 'block';
        });
    },
    setCommentFields : function() {
        if (!BM.cName || !BM.cEmail || !BM.cURL) return;
        var nlen = 7; //bmcomm length
        var i = 0;
        var c= document.cookie;
        var value;
        while (i < c.length) {
            var j = i + nlen;
            if (c.substring(i,j) == 'bmComm=') {
                var endstr = c.indexOf(';',j);
                if (endstr < 0) endstr = c.length;
                value = unescape(c.substring(j,endstr));
                break;
            }
            i = c.indexOf(' ',i) + 1;
            if (i==0) break;
        }
        if (!value) return;
        var vals = value.split(':::');
        $(BM.cName).value = vals[0];
        $(BM.cEmail).value = vals[1];
        $(BM.cURL).value = vals[2];
        $('bmf_comment_remember').checked = true;
    },
    saveCommentCookie : function() {
        if (!BM.cName || !BM.cEmail || !BM.cURL) return;
        var name = $F(BM.cName), email = $F(BM.cEmail), url = $F(BM.cURL);
        if ($('bmf_comment_remember').checked) {
            var expDate = new Date();
            //safari has a setdate bug that limits number of days
            expDate.setDate(expDate.getDate() + 96);
            expDate.setDate(expDate.getDate() + 96);
            document.cookie = 'bmComm=' + escape(name+':::'+email+':::'+url)
              + '; expires=' + expDate.toGMTString();
        }
        else {
            document.cookie = 'bmComm=;expires=Thu, 01-Jan-70 00:00:01 GMT';
        }
    }
    
};
Event.observe(window,"load",BM.initPage,false);