function CardInfo(controlContent, pinAnimationId, pinName, detailCard)
{
	var m_pinAnimationId = pinAnimationId;
	var m_showPictureAnimationId = 'GenInfoCard';
	var m_hidePictureAnimationId = 'StormypointInfocardReverse';
	var m_pinName = pinName;
	var m_isDisplayed = false;
	
	var detailElement = controlContent.findName(detailCard);	
	var m_textElement = detailElement.children.getItem(1);
	var m_pictureElement = detailElement.children.getItem(2);
	
	this.ToggleCardDisplay = toggleCardDisplay;
	this.PinName = getPinName;
	
	function getPinName()
	{
		return m_pinName;
	}
	
	function toggleCardDisplay(sender, eventArgs)
	{
		var showAnimation = sender.findName("GenInfoCard");
					//alert(showAnimation);
		var textElement = sender.findName("genText");		
					//alert(textElement );
		var pictureElement = sender.findName("pic");
					//alert(pictureElement );
		var pinAnimation = sender.findName(m_pinAnimationId);
		if (pinAnimation==null)
		{
			alert('Cannot find storyboard for ' + m_pinAnimationId);
		}
				//alert(pinAnimation );
		var hideAnimation = sender.findName(m_hidePictureAnimationId);
				//alert(hideAnimation );
		

		if (m_isDisplayed)
		{
			// stop all running animations and start the hide animations
			showAnimation.stop();
			if (pinAnimation)
				pinAnimation.stop();
			hideAnimation.begin();
			m_isDisplayed = false;
		}
		else
		{
			// stop any hide animations and start the show ones
			hideAnimation.stop();
			
			// change the picture and text elements			
			pictureElement.Source = m_pictureElement.Source;//m_pictureSource;
			pictureElement.Width = m_pictureElement.Width;
			pictureElement.Height = m_pictureElement.Height;
			textElement.Text = m_textElement.Text;
			

			showAnimation.begin();

			if (pinAnimation)
				pinAnimation.begin();

			m_isDisplayed = true;
		}
	}
			
}

var cards = new Array();

function FindCardByPinName(pinName)
{
	for(var i=0;i<cards.length;i++)
	{
		if (cards[i].PinName()==pinName)
		{
			return cards[i];
		}
	}
	return null;
}

if (!window.aedge_map)
	window.aedge_map = {};

aedge_map.Page = function() 
{
}

aedge_map.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		// Add Cards here
		cards[0] = new CardInfo(control.content, 'StormypointMapPin','pin_stormypoint', 'InfoCardStormyPoint');
		cards[1] = new CardInfo(control.content, 'GoldenStoneMapPin','pin_goldenstone',	'InfoCardGoldenStone');
		cards[2] = new CardInfo(control.content, 'EngineveinMapPin', 'pin_enginevein',	'InfoCardEngineVein');
		cards[3] = new CardInfo(control.content, 'WizardsWellMapPin','pin_wizardswell', 'InfoCardWizardsWell');
		cards[4] = new CardInfo(control.content, 'CastleRockMapPin', 'pin_castlerock',  'InfoCardCastleRock');
		cards[5] = new CardInfo(control.content, 'BeaconMapPin', 'pin_beacon',  'InfoCardBeacon');
		cards[6] = new CardInfo(control.content, 'HolyWellMapPin', 'pin_holywell',  'InfoCardHolyWell');
		cards[7] = new CardInfo(control.content, 'DevilsGraveMapPin', 'pin_devilsgrave',  'InfoCardDevilsGrave');
		cards[8] = new CardInfo(control.content, 'QuarryMapPin', 'pin_quarry',  'InfoCardQuarry');

		

		// 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();
	}
		
}



var currentCard = null;

function animatePicture_begin(sender, args) {

	var	name = sender.name;
	var card = null;
	
	if (name.substring(0,4) == 'pin_')
	{
		 card = FindCardByPinName(sender.name);
	}
	else
	{
		card = currentCard;
	}
	
	if (card==null)
	{
		alert('could not locate card for ' + name + ' please ensure the pin x:Name starts with pin_');	
	}	 
	else
	{
		card.ToggleCardDisplay(sender, args);
		currentCard = card;
	}
	
}


