if (!window.photoGallery)
	window.Dvbbs = {};

Dvbbs.AlbumPage = function() 
{
}

Dvbbs.AlbumPage.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		// 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();
	}
}
Dvbbs.AlbumTitle = '';
Dvbbs.AlbumImages = [];
Dvbbs.SilverlightSender = null;

var zoomFlag = 0;

function loadImages(sender,args){

	if (sender)
	{
		Dvbbs.SilverlightSender = sender;
	}
	else if (!sender && Dvbbs.SilverlightSender)
	{
		sender = Dvbbs.SilverlightSender;
	}

	// set the gallery title text
	sender.findName("txtGalleryTitle").text = Dvbbs.AlbumTitle;

	// change the background color for the images
	// being used to white
	for (var i=0; i < 12; i++) {
		nameString = "photo" + i;
		if (Dvbbs.AlbumImages[i]) {
			sender.findName(nameString).Opacity = 1;
			sender.findName(nameString).Visibility = "Visible";
		}
		else
		{
			sender.findName(nameString).Visibility = "Collapsed";
		}
	}

	// load the images from the array into
	// the gallery canvases
	var dest = null;
	for (var i = 0; i < 12; i++) {
		nameString = "image" + i;
		dest = sender.findName(nameString);
		if (dest && Dvbbs.AlbumImages[i])
		{
			dest.Source = Dvbbs.AlbumImages[i];
		}
	}	
}

function mouseEnter(sender, args) {

	var dest = null;
	// zero out the z-index for any photos being displayed
	for (var i=0; i < 12; i++) {
		nameString = "photo" + i;
		dest = sender.findname(nameString);
		if (dest)
		{
			dest["canvas.ZIndex"] = 0;
		}
	}	
	
	// play the mouse enter storyboard for the selected image
	photoPosition = sender.name.charAt(5) + sender.name.charAt(6);
	nameString = "mouseEnter" + photoPosition;
	sender.findName(nameString).begin();
}

function mouseLeave(sender, args) {
	photoPosition = sender.name.charAt(5) + sender.name.charAt(6);

	// if the image has already been clicked, first, zoom back out
	// then play the mouse out action. Otherwise (the image has not
	// yet been clicked, so just play the mouse out action
	if (zoomFlag == 1) {
		nameString = "pictureZoomOut" + photoPosition;
		sender.findName(nameString).begin();
		nameString = "mouseLeave" + photoPosition;
		sender.findName(nameString).begin();
		zoomFlag = 0;
	}
	else {
		nameString = "mouseLeave" + photoPosition;
		sender.findName(nameString).begin();
	}
}

function pictureZoomIn(sender, args) {
	photoPosition = sender.name.charAt(5) + sender.name.charAt(6);
	
	// if the photo is already zoomed in (clicked), then play the
	// zoom out storyboard, otherwise, the picture has not
	// been zoomed in (clicked) and should be.
	if (zoomFlag == 1) {
		nameString = "pictureZoomOut" + photoPosition;
		sender.findName(nameString).begin();
		zoomFlag = 0;
	}

	else {
		nameString = "pictureZoomIn" + photoPosition;	
		sender.findName(nameString).begin();
		sender["canvas.ZIndex"] = 1;
		zoomFlag = 1;
	}
}
