﻿function createSilverlight()
{
	if(!Silverlight.isInstalled('1.0')){
	    document.getElementById('silverlightPlugInstall').innerHTML = '<iframe src="silverlightfiles_eco/silverlightInstall.html" width="972" height="520" frameborder="0" scrolling="no" allowtransparency="true" style="margin: 0px; padding:0px;"></iframe>';
	    document.getElementById('silverlightPlugInHost').style.display = "none";
	    var install_reloader = function(){
	        if (Silverlight.isInstalled('1.0'))
	        {
	            window.location.reload(false);
	        }else{
	            setTimeout(install_reloader, 3000);
	        }
	    }
	    var ua = window.navigator.userAgent;
	    if( ua.indexOf('Windows') >= 0 && ua.indexOf('MSIE') >= 0 ){
	        setTimeout(install_reloader, 3000);
	    }
	}else{
	    if (!window.Silverlight) 
	        window.Silverlight = {};

	    Silverlight.createDelegate = function(instance, method) {
	        return function() {
	            return method.apply(instance, arguments);
	        }
	    }
	    
	    var scene = new eco.Scene();
	    
	    Silverlight.createObjectEx({
	        source: 'SceneEco.xaml',
	        parentElement: document.getElementById('silverlightPlugInHost'),
	        id: 'silverlightPlugIn',
	        properties: {
	            width: '972px',
	            height: '532px',
	            background:'black',
	            version: '1.0'
	        },
	        events: {
	            onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
	            onError: function(sender, args) {
		            var errorDiv = document.getElementById("errorLocation");
		            if (errorDiv != null) {
			            var errorText = args.errorType + "- " + args.errorMessage;
								
			            if (args.ErrorType == "ParserError") {
				            errorText += "<br>File: " + args.xamlFile;
				            errorText += ", line " + args.lineNumber;
				            errorText += " character " + args.charPosition;
			            }
			            else if (args.ErrorType == "RuntimeError") {
				            errorText += "<br>line " + args.lineNumber;
				            errorText += " character " +  args.charPosition;
			            }
			            errorDiv.innerHTML = errorText;
		            }	
	            }
	        },
	        context: null 
	    });
	    document.getElementById('silverlightPlugInstall').style.display = "none";
	}
}