if (!window.orbit)
	window.orbit = {};

orbit.Page = function() 
{
}

orbit.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
	    this.control = control;
				
		function fillCanvas(roleName1, roleName2, roleName3, roleName4, roleName5)
        {
		    canImage1 = control.content.FindName("canImage1");
		    canImage1.source = orbitImageBase + roleName1 + ".png";
		    /**/
		    canImage2 = control.content.FindName("canImage2");
		    canImage2.source = orbitImageBase + roleName2 + ".png";
		    /**/
		    canImage3 = control.content.FindName("canImage3");
		    canImage3.source = orbitImageBase + roleName3 + ".png";
		    /**/
		    canImage4 = control.content.FindName("canImage4");
		    canImage4.source = orbitImageBase + roleName4 + ".png";
		    /**/
		    canImage5 = control.content.FindName("canImage5");
		    canImage5.source = orbitImageBase + roleName5 + ".png";
        }

        /*filling the canvases with icons and text*/
        switch (selectedRole) 
	    { 
		     case "Home" : 
			    fillCanvas('Pupils', 'Parents', 'Home', 'Students', 'Teachers');
		     break; 
		     case "Parents" : 
			    fillCanvas('Teachers', 'Pupils', 'Parents', 'Home', 'Students');
		     break; 
		     case "Pupils" : 
			    fillCanvas('Students', 'Teachers', 'Pupils', 'Parents', 'Home');
		     break; 
		     case "Teachers" : 
			    fillCanvas('Home', 'Students', 'Teachers', 'Pupils', 'Parents');
		     break; 
		     case "Students" : 
			    fillCanvas('Parents', 'Home', 'Students', 'Teachers', 'Pupils');
		     break; 
		     default : 
		     fillCanvas('Pupils', 'Parents', 'Home', 'Students', 'Teachers');
		     break; 
	    } 

		/* prepraing buttons and time lines*/
		canButon1 = control.content.FindName("canButon1");
		canAnimation1 = control.content.FindName("canAnimation1");

		canButon2 = control.content.FindName("canButon2");
		canAnimation2 = control.content.FindName("canAnimation2");

		canButon4 = control.content.FindName("canButon4");
		canAnimation4 = control.content.FindName("canAnimation4");

		canButon5 = control.content.FindName("canButon5");
		canAnimation3 = control.content.FindName("canAnimation3");
		/*default case*/
		canButon3 = control.content.FindName("canButon3");

		/**/		
		/*event handler*/		
	    canButon1.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.animation1));
	    canButon2.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.animation2));
	    canButon4.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.animation3));
	    canButon5.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.animation4));	
	    /*default case link*/
	    canButon3.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this,  this.getURL5));
	    /*animation on end*/
	    canAnimation1.addEventListener("completed", Silverlight.createDelegate(this, this.getURL1));
	    canAnimation2.addEventListener("completed", Silverlight.createDelegate(this, this.getURL2));
	    canAnimation3.addEventListener("completed", Silverlight.createDelegate(this, this.getURL3));
	    canAnimation4.addEventListener("completed", Silverlight.createDelegate(this, this.getURL4));
	
		// Sample event hookup:	
		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
	},
	
	// Sample event handler
	handleMouseDown: function(sender, eventArgs) 
	{
		// The following line of code shows how to find an element by name and call a method on it.
		// this.control.content.findName("Timeline1").Begin();
	},
	animation1: function(sender, eventArgs) 
	{
	   canAnimation1.begin();
	},
	animation2: function(sender, eventArgs) 
	{
	   canAnimation2.begin();
	},
	animation3: function(sender, eventArgs) 
	{
	   canAnimation3.begin();
	},
	animation4: function(sender, eventArgs) 
	{
	   canAnimation4.begin();
	},
	getURL1: function(sender, eventArgs) 
	{
		location.href = URL1;
	},
	getURL2: function(sender, eventArgs) 
	{
		location.href = URL2;
	},
	getURL3: function(sender, eventArgs) 
	{
		location.href = URL3;
	},
	getURL4: function(sender, eventArgs) 
	{
		location.href = URL4;
	},
	getURL5: function(sender, eventArgs) 
	{
		location.href = URL5;
	}
}