/**
 * @author alteredq / http://alteredqualia.com/
 * @author mr.doob / http://mrdoob.com/
 */

/*var window = window || {CanvasRenderingContext2D:false,WebGLRenderingContext:false,Worker:undefined,File:undefined,
FileReader:undefined,FileList:undefined, Blob:undefined }*/

var Detector = {

  canvas : !! window.CanvasRenderingContext2D,
  webgl : ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(),
  workers : !! window.Worker,
  fileapi : window.File && window.FileReader && window.FileList && window.Blob,

}

module.exports = Detector


function getWebGLErrorMessage () {

  var domElement = document.createElement( 'div' );

  domElement.style.fontFamily = 'monospace';
  domElement.style.fontSize = '13px';
  domElement.style.textAlign = 'center';
  domElement.style.background = '#eee';
  domElement.style.color = '#000';
  domElement.style.padding = '1em';
  domElement.style.width = '475px';
  domElement.style.margin = '5em auto 0';

  if ( ! this.webgl ) {

    domElement.innerHTML = window.WebGLRenderingContext ? [
      'Sorry, your graphics card doesn\'t support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>'
    ].join( '\n' ) : [
      'Sorry, your browser doesn\'t support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a><br/>',
      'Please try with',
      '<a href="http://www.google.com/chrome">Chrome</a>, ',
      '<a href="http://www.mozilla.com/en-US/firefox/new/">Firefox 4</a> or',
      '<a href="http://nightly.webkit.org/">Webkit Nightly (Mac)</a>'
    ].join( '\n' );

  }

  return domElement;

}


function addGetWebGLMessage ( parameters ) {

    var parent, id, domElement;

    parameters = parameters || {};

    parent = parameters.parent !== undefined ? parameters.parent : document.body;
    id = parameters.id !== undefined ? parameters.id : 'oldie';

    domElement = Detector.getWebGLErrorMessage();
    domElement.id = id;

    parent.appendChild( domElement );

  }
