if (!window.MySilverlight)
	window.MySilverlight = {};
MySilverlight.Scene = function() 
{
}

MySilverlight.Scene.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		this.root = rootElement;
		
		//Browser Compatibility Check
		if (document.implementation && document.implementation.createDocument) {
			this.BrowserFamily = "Mozilla";
		} else if (window.ActiveXObject) {
			this.BrowserFamily = "IE";
		} else {
			this.BrowserFamily = "Unknown";
		}
		
		/**************************************************
			SETUP
		**************************************************/
		this.currentSlide = 1;		
		this.SelectedColor = "Blue";
		this.EnergyColors = new Array();//"Blue", "Green", "Orange", "Purple", "Silver");
		this.SelectedSection = "Intro";
		this.SectionNames = new Array("IntroPanel", "InterestPanel", "InterestDetailPanel", "ProductPanel");
		this.InterestArticles = new Object();
		this.InterestNames = new Array("Windows", "Web", "Gaming", "Hardware");
		this.SelectedInterestIndex = 0;
		//this.SelectedInterestPageIndex = 0;
		this.productOrigins = new Array();
		this.DLImages = new Array(
			"bg_panel_main.png",
			"bg_pattern.png",
			"interest_panel1.png",
			"interest_panel2.png",
			"interest_panel3.png",
			"interest_panel4.png",
			"interestTitle1.png",
			"interestTitle2.png",
			"interestTitle3.png",
			"interestTitle4.png",
			"intro_CPP_easy.png",
			"intro_CPP_fun.png",
			"intro_CPP_simple.png",
			"intro_CS_easy.png",
			"intro_CS_fun.png",
			"intro_CS_simple.png",
			"intro_VB_easy.png",
			"intro_VB_fun.png",
			"intro_VB_simple.png",
			"intro_VWD_easy.png",
			"intro_VWD_fun.png",
			"intro_VWD_simple.png",
			"productTitle_CPP_txt.png",
			"productTitle_CS.png",
			"productTitle_CS_txt.png",
			"productTitle_VB.png",
			"productTitle_VB_txt.png",
			"productTitle_VWD.png",
			"productTitle_VWD_txt.png"
			);
		this.DLImages2 = new Array(
			"energy_Blue.png", 
			"productTitle_CPP.png",
			"productTitle_VWD.png"
			);
		
		this.loadingBar_maxBar = this.root.findName("loadingBar_maxBar");
		this.loadingBar_progressBar = this.root.findName("loadingBar_progressBar");
		this.SB_5secDelay = this.root.findName("SB_5secDelay");
		this.addEvent(this.SB_5secDelay, "Completed", this, "onSB_5secDelayCompleted");	
		
		this.InterestButtonFocus = this.root.findName("InterestButtonFocus");
		this.InterestButtonFocus.Visibility = "Collapsed";
		
		//this.updateSlider();
		//this.addEvent(this.root, "MouseMove", this, "onRootMouseMove");
		//this.addEvent(this.root, "MouseLeftButtonDown", this, "onRootMouseMove");
		
		for (i in this.EnergyColors) {
			var myColor = this.EnergyColors[i];
			myEnergy = this.root.findName("MediaElement_Energy"+myColor);
			this.addEvent(myEnergy, "MediaOpened", this, "MediaElement_Energy_onOpened");
			this.addEvent(myEnergy, "MediaEnded", this, "MediaElement_Energy_onMediaEnded");
			this.addEvent(this.root.findName("SB_MediaElement_Energy"+myColor+"_Hide"), "Completed", this, "SB_Energy_Completed");
			this.addEvent(this.root.findName("SB_MediaElement_Energy"+myColor+"_Show"), "Completed", this, "SB_Energy_Completed");
		}

		this.addEvent(this.root.findName("IntroPanel_out"), "Completed", this, "onIntroPanel_outComplete");
		this.addEvent(this.root.findName("InterestPanel_out"), "Completed", this, "onInterestPanel_outComplete");
		this.addEvent(this.root.findName("InterestDetailPanel_out"), "Completed", this, "onInterestDetailPanel_outComplete");
		this.addEvent(this.root.findName("ProductPanel_out"), "Completed", this, "onProductPanel_outComplete");
		this.addEvent(this.root.findName("interestDetailPanels_out"), "Completed", this, "oninterestDetailPanels_outComplete");		
		
		this.btn_exploreByInterest = this.root.findName("btn_exploreByInterest");
		this.btn_download = this.root.findName("btn_download");
		this.btn_exploreByProduct = this.root.findName("btn_exploreByProduct");
		for (i=1;i<=4;i++) {
			this["btn_product"+i] = this.root.findName("btn_product"+i);
			this["btn_interest"+i] = this.root.findName("btn_interest"+i);
		}
		
		this.addEvent(this.btn_exploreByInterest, "MouseEnter", this, "onButtonRollover");
		this.addEvent(this.btn_download, "MouseEnter", this, "onButtonRollover");
		this.addEvent(this.btn_exploreByProduct, "MouseEnter", this, "onButtonRollover");
		this.addEvent(this.btn_exploreByInterest, "MouseLeave", this, "onButtonRollout");
		this.addEvent(this.btn_download, "MouseLeave", this, "onButtonRollout");
		this.addEvent(this.btn_exploreByProduct, "MouseLeave", this, "onButtonRollout");
		this.addEvent(this.btn_exploreByInterest, "MouseLeftButtonDown", this, "onButtonClick");
		this.addEvent(this.btn_download, "MouseLeftButtonDown", this, "onButtonClick");
		this.addEvent(this.btn_exploreByProduct, "MouseLeftButtonDown", this, "onButtonClick");
		
		for (i=1;i<=4;i++) {
			//this.productOrigins[i-1] = this["btn_product"+i]["Canvas.Left"];
			this.addEvent(this["btn_product"+i], "MouseEnter", this, "onButtonRollover");
			this.addEvent(this["btn_product"+i], "MouseLeave", this, "onButtonRollout");
			this.addEvent(this["btn_product"+i], "MouseLeftButtonDown", this, "onButtonClick");
			
			this.addEvent(this["btn_interest"+i], "MouseEnter", this, "onButtonRollover");
			this.addEvent(this["btn_interest"+i], "MouseLeave", this, "onButtonRollout");
			this.addEvent(this["btn_interest"+i], "MouseLeftButtonDown", this, "onButtonClick");
		}
		
		for(i=1;i<=12;i++) {
			this.addEvent(this.root.findName("slide"+i+"_in"), "Completed", this, "onslideN_inCompleted");
			this.addEvent(this.root.findName("slide"+i+"_out"), "Completed", this, "onslideN_outCompleted");
		}
		
		for(i=1;i<=4;i++) {
			this["btn_Interest"+i] = this.root.findName("btn_Interest"+i);
			this.addEvent(this["btn_Interest"+i], "MouseEnter", this, "onButtonRollover");
			this.addEvent(this["btn_Interest"+i], "MouseLeave", this, "onButtonRollout");
			this.addEvent(this["btn_Interest"+i], "MouseLeftButtonDown", this, "onInterestButtonClick");
		}
		
		/*
		for(i=1;i<=9;i++) {
			this["btn_Page"+i] = this.root.findName("btn_Page"+i);
			this.addEvent(this["btn_Page"+i], "MouseEnter", this, "onButtonRollover");
			this.addEvent(this["btn_Page"+i], "MouseLeave", this, "onButtonRollout");
			this.addEvent(this["btn_Page"+i], "MouseLeftButtonDown", this, "onPageButtonClick");
		}
		
		this.btn_next = this.root.findName("btn_next");
		this.addEvent(this.btn_next, "MouseEnter", this, "onButtonRollover");
		this.addEvent(this.btn_next, "MouseLeave", this, "onButtonRollout");
		this.addEvent(this.btn_next, "MouseLeftButtonDown", this, "onbtn_nextClick");
		this.btn_prev = this.root.findName("btn_prev");
		this.addEvent(this.btn_prev, "MouseEnter", this, "onButtonRollover");
		this.addEvent(this.btn_prev, "MouseLeave", this, "onButtonRollout");
		this.addEvent(this.btn_prev, "MouseLeftButtonDown", this, "onbtn_prevClick");
		*/
		
		for(i=1;i<=3;i++) {
			this["btn_ViewDemo"+i] = this.root.findName("btn_ViewDemo"+i);
			this.addEvent(this["btn_ViewDemo"+i], "MouseEnter", this, "onButtonRollover");
			this.addEvent(this["btn_ViewDemo"+i], "MouseLeave", this, "onButtonRollout");
			this.addEvent(this["btn_ViewDemo"+i], "MouseLeftButtonDown", this, "onViewDemoButtonClick");
		}
		
		this.downloader = control.createObject("downloader");
		this.downloader.addEventListener("downloadProgressChanged", Silverlight.createDelegate(this, this.onDownloadProgressChanged));
		this.downloader.addEventListener("completed", Silverlight.createDelegate(this, this.onDownloadCompleted));
		this.downloader.open("GET", "MySiverlightAssets.cat");
		this.downloader.send();
	},	
	onError: function() {
		//Legolas! What do your Elven eyes see?
		//A red Sun rises... a scripting error has been spilled this day.
	},
	startApp: function() {
		this.root.findName("SB_loadingComplete").Begin();
		this.waitForNextSlide();		
	},
	
	onDownloadProgressChanged: function(sender, eventArgs)
	{
		var percentage = sender.downloadProgress * 100;
		// Update the Rectangle and TextBlock objects of the visual progress indicator.
		this.loadingBar_progressBar.Width = Math.floor(percentage * this.loadingBar_maxBar.Width/100);
	},

	onDownloadCompleted: function(sender, eventArgs)
	{
		for(i in this.DLImages) {
			var myImageName = this.DLImages[i];
			this.root.findName("image_"+myImageName.split(".")[0]).setSource(this.downloader, "images/"+myImageName);
		}
		for(i in this.DLImages2) {
			var myImageName = this.DLImages2[i];
			this.root.findName("image_"+myImageName.split(".")[0]).setSource(this.downloader, "images/"+myImageName);
			var myImageName2 = myImageName.split(".")[0]+"2"
			this.root.findName("image_"+myImageName2).setSource(this.downloader, "images/"+myImageName);
		}
		
		this.getXMLDoc("data.xml", this.onDataLoad, this);
	},
	
	onDataLoad: function(xmldoc, xthis) {
		xthis.storeDataFromXMLDoc(xmldoc);
	},	
	storeDataFromXMLDoc: function(xmldoc) {
		
		//Store Article Data
		//IE Check
		if (this.BrowserFamily=="IE") {	
			var articleNodes = xmldoc.selectNodes("/data/article");
			var articleNodesLength = articleNodes.length;
		} else if (this.BrowserFamily=="Mozilla") {
			var articleNodes = document.evaluate('/data/article', xmldoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
			var articleNodesLength = articleNodes.snapshotLength;
		}
		
		for ( var i=0 ; i < articleNodesLength; i++ )
		{
			//IE Check
			if (this.BrowserFamily=="IE") {	
				var myArticleNode = articleNodes[i];
			} else if (this.BrowserFamily=="Mozilla") {
				var myArticleNode = articleNodes.snapshotItem(i);
			}
			
			var myArticle = new Object();
			myArticle["interest"] = getAttributeValue(myArticleNode,"interest");
			myArticle["title"] = getAttributeValue(myArticleNode,"title");
			myArticle["description"] = getAttributeValue(myArticleNode,"description");
			myArticle["url"] = getAttributeValue(myArticleNode,"url");
			
			if(this.InterestArticles[myArticle["interest"]] == undefined) {
				this.InterestArticles[myArticle["interest"]] = new Array();
			}
			this.InterestArticles[myArticle["interest"]].push(myArticle);
		}
		
		this.buildInterestPages(this.InterestNames[this.SelectedInterestIndex]);
		
		this.startApp();
	},



	/**************************************************
		SLIDER - not in use
	**************************************************/
	updateSlider: function(sender, mouseEventArgs) {
		var mp = mouseEventArgs.getPosition(null);
		if(mp.x>120 && mp.x<890 && mp.y>45 && mp.y<370) {
			for (i=1;i<=4;i++) {
				//this.productOrigins[i-1]
				var myScaleTranform = this.root.findName("btn_product"+i+"_ScaleTransform");
				
				factor = 1-(Math.abs(mp.x-120-this.productOrigins[i-1])/160-1)*0.2;
				
				myScaleTranform.ScaleX=factor;
				myScaleTranform.ScaleY=factor;
			}
		}
		setInterval(updateSlider,50);
	},
	
	

	/**************************************************
		INTEREST PAGES
	**************************************************/
	
	buildInterestPages: function(p_interestkey) {
		/*
		var numPages = Math.ceil(this.InterestArticles[p_interestkey].length/3);
		numPages = Math.max(numPages,1); //at least 1
		numPages = Math.min(numPages,9); //no more than 9
		if(numPages==1) {
			this.root.findName("interestDetail_header").Visibility = "Collapsed";
		} else {
			this.root.findName("interestDetail_header").Visibility = "Visible";
			for (var i=1;i<=numPages;i++) {
				this.root.findName("btn_Page"+i).Visibility = "Visible";
			}
			for (var i=numPages+1;i<=9;i++) {
				this.root.findName("btn_Page"+i).Visibility = "Collapsed";
			}
		}
		*/
		this.selectInterestPage(1, true);
	},
	/*
	onPageButtonClick: function(sender, eventArgs) {
		//this.selectInterestPage(Number(sender.Name.substr(8)), false);
	},

	onbtn_nextClick: function(sender, eventArgs) {
		this.selectInterestPage(this.SelectedInterestPageIndex+1, false);
	},
	onbtn_prevClick: function(sender, eventArgs) {
		this.selectInterestPage(this.SelectedInterestPageIndex-1, false);
	},
	*/
	selectInterestPage: function(p_interestPageIndex, p_immediate) {
		/*
		if(this.SelectedInterestPageIndex>0) {
			this.root.findName("btn_Page"+this.SelectedInterestPageIndex+"_out").Begin();
		}
		*/
		this.SelectedInterestPageIndex = p_interestPageIndex;
		/*
		this.root.findName("btn_Page"+this.SelectedInterestPageIndex+"_over").Begin();
		
		var numPages = Math.ceil(this.InterestArticles[this.InterestNames[this.SelectedInterestIndex]].length/3);
		numPages = Math.max(numPages,1); //at least 1
		numPages = Math.min(numPages,9); //no more than 9
		
		if(this.SelectedInterestPageIndex==1) {
			this.btn_prev.Visibility = "Collapsed";
		} else {
			this.btn_prev.Visibility = "Visible";
		}

		if(this.SelectedInterestPageIndex==numPages) {
			this.btn_next.Visibility = "Collapsed";
		} else {
			this.btn_next.Visibility = "Visible";
		}
		*/
		
		if(p_immediate) {
			this.displaySelectedInterestPage();
		} else {
			this.root.findName("interestDetailPanels_out").Begin();
		}
	},
	oninterestDetailPanels_outComplete: function(sender, eventArgs) {
		this.displaySelectedInterestPage();
	},
	displaySelectedInterestPage: function() {
		var firstItem = (this.SelectedInterestPageIndex-1)*3;
		var lastItem = Math.min(firstItem+2,this.InterestArticles[this.InterestNames[this.SelectedInterestIndex]].length-1);
		var count = 1;
		for(var i=firstItem; i<=firstItem+2; i++) {
			if(i<=lastItem) {
				this.root.findName("InterestTitle"+count)["Text"] = this.InterestArticles[this.InterestNames[this.SelectedInterestIndex]][i]["title"];
				this.root.findName("InterestDesc"+count)["Text"] = this.InterestArticles[this.InterestNames[this.SelectedInterestIndex]][i]["description"];
				this.root.findName("interestDetail"+count).Visibility = "Visible";
			} else {
				this.root.findName("interestDetail"+count).Visibility = "Collapsed";
			}
			count++;
		}
		this.root.findName("interestDetailPanels_in").Begin();
	},
	onViewDemoButtonClick: function(sender, eventArgs) {
		var chosenLink = Number(sender.Name.substr(12));
		var chosenArticleIndex = (this.SelectedInterestPageIndex-1)*3 + chosenLink-1;
		this.requestLink(this.InterestArticles[this.InterestNames[this.SelectedInterestIndex]][chosenArticleIndex]["url"]);
	},



	/**************************************************
		BUTTON INTERACTIONS
	**************************************************/
	onButtonClick: function(sender, eventArgs) {
	    this.collectWebTrends(sender.Name);
		switch (sender.Name) {
		   case "btn_exploreByInterest" :
			  this.SelectSection("Interest");
			  break; 
		   case "btn_download" :
			  // From Default.htm:
			  this.requestLink(DownloadLink);
			  break; 
		   case "btn_exploreByProduct" :
			  this.SelectSection("Product");
			  break; 
		   case "btn_product1" :
			  this.openProductTour(1);
			  break; 
		   case "btn_product2" :
			  this.openProductTour(2);
			  break; 
		   case "btn_product3" :
			  this.openProductTour(3);
			  break; 
		   case "btn_product4" :
		   	  this.openProductTour(4);
			  break; 
		   case "btn_interest1" :
			  this.SelectSection("InterestDetail");
			  this.SelectInterest(0);
			  break; 
		   case "btn_interest2" :
			  this.SelectSection("InterestDetail");
			  this.SelectInterest(1);
			  break; 
		   case "btn_interest3" :
			  this.SelectSection("InterestDetail");
			  this.SelectInterest(2);
			  break; 
		   case "btn_interest4" :
			  this.SelectSection("InterestDetail");
			  this.SelectInterest(3);
			  break;
		}
	},
	collectWebTrends: function(text) {
	    dcsMultiTrack("DCS.dcsuri", "slTrack", "intro", text );
	},
	openProductTour: function(p_num) {
		//From Default.htm
		OpenProductTour(p_num);
	},
	onButtonRollover: function(sender, eventArgs) {
		if(sender.name.substring(0,8)=="btn_Page" && sender.name.substring(8,9)==this.SelectedInterestPageIndex) {
			//ignore
		} else if(sender.name.substring(0,12)=="btn_Interest" && sender.name.substring(12,13)==this.SelectedInterestIndex+1) {
			//ignore
		} else {
			this.root.findName(sender.Name+"_over").Begin();
		}
	},
	onButtonRollout: function(sender, eventArgs) {
		if(sender.name.substring(0,8)=="btn_Page" && sender.name.substring(8,9)==this.SelectedInterestPageIndex) {
			//ignore
		} else if(sender.name.substring(0,12)=="btn_Interest" && sender.name.substring(12,13)==this.SelectedInterestIndex+1) {
			//ignore
		} else {
			this.root.findName(sender.Name+"_out").Begin();
		}
	},
	
	/**************************************************
		SECTION TRANSITIONS
	**************************************************/
	SelectSection: function(p_sectionName) {
		if(this.SelectedSection != p_sectionName) {
			this.root.findName(this.SelectedSection+"Panel_out").Begin();
			this.SelectedSection = p_sectionName;
			this.root.findName(this.SelectedSection+"Panel").Visibility = "Visible";
			this.root.findName(this.SelectedSection+"Panel_in").Begin();
		}
	},
	onInterestButtonClick: function(sender, eventArgs) {
		this.SelectInterest(sender.name.substr(12,1)-1);
	},
	SelectInterest: function(p_interestIndex) {
		if(this.SelectedInterestIndex != p_interestIndex) {
			this.root.findName("image_interest_panel"+(this.SelectedInterestIndex+1)).Visibility = "Collapsed";
			this.root.findName("btn_Interest"+(this.SelectedInterestIndex+1)+"_out").Begin();
			
			this.SelectedInterestIndex = p_interestIndex;
			
			this.root.findName("btn_Interest"+(this.SelectedInterestIndex+1)+"_over").Begin();
			//this.InterestButtonFocus["Canvas.Left"] = 	this["btn_Interest"+(p_interestIndex+1)]["Canvas.Left"]-11;
			//this.InterestButtonFocus["Width"] = 		this["btn_Interest"+(p_interestIndex+1)]["Width"]+21;
			this.buildInterestPages(this.InterestNames[this.SelectedInterestIndex]);
			this.root.findName("image_interest_panel"+(this.SelectedInterestIndex+1)).Visibility = "Visible";
		}
	},
	onIntroPanel_outComplete: function(sender, eventArgs) {
		  this.root.findName("IntroPanel").Visibility = "Collapsed";
	},
	onInterestPanel_outComplete: function(sender, eventArgs) {
		  this.root.findName("InterestPanel").Visibility = "Collapsed";
	},
	onInterestDetailPanel_outComplete: function(sender, eventArgs) {
		  this.root.findName("InterestDetailPanel").Visibility = "Collapsed";
	},
	onProductPanel_outComplete: function(sender, eventArgs) {
		  this.root.findName("ProductPanel").Visibility = "Collapsed";
	},
	
	/**************************************************
		SLIDE TRANSITIONS
	**************************************************/
	SlideIn: function(p_index) {
		this.root.findName("slide"+p_index).Visibility="Visible";
		this.root.findName("slide"+p_index+"_in").Begin();
	},
	SlideOut: function(p_index) {
		this.root.findName("slide"+p_index+"_out").Begin();
	},
	onslideN_inCompleted: function(sender, eventArgs) {
		this.waitForNextSlide();
	},
	waitForNextSlide: function() {
		this.SB_5secDelay.Begin();
	},
	onSB_5secDelayCompleted: function(sender, eventArgs) {
		this.TransitionToNextSlide();
	},
	onslideN_outCompleted: function(sender, eventArgs) {
		this.currentSlide = this.nextSlide;
		this.SlideIn(this.currentSlide);
	},
	TransitionToSlide: function(p_index) {
		this.nextSlide = p_index;
		this.SlideOut(this.currentSlide);
	},
	TransitionToNextSlide: function() {
		if(this.currentSlide==12) {
			this.TransitionToSlide(1);
		} else {
			this.TransitionToSlide(this.currentSlide+1);
		}
	},
	
	/**************************************************
		ENERGY VIDEOS
	**************************************************/
	MediaElement_Energy_onOpened: function(sender, eventArgs)
	{
	},
	MediaElement_Energy_onMediaEnded: function(sender, eventArgs)
	{
		sender.Position = "00:00:00";
		sender.Play();
	},
	SB_Energy_Completed: function(sender, eventArgs)
	{
		for (i in this.EnergyColors) {
			var myColor = this.EnergyColors[i];
			if(myColor!=this.SelectedColor) {
				this.HideEnergyVideo(myColor);
			}
		}
		this.ShowEnergyVideo(this.SelectedColor);
	},
	EnergyColorSwitch: function(p_color)
	{
		var myColor = p_color;
		
		if(myColor!=this.SelectedColor) {
			for (i in this.EnergyColors) {
				var myColor2 = this.EnergyColors[i];
				if(myColor2!=myColor && myColor2!=this.SelectedColor) {
					this.HideEnergyVideo(myColor2);
				} else {
					this.ShowEnergyVideo(myColor2);
				}
			}
			
			if(myColor>this.SelectedColor) {
				this.FadeInEnergyVideo(myColor);
			} else if (myColor<this.SelectedColor) {
				this.root.findName("MediaElement_Energy"+myColor).Opacity = 100;
				this.FadeOutEnergyVideo(this.SelectedColor);
			}
			
			this.SelectedColor = myColor;
		}
	},
	FadeOutEnergyVideo: function(myColor)
	{
		this.root.findName("SB_MediaElement_Energy"+myColor+"_Hide").Begin();
	},
	FadeInEnergyVideo: function(myColor)
	{
		this.root.findName("SB_MediaElement_Energy"+myColor+"_Show").Begin();
	},
	HideEnergyVideo: function(myColor)
	{
		this.root.findName("MediaElement_Energy"+myColor).Visibility = "Collapsed";
	},
	ShowEnergyVideo: function(myColor)
	{
		this.root.findName("MediaElement_Energy"+myColor).Visibility = "Visible";
	},
	
	/**************************************************
		UTILITIES
	**************************************************/
	requestLink: function(p_url) {
		//on Default.htm
		RequestLink(p_url);
	},
	getXMLDoc: function(url, callBack, xthis) {
		if (this.BrowserFamily=="Mozilla")
		{
			var xmldoc = document.implementation.createDocument("", "", null);
			xmldoc.onload = function() {
					callBack(this, xthis);
			}
		}
		else if (this.BrowserFamily=="IE")
		{
			var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
			xmldoc.onreadystatechange = function () {
				if (xmldoc.readyState == 4) {
					callBack(xmldoc, xthis);
				}
			};
	 	}
		else
		{
			//alert('Your browser can\'t handle this script.');
			return;
		}
		xmldoc.load(url);
	},

	getXMLDocSource: function(url, callBack, xthis) {
		if (this.BrowserFamily=="Mozilla")
		{
			var xmldoc = document.implementation.createDocument("", "", null);
			xmldoc.onload = function() {
					callBack(xthis.getSourceFromXMLDoc(this), xthis);
			}
		}
		else if (this.BrowserFamily=="IE")
		{
			var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
			xmldoc.onreadystatechange = function () {
				if (xmldoc.readyState == 4) {
					callBack(xthis.getSourceFromXMLDoc(xmldoc), xthis);
				}
			};
	 	}
		else
		{
			//alert('Your browser can\'t handle this script.');
			return;
		}
		xmldoc.load(url);
	},
	
	getSourceFromXMLDoc: function(xmlDoc) {
		if (xmlDoc.xml == null)
		{
			var serializer = new XMLSerializer();
			var xml = serializer.serializeToString(xmlDoc);
		}
		else
		{
			var xml = xmlDoc.xml;
		}
		return xml;
	}, 
	addEvent: function(a,b,c,d) {
		a.addEventListener(b, Silverlight.createDelegate(c, c[d]));
	},
	centerText: function(textObject) {
		textObject["Canvas.Left"] += Math.round((textObject.Width - textObject.ActualWidth)/2);
		textObject.Width = Math.ceil(textObject.ActualWidth);
	},	
	rightAlignText: function(textObject) {
		textObject["Canvas.Left"] += Math.round(textObject.Width - textObject.ActualWidth);
		textObject.Width = Math.ceil(textObject.ActualWidth);
	}
}