///////////////////////////////////////////////////////////////////////////////
//
//  AgInstall.js   				version 2.0.31030.0M
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Microsoft
//  Public License available at 
//  http://code.msdn.microsoft.com/silverlightjs/Project/License.aspx.  
//  You may not use or distribute this file or the code in this file except as 
//  expressly permitted under that license.
// 
//  Copyright (c) Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////

window.AgInstall = {
	INSTALL_REQUIRED: "install",
	UPGRADE_REQUIRED: "upgrade",
	RESTART_REQUIRED: "restart",
	INSTALLING: "installing",
	NOT_SUPPORTED: "notSupported",

	WIDE: "Wide",
	NARROW: "Narrow",
	SMALL: "Small",
	ENCODER: "Encoder",

	IsIE6: typeof window.XMLHttpRequest == "undefined" && window.external,
	IsIE: /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent),

	DefaultConfig:
    {
    	title: "Eastberlin Onlineshop",
    	picture: "",
    	description:
        {
        	install:
            {
            	wide: "Bitte das Microsoft Siverlight Plugin herunterladen und installieren."
            },
        	upgrade:
            {
            	wide: "Für den Eastberlin Onlineshop wird eine neue Version des Silverlight Plugin benötigt."
            },
        	installing:
            {
            	wide: "Der Download wird gestartet. Bitte dann das Silverlight Plugin installieren und den Browser neu starten."
            },
        	restart:
            {
            	wide: "Die Aktualisierung des Silverlight PLugin ist beendet. Bitte den Browser neu starten."
            },
        	notSupported:
            {
            	wide: "Leider wird das Silverlight Plugin auf diesem Browser nicht unterstützt."
            }
        },
    	buttonLabel: "UPDATE AND START &gt;"
    },


	//=============================================================
	//  Output Template Here \/ \/ \/ 
	//=============================================================
	Template: function(t, i) {


return "<div id='install' class='slInstallPopupWide'><h1>Onlineshop - Jetzt in Silverlight!</h1><ul><li>- Schneller und sicherer Online Shoppen</li><li>- Atemberaubende Grafik und geniale Effekte</li><li>- Schnelles Videostreaming</li><li>- Einfach downloaden und installieren</li></ul><div id='desc' class='slDescription'></div><a href=\"javascript:Silverlight.getSilverlight('{1}');\" id='installlink' class='slButtonWide' title='Download the Silverlight Plugin for Free!'>Ja, Free Download &raquo;</a><a href='/de' id='gohtml' title='open the HTML Version of the Shop'>Nein, HTML-Version &raquo;</a><a href='http://silverlight.net' id='getsl' target='_blank' title='go to Silverlight.net'>get Silverlight</a></div>";



//Original Template:		
//			return "<div class=\"slInstall\"><div class=\"slInstallPopup" + t + "\"><div class=\"slPopupContent" + t + "\"><div class=\"slScreenshot" + t + "\"><img src=\"" + i.config.picture + "\" /></div><div class=\"slTextContent" + t + "\"><div class=\"slHeadline" + t + "\">" + i.config.title + "</div><div class=\"slDescription\"></div><img class=\"slDivider\" src=\"" + (t == AgInstall.WIDE ? "images/wide/divider.png" : "images/narrow/divider.png") + "\" /><a class=\"slButton" + t + "\" href=\"javascript:Silverlight.getSilverlight('{1}');\">" + i.config.buttonLabel + "</a></div></div><div class=\"slPopupTop" + t + "\"></div><div class=\"slPopupLoop" + t + "\"></div><div class=\"slPopupBot" + t + "\"></div></div></div>";

		
	},
	//=============================================================
	//	end Output Template Here /\ /\ /\
	//=============================================================

	// Iterate objects and copy contents where it is missing in the original
	Fill: function(f, t) {
		for (var k in f) {
			if (!t[k] || (typeof t[k] != typeof f[k]))
				t[k] = f[k];
			else if (typeof f[k] == "object")
				AgInstall.Fill(f[k], t[k]);
		}
	},

	Installer: function(params) {

		var NEED_INSTALL = 'install';
		this.config = params.installerUiConfig;

		// Iterate config and replace any missing parts with default
		if (!this.config)
			this.config = AgInstall.DefaultConfig;
		else
			AgInstall.Fill(AgInstall.DefaultConfig, this.config);

		params.properties.alt = NEED_INSTALL;
		var version = params.properties.version;

		var element = document.getElementById(params.parentElement);
		if (!element) {
			alert("Silverlight could not find a DOM element with id '" + params.parentElement + "'.");
			return;
		}

		// Perform the injection ourselves, so make sure Silverlight knows not to do it
		params.parentElement = null;
		var obj = Silverlight.createObjectEx(params);

		if (obj == NEED_INSTALL) {
			// Installation is required.
			var t = AgInstall.WIDE;

			var w = element.offsetWidth;
			var h = element.offsetHeight;

			this.type = this.config.type ? this.config.type : t;
			// Ensure that the styles are attached.
			if (!Silverlight.attachedInstallDependencies) {
				document.write('<link rel="stylesheet" type="text/css" href="', 'css/slInstall.css', '"/>');
				// If we are in IE6, attach a stylesheet that allows for png transparency
				if (AgInstall.IsIE6)
					document.write('<link rel="stylesheet" type="text/css" href="', 'css/ie6.css', '"/>');
				Silverlight.attachedInstallDependencies = true;
			}
			if (!Silverlight.attachedTemplateDependencies || !Silverlight.attachedTemplateDependencies[this.type]) {
				document.write('<link rel="stylesheet" type="text/css" href="', 'css/slInstall' + this.type + '.css', '"/>');
			}
			if (!Silverlight.installControls)
				Silverlight.installControls = [];
			Silverlight.installControls.push(this);

			element.innerHTML = AgInstall.Template(this.type, this).replace(/\{1\}/g, version);

			this.root = element;
			element.style.textAlign = "center";
			var divs = this.root.getElementsByTagName("*");
			for (var i = 0; i < divs.length; i++) {
				this[divs[i].className] = divs[i];
			}
			this.state = AgInstall.UPGRADE_REQUIRED;

			// Update the installer to a predefined state
			this.update = function(state) {
				// If no state was passed, just redraw with the current state
				if (!state)
					state = this.state;
				if (this.slDivider && (this.type == AgInstall.WIDE || this.type == AgInstall.NARROW))
					this.slDivider.style.display = 'block';
				this['slButton' + this.type].style.display = 'block';
				this.state = state;

				
				var desc = this.config.description[state][this.type.toLowerCase()];
				switch (state) {
					case AgInstall.INSTALLING:
						if (this.slDivider)
							this.slDivider.style.display = 'none';
						this['slButton' + this.type].style.display = 'none';
						break;
					case AgInstall.RESTART_REQUIRED:
						if (this.slDivider)
							this.slDivider.style.display = 'none';
						this['slButton' + this.type].style.display = 'none';
						break;
					case AgInstall.NOT_SUPPORTED:
						if (this.slDivider)
							this.slDivider.style.display = 'none';
						this['slButton' + this.type].style.display = 'none';
						break;
				}
				this.slDescription.innerHTML = desc;
				
			};
		}
		// No installation required, inject the control
		else
			element.innerHTML = obj;
	}
}