/*
 * netscape_support.js - A browser compatibility module.  Runs before any dojo.require statements.
 *
 *
 *
 * --- ABOUT THIS FIX ---
 *
 * Adds the following support for Netscape:
 *      - Eliminates a 'Too much recursion' issue that gets thrown by dojo.declare._core._findMixin
 *      - New dojo.isNS property, which gets set to the Major version of the browser
 *      - New dj_ns class for dijit (just like dj_ie, dj_ie6, dj_gecko, etc.)
 *      - If you have any questions/suggestions please contact me at strickn@gmail.com
 *
 *
 *
 * --- PLEASE NOTE ---
 *
 * This must be included right after you include the dojo.js (dojo.js.uncompressed.js)
 * files, such that your <script></script> tags go in an order like this...
 *
 * <script type="text/javascript" src="/js/dojo-release-1.1.0/dojo/dojo.js"></script>
 * <script type="text/javascript" src="/js/where_you_want_this_fix/netscape_support.js"></script>
 *
 *
 *
 * --- TODO & Figure Out ---
 *
 *      - Optimize this more if possible
 *      - Should I be removing the dj_gecko class or not?
 *
 */

(function(){
       
        /* First we need to sniff the userAgent string and see if Netscape is even being used. I'm
         * going to borrow the same variable names from dojo/_base/_loader/hosenv_browser to make
         * things similar.
         */
        var n = navigator;
        var dua = n.userAgent;
        var dav = n.appVersion;
       
        /* Get the version number of Netscape and assign our dojo.isNS property. */
        dojo.isNS = dua.indexOf("Netscape") == -1 ? 0 : parseFloat(dav);
       
        /* If Netscape really is being used, then we need to do a few things to make life
         * easier for ourselves down the road.
         */
        if(dojo.isNS){
               
                /* First, we need to re-define the dojo.declare._core._findMixin function, or we're
                 * going to end up in an endless loop, thus throwing a 'Too much recursion' error.
                 */
                dojo.declare._core._findMixin = function(mixin){
                        var c = this.constructor, p, m;
                        while(c){
                                p = c.superclass;
                                m = c.mixin;
                               
                                /* We change the following line to accomodate Netscape. The original line
                                 * is this:
                                 *      if(m==mixin || (m instanceof mixin.constructor)){return p;}
                                 */
                                if(m==mixin || (m && m.constructor === mixin.constructor)){ return p; }
                               
                                if(m && (m=m._findMixin(mixin))){ return m; }
                                c = p && p.constructor;
                        }
                };
               
                /* Now we need to handle the new dj_ns class implementation */
                var html = dojo.doc.documentElement; //TODO browser-specific DOM magic needed?
               
                /* Netscape is going to show up to Dojo as a Gecko-based browser, so we need to
                 * remove this class first, because we're not in FireFox.
                 */
                if(html.className.indexOf("dj_gecko") != -1){
                        html.className = html.className.replace("dj_gecko", "");
                }
               
                /* Now use the same methodology as dijit._base.sniff to add our new dj_ns class */
                if(html.className){
                        html.className += " " + "dj_ns";
                }else{
                        html.className = "dj_ns";
                }
               
        }
       
})();