/**
 * Launch.js
 * Determines whether the window is a popup without chrome
 * Sets up the link to launch it if not
 * Initializes the application if so
 */

Schematic.Event.add(window, 'DOMContentLoaded', function() {
	if (Silverlight.ua.Browser !== 'Unsupported' && Silverlight.isInstalled('1.0')) {
		if (window.opener || WWESL.TESTING) {
			new WWESL.Application();
		} else {
			var link = document.getElementById('popupLink'),
				newWindowParams = 'status=no,toolbar=no,location=no,menubar=no,directories=no,resizable=no,scrollbars=no,height=650,width=978';
			if (! window.open(link.href, 'WWESLPopup', newWindowParams)) {
				// show popup block message
			}
			Schematic.Event.add(link, 'click', function(event) {
				event.preventDefault();
				window.open(link.href, 'WWESLPopup', newWindowParams);
			});
		}
	} else {
		var div = Schematic.Dom.getById('preview');
		Schematic.Dom.addClass(div, 'preview');
		Silverlight.InstallAndCreateSilverlight('1.0', 'installPrompt', 'silverlightHost', function() {});
		if (Silverlight.ua.Browser === 'Unsupported') {
			Schematic.Dom.getById('installPrompt').innerHTML += '<p class="unsupported">Your browser may not be supported by Microsoft Silverlight. Please visit <a href="http://www.microsoft.com/silverlight/system-requirements.aspx">http://www.microsoft.com/silverlight/system-requirements.aspx</a> for more information.</p>'
		}
	}
});