//Document,documentչ
var Document = new Native({

 //,Ϊ$typeṩ׼ж
 name: 'Document',

 //չԭ
 legacy: (Browser.Engine.trident) ? null: window.Document,

 initialize: function(doc){
  //Ψһʶ
  $uid(doc);

  //ݷʽ
  doc.head = doc.getElementsByTagName('head')[0];
  doc.html = doc.getElementsByTagName('html')[0];

  //ԵǰĵwindowĿݷʽ
  doc.window = doc.defaultView || doc.parentWindow;
  if (Browser.Engine.trident4) $try(function(){
   //IE6²汳ͼƬBug
   doc.execCommand("BackgroundImageCache", false, true);
  });
  return $extend(doc, Document.Prototype);
 },

 //ͬʱԵǰwindowչ
 afterImplement: function(property, value){
  document[property] = Document.Prototype[property] = value;
 }

});

Document.Prototype = {$family: {name: 'document'}};

new Document(document);


//Documentչʵ
Document.implement({

 //HTML Element
 newElement: function(tag, props){
  //IEҪرͬʱIEֱ֧ʹñǩ봴HTML Element
  if (Browser.Engine.trident && props){
   ['name', 'type', 'checked'].each(function(attribute){
    if (!props[attribute]) return;
    tag += ' ' + attribute + '="' + props[attribute] + '"';
    if (attribute != 'checked') delete props[attribute];
   });
   tag = '<' + tag + '>';
  }
  //mooĶ
  return $.element(this.createElement(tag)).set(props);
 },

 //ıڵ
 newTextNode: function(text){
  return this.createTextNode(text);
 },

 //document
 getDocument: function(){
  return this;
 },

 //window
 getWindow: function(){
  return this.defaultView || this.parentWindow;
 },

 //ɨսֹڴй©
 purge: function(){
  var elements = this.getElementsByTagName('*');
  for (var i = 0, l = elements.length; i < l; i++) memfree(elements[i]);
 }

});


