  var hosts  = new Object();
  function agHost(hostElementID, id, width, height, backgroundcolor, sourceelement, source, windowlessmode, framerate, errorhandler) {
    var hostElement = document.getElementById(hostElementID);
    var innerHTML;
    
//assign error handler

    if(errorhandler == null) {
    
    errorhandler = "aghost_errorhandler";
    
    }
    
//IE detection
    if((navigator.appVersion.indexOf('MSIE') != -1)) {   
    
    try { 
       
        var WPFE = new ActiveXObject("AgControl.AgControl.0.8");
        
        innerHTML = '<object id="'+id+'" width="'+width+'" height="'+height+'" classid="CLSID:32C73088-76AE-40F7-AC40-81F62CB2C1DA">';
        
      if (sourceelement != null) {
          innerHTML += ' <param name="SourceElement" value="'+sourceelement+'" />';
      }
      if (source != null) {
          innerHTML += ' <param name="Source" value="'+source+'" />';
      }
      if (framerate != null) {
          innerHTML += ' <param name="MaxFrameRate" value="'+framerate+'" />';
      }
      if (errorhandler != null) {
          innerHTML += ' <param name="OnError" value="'+errorhandler+'" />';
      }
      if (backgroundcolor != null) {
          innerHTML += ' <param name="BackgroundColor" value="'+backgroundcolor+'" />';
      }
      if (windowlessmode != null) {
          innerHTML += ' <param name="WindowlessMode" value="'+windowlessmode+'" />';
      }
      innerHTML += '<\/object>';
    
      }
    
        catch(e) {   
          
        innerHTML =  '<div width="'+width+'" height="'+height+'" >'; 
        innerHTML += 'You must install "WPF/E" (codename) December 2006 CTP to view this page: ';
        innerHTML +=  '<A href="http://go.microsoft.com/fwlink/?LinkID=77792&clcid=0x409">Get "WPF/E!"</A>';
        innerHTML += '</div>'
        
        }     
    }

    //FF/Windows detection
    
    
    
    else if((window.GeckoActiveXObject && navigator.userAgent.indexOf('Windows') != -1)) {   
    
      innerHTML = '<embed id="'+id+'" width="'+width+'" height="'+height+'" pluginspage="http://go.microsoft.com/fwlink/?LinkID=77792&clcid=0x409';
         if (source != null) {
             innerHTML += '" Source="'+source;
         }
         if (sourceelement != null) {
          innerHTML += '" SourceElement="'+sourceelement;
         }
         if (framerate != null) {
             innerHTML += '" MaxFrameRate="'+framerate;
         }
         if (errorhandler != null) {
             innerHTML +='" OnError="'+errorhandler;
         }
         if (backgroundcolor != null) {
             innerHTML += '" BackgroundColor="'+backgroundcolor;
         }
         if (windowlessmode != null) {
             innerHTML += '" WindowlessMode="'+windowlessmode;
         }
      innerHTML += '" type="application/ag-plugin"/>';

      }

    //MAC detection
      else if(navigator.userAgent.indexOf("Macintosh") != -1){
      
      var res = window.confirm("Please note on MacOS, this sample works best with an Intel processor (dual core) with 1GB+ of RAM.  Additional performance improvements will be made available in a later release.");
      if (res) {

        if(navigator.userAgent.indexOf("Firefox/1.5.0.8") != -1 || navigator.userAgent.indexOf("Safari") != -1){   
     
      
          innerHTML = '<embed id="'+id+'" width="'+width+'" height="'+height+'" pluginspage="http://go.microsoft.com/fwlink/?LinkID=77793&clcid=0x409';
         if (source != null) {
             innerHTML += '" Source="'+source;
         }
         if (sourceelement != null) {
          innerHTML += '" SourceElement="'+sourceelement;
         }
         if (framerate != null) {
             innerHTML += '" MaxFrameRate="'+framerate;
         }
         if (errorhandler != null) {
             innerHTML +='" OnError="'+errorhandler;
         }
         if (backgroundcolor != null) {
             innerHTML += '" BackgroundColor="'+backgroundcolor;
         }
         if (windowlessmode != null) {
             innerHTML += '" WindowlessMode="'+windowlessmode;
         }
      innerHTML += '" type="application/ag-plugin"/>';

	    //Disable Safari caching

      	// For more information, see http://developer.apple.com/internet/safari/faq.html#anchor5 

      innerHTML += "<iframe style='visibility:hidden'/>";

      }
      
      else {     
        innerHTML =  '<div width="'+width+'" height="'+height+'" >'; 
        innerHTML += 'You must be running Firefox 1.5.0.8 to view "WPF/E" content on this page.  ';
        innerHTML +=  '<A href="http://go.microsoft.com/fwlink/?LinkID=78984&clcid=0x409">Visit the "WPF/E" product site for more details.</A>';
        innerHTML += '</div>'        
        }        
      } 
    else {
	return;
    }
  }  


    hostElement.innerHTML = innerHTML;
  }
  
  function aghost_errorhandler(line, col, hr, string) {
    if(line !=0 && col !=0)
    {
      var str = "("+line+","+col+"): "+string+"\n";
      str += "HRESULT: "+hr;
      alert(str);
    }
  }  