﻿VignettManager = function () 
{
    Sys.Application.add_init(Function.createDelegate(this, this.handleAppInit)); 
} 

VignettManager.prototype = 
{
    handleAppInit : function()
    {
        if (!window.Silverlight) 
            window.Silverlight = {};

        var sot = null;
        if (typeof SWFObject != 'undefined')
            sot = new SWFObject();      

        if ((typeof (xmalSource) != 'undefined') && Silverlight.isInstalled('1.0') ) 
        {
            this.initializeXAML('vignett', xmalSource, 550, 86);
            this.createSilverlight(); 
        }
        else 
            if ((typeof(flashJS) != 'undefined') && (sot && sot.installedVer))
            {
                var e = document.createElement("script");
                e.src = flashJS;
                e.type = "text/javascript";
                var headID = document.getElementsByTagName("head")[0];
                if (headID) 
                    headID.appendChild(e);
            }
            else 
                if (typeof(alternateJS) != 'undefined') 
                {
                    var e = document.createElement("script");
                    e.src = alternateJS;
                    e.type="text/javascript";
               
                    var headID = document.getElementsByTagName("head")[0];
                    if (headID) 
                        headID.appendChild(e);
                    if (alternateJS.indexOf('.htm' > 0))
                    {
                        var htmURL = alternateJS.replace('~/', '');
                        htmURL = htmURL.replace('.js', ''); 
                        this.loadHTM(htmURL); 
                    } 
                }
  },
    
  createSilverlight : function()
  {
      if (typeof productXamlMgr != 'undefined')
      {
          var parentEl = $get(this.parent);
          Silverlight.createObjectEx(
          {
              source: this.XMALURL,
              parentElement: parentEl,
              id: 'SilverlightPlugIn',
              properties: 
              {
                  width: '550',
                  height: '89',  
                  isWindowless: this.isWindowless,
                  background: this.background,
                  version: this.version
              },
              events: 
              {
                  onError: null,
                  onLoad: Silverlight.createDelegate(productXamlMgr, productXamlMgr.handleLoad)
              },    
              context: null 
          });
      }
  }, 
      
  initializeXAML : function(parent, url, width, height)
  {
      Silverlight.createDelegate = function(instance, method) 
      {
          return function() 
          {
              return method.apply(instance, arguments);
          }
      }
      
      this.parent = parent; 
      this.XMALURL = url; 
      this.width = width; 
      this.height = height
      
      this.background = "#00FFFFFF";
      this.isWindowless = 'true';
      this.version = '2.0'; 
  }, 
  
  loadHTM : function(url)
  {
      var request = new Sys.Net.WebRequest();
      request.set_httpVerb("GET");
      request.set_url(url);
      request.add_completed(Function.createDelegate(this, this.onLoadHTM));   
       
      var executor = new Sys.Net.XMLHttpExecutor();
      request.set_executor(executor); 
      executor.executeRequest();
  }, 
  
  onLoadHTM : function( executor )
  {
       if (executor.get_responseAvailable()) 
       {             
           var content = executor.get_responseData();
           var newDiv = document.createElement("div"); 
           newDiv.innerHTML = content;
           $get('vignett').appendChild(newDiv);                      
       }
  }
 
  /* Not used, I think! (TL, 08.06.05)
  setJavaClass : function(newClass)
  {
      this.javaClass = newClass; 
  }*/
} 

// Register the class with the script manager. 
VignettManager.registerClass('VignettManager'); 
 
// Bootstrap, but only on modern browsers
if (typeof document.getElementById != 'undefined')
    vignettMgr = new VignettManager();

if (typeof(Sys) !== "undefined")
    Sys.Application.notifyScriptLoaded();