// Set a global flag that allows compliant browsers to run JavaScript and global WW namespace
var
  go = false,
  WW
;
/* Eliminates IE4 and NS4 */
if ( document.getElementById && document.childNodes && document.createElement) {
	go = true;
  /* Eliminates IE5 and IE5.5 */
  /*@cc_on
  go = false;
  if (@_jscript_version > 5.5) {
    go = true;
  }
  @*/
}

function init() {
	if (go) { 
    
    var 
      /* Create two empty links for vendor/layout engine specific style-sheets */
      link = document.createElement("link"),
      link2 = document.createElement("link"),
      ua = navigator.userAgent,
      old = false
    ;    

     link.rel = "stylesheet";
     link2.rel = "stylesheet";

     link.type = "text/css";
     link2.type = "text/css";

     link.id = "link";
     link2.id = "link2";
 
    // link.title = title;
    // link.href = filename;
    document.getElementsByTagName("head")[0].appendChild(link);    
    document.getElementsByTagName("head")[0].appendChild(link2);    

    // WW namespace 
    WW = {
      Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1?true:false,
      WebKit: ua.indexOf('AppleWebKit/') > -1?true:false,
      Presto: ua.indexOf('Presto/2') > -1?true:false,
      MobileSafari: /Apple.*Mobile.*Safari/.test(ua)?true:false,
      KHTML: window.navigator.vendor=='KDE'?true:false,
      NS4: document.layers?true:false,
      Trident: false,
      fixIE: false,
      IE6: false,
      IE7: false,
      IE8: false,
      IE9: false
    }
    /* Consider a Style-sheet WW.loadCSS as well */
    /* Perhaps this could reduce style block creation code above */
    WW.loadJS = function (url) {
      var script = document.createElement( 'script' );
      script.type = 'text/javascript';
      script.src = url;
      document.getElementsByTagName('head')[0].appendChild( script );
    }

    if (WW.Gecko) {
      link.setAttribute("href", '/c/gecko.css');   
    }
    if (WW.WebKit) {
      link.setAttribute("href", '/c/webKit.css');
    }
    if (WW.Presto) {
      link.setAttribute("href", '/c/presto.css');
    }
    /* JavaScript IE conditional comments */
    /*@cc_on
      WW.Trident = @_win32?true:false;
      if ((@_jscript_version > 5.5) && (@_jscript_version < 5.9)) {
        link.href = '/c/trident.css'; // Sets background colour for all IE browsers
        WW.fixIE = true; // Flag to target IE6 to IE8
      }
      if (@_jscript_version === 5.5) {
        old = true;
      }
      if (@_jscript_version === 5.6) {
        link2.href = '/c/ie5.6.css';
        WW.IE6 = true;
      }
      if (@_jscript_version === 5.7) {
        link2.href = '/c/ie5.7.css';
        WW.IE7 = true;
      }
      if (@_jscript_version === 5.8) {
        link2.href = '/c/ie5.8.css';
         WW.IE8 = true;
     }
      if (@_jscript_version === 9) {
        link2.href = '/c/ie9.css';
        WW.IE9 = true;
      }
    @*/
  if (!old) {
    /* Just for test purposes at the moment */
    //WW.loadJS('j/test.js'); // This works
    
    // Only hide content if JavaScript is available
    document.documentElement.className = 'js';  
    }    
  } else { 
    //alert('No go'); /* Alerts only in IE4 and NS4 */
    return false;
  }
}

init();
