if (!window.MS_Shared_Source) window.MS_Shared_Source = {};

MS_Shared_Source.Base = function() {
    this.control = null;
    this.rootCanvas = null;
    this.root = null;
    this.links = new Array()
    this.links.push("http://www.microsoft.com/resources/sharedsource/productsourceprogram.mspx");
    this.links.push("http://www.microsoft.com/resources/sharedsource/referencesource.mspx");
    this.links.push("http://www.microsoft.com/resources/sharedsource/communitysource.mspx");
}
MS_Shared_Source.Base.prototype = {
    dispose : function() { this.root = null; },
    initialize : function(control, userContext, rootElement) {
		this.control = control;
		this.data = null;
		this.root = this.control.content;
		this.rootCanvas = this.root.findName("rootCanvas");
		this.animateBack = this.rootCanvas.findName("AnimateBackground");
		this.animateIntro = this.rootCanvas.findName("AnimateIntro");
		this.registerButton(this.rootCanvas.findName("Column_1"),
			this.onCol1_Over, this.onCol1_Out, this.onCol1_Down, this.onCol1_Release);
		this.registerButton(this.rootCanvas.findName("Column_2"),
			this.onCol2_Over, this.onCol2_Out, this.onCol2_Down, this.onCol2_Release);
		this.registerButton(this.rootCanvas.findName("Column_3"),
			this.onCol3_Over, this.onCol3_Out, this.onCol3_Down, this.onCol3_Release);
		this.fileDownloader("Silverlight/HeroWidget/Segoe.deploy", Silverlight.createDelegate(this, this.onFontLoad));
    },
    onFontLoad : function(sender, eventArgs) {
		this.segoeFont = sender;
		this.attachFont(this.rootCanvas.findName("Title"));
		this.attachFont(this.rootCanvas.findName("ColHdr_1a"));
		this.attachFont(this.rootCanvas.findName("ColHdr_1b"));
		this.attachFont(this.rootCanvas.findName("ColHdr_2a"));
		this.attachFont(this.rootCanvas.findName("ColHdr_2b"));
		this.attachFont(this.rootCanvas.findName("ColHdr_3a"));
		this.attachFont(this.rootCanvas.findName("ColHdr_3b"));
		this.animateBack.begin();
		this.animateIntro.begin();
    },
    registerButton : function(button, overAction, outAction, downAction, releaseAction) {
        button.addEventListener("MouseEnter", Silverlight.createDelegate(this, overAction));
        button.addEventListener("MouseLeave", Silverlight.createDelegate(this, outAction));
        button.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, downAction));
        button.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, releaseAction));
    },
    onCol1_Over : function(sender, eventArgs) { this.rootCanvas.findName("OverCol_1").begin(); },
    onCol1_Out : function(sender, eventArgs) { this.rootCanvas.findName("OutCol_1").begin(); },
    onCol1_Down : function(sender, eventArgs) { this.rootCanvas.findName("DownCol_1").begin(); },
	onCol1_Release : function(sender, eventArgs) { document.location = this.links[0]; },
	
    onCol2_Over : function(sender, eventArgs) { this.rootCanvas.findName("OverCol_2").begin(); },
    onCol2_Out : function(sender, eventArgs) { this.rootCanvas.findName("OutCol_2").begin(); },
    onCol2_Down : function(sender, eventArgs) { this.rootCanvas.findName("DownCol_2").begin(); },
	onCol2_Release : function(sender, eventArgs) { document.location = this.links[1]; },
	
    onCol3_Over : function(sender, eventArgs) { this.rootCanvas.findName("OverCol_3").begin(); },
    onCol3_Out : function(sender, eventArgs) { this.rootCanvas.findName("OutCol_3").begin(); },
    onCol3_Down : function(sender, eventArgs) { this.rootCanvas.findName("DownCol_3").begin(); },
	onCol3_Release : function(sender, eventArgs) { document.location = this.links[2]; },
	attachFont : function(textObject) {
		textObject.setFontSource(this.segoeFont);
		textObject["FontFamily"] = "Segoe";
	},
	fileDownloader : function(fileName, callback, progress) {
		var downloader = this.control.createObject("downloader");
		downloader.addEventListener("Completed", Silverlight.createDelegate(this, callback));
		if (progress != null)
			downloader.addEventListener("DownloadProgressChanged", Silverlight.createDelegate(this, progress));
		downloader.open("GET", fileName);
		downloader.send();
	}
}