/* h2h.js - copyright (c) 2009 housetohouseisrael.com */

var H2H = new function()
{
    this.ver = '090522' ;
    this.onload = function() {};
    this.nobtmsg = function() { alert( 'These buttons have been temporarily disabled.\nWe apologize for any inconvenience.\n\n' +
        '- To print this page, select Print from your File menu, and\nun-check Print Backgrounds.\n\n- For ' +
        'a PDF, select Print from your File menu, and {Print to PDF} (Mac) or choose {PDF} in the ' +
        'printer list (Windows).\n\n- To email this page, triple-click the address bar above, then ' +
        'click Copy from your Edit menu.  Compose your email and click Paste from the Edit menu to insert the address.' ) ; };
};

H2H.setup = new function() {
    this.init = function() {
        if ( H2H.onload ) H2H.onload() ;
        if ( H2H.menu.onload ) H2H.menu.onload() ;
    };
};

H2H.site = new function() {
    this.onContactForm = function() {
        return true ;
    }
};

H2H.menu = new function() {
    this.curclass = 'curpage' ;
    this.allkids = [] ;
    this.curparent = null ;
    this.mmenu = null ;

    this.onload = function() {
        this.initMenu() ;
        this.markPageMenuItem() ;
    };

    this.markPageMenuItem = function() {
        var loc = window.location.href.substring( window.location.href.lastIndexOf('=') + 1 ) ;
        var links = document.getElementById( 'mmenu' ).getElementsByTagName( 'a' ) ;
        for ( var i = 0 ; i < links.length ; i ++ ) {
            if ( links[i].href.substring(links[i].href.lastIndexOf('=') + 1 ) == loc )
                links[i][ASF.has.attrclass] += ' ' + this.curclass ;
        }
    };

    this.initMenu = function() {
        var mlinks = document.getElementById( 'mmenu').getElementsByTagName( 'A' ) ; 
        for ( var i = 0 ; i < mlinks.length ; i ++ ) {
            if ( mlinks[i][ASF.has.attrclass].indexOf( 'haskid' ) != -1 )
                this.attachParentHandlers( mlinks[i].parentNode ) ;
            else if ( mlinks[i][ASF.has.attrclass].indexOf( 'iskid' ) != -1 )
                this.allkids.push( mlinks[i] ) ;
            else
                this.attachParentHandlers( mlinks[i].parentNode ) ;
        }
        this.mmenu = document.getElementById( 'mmenu' ) ;
        this.mmenu.onmouseout = function() { H2H.menu.onmouseout() ; };
        this.hideallkids();
    };

    this.attachParentHandlers = function( elLI ) {
        elLI.onmouseover = function() { H2H.menu.onmouseover(this); };
    }

    this.showKidsOf = function(elLI) {
        if ( elLI[ASF.has.attrclass].indexOf('mmenu_last') != -1 )
            return ;
        var akid = ASF.getNextTag( elLI, 'LI' ) ;
        while ( akid.firstChild[ASF.has.attrclass].indexOf('iskid') != -1 ) {
            this.showkid(akid);
            akid = ASF.getNextTag(akid, 'LI' );
        }
    }

    this.showkid = function( kidLI ) {
        kidLI.firstChild[ASF.has.attrclass] = 'mmenu iskid' ;
        kidLI[ASF.has.attrclass] = '' ;  /* * */
    }

    this.hideallkids = function() {
        for ( var i = 0 ; i < this.allkids.length ; i ++ ) { /* * */
            this.allkids[i][ASF.has.attrclass] = 'iskid mkidoff mmenu' ;
            this.allkids[i].parentNode[ASF.has.attrclass] = 'mlioff' ; /* * */
        } /* * */
    }

    this.onmouseover = function(e) {
        this.hideallkids() ;
        this.curparent = null ;
        this.showKidsOf(e) ;
        this.curparent = e ;
    }

    this.onmouseout = function(e) {
        this.curparent = null ;
    }
};


var ASF = new function() {
    this.init = function() {
        this.onload() ;
        H2H.setup.init() ;
    }
    this.onload = function() {};
    this.getNextTag = function(e,t) {
        e=e.nextSibling;
        while (e.nodeType != 1)
            e=e.nextSibling;
        if ( (e.tagName.toUpperCase() != t.toUpperCase() ) )
            e = this.getNextTag(e,t);
        return e;
    };
};

ASF.has = new function() {
    var xmp = document.createElement("DIV") ;
    this.filters = typeof document.filters != 'undefined' ;
    this.filter  = typeof xmp.filter != 'undefined' ;
    this.style     = typeof xmp.style != 'undefined' ;
    this.css = !! document.styleSheets ;
    this.attrclass = ((typeof xmp['className']=="string")?'className':'class');
    this.intext  = ( typeof xmp.innerText == 'undefined' ) ? 'textContent' : 'innerText';
    this.styles = new function() {
        var x = null ;
        if ( window.getComputedStyle ) x = window.getComputedStyle(xmp,null);
        else if ( xmp.currentStyle ) x = xmp.currentStyle ;
        else x = xmp.style ;
        this.filter       = typeof x.filter       != 'undefined' ;
        this.opacity      = typeof x.opacity      != 'undefined' ;
        this.MozOpacity   = typeof x.MozOpacity   != 'undefined' ;
        this.KhtmlOpacity = typeof x.KhtmlOpacity != 'undefined' ;
    };
};

