﻿if (!window.JAL_Collection_1)
	window.JAL_Collection_1 = {};

JAL_Collection_1.Page = function() 
{
}

JAL_Collection_1.Page.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("Storyboard1").Begin();
	}
}





function loadImages(sender, args)
{

    var i;

    // Add Xaml for each thumbnail
	for (i=0; i < photoArray.length; i++) 
	{
		if (photoArray[i] != "") 
		{

            // 80
			var XamlTemplateString = '<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ';
			XamlTemplateString += '     Width="80" Height="80" Canvas.Top="_TOP_" x:Name="TN_Canvas_NUM_" MouseEnter="handleTNMouseEnter" MouseLeftButtonDown="handleTNMouseLeftButtonDown" Cursor="Hand" > ';

//			XamlTemplateString += '  <Canvas.Triggers>';
//			XamlTemplateString += '   <EventTrigger RoutedEvent="Canvas.Loaded">';
//			XamlTemplateString += '     <BeginStoryboard> ';
//			XamlTemplateString += '      <Storyboard>';
//			XamlTemplateString += '       <DoubleAnimation BeginTime="00:00:04" SpeedRatio=".4" Storyboard.TargetName="TN_Canvas_NUM_" Storyboard.TargetProperty="(Canvas.Top)"';
//			XamlTemplateString += '             To="_TOP_" AutoReverse="False" />';
//			XamlTemplateString += '      </Storyboard>';
//			XamlTemplateString += '     </BeginStoryboard>';
//			XamlTemplateString += '   </EventTrigger>';
//			XamlTemplateString += '  </Canvas.Triggers>';

			XamlTemplateString += '  <Rectangle Opacity="1" x:Name="TN_Frame_NUM_" Width="76" Height="76" Canvas.Left="2" Canvas.Top="2" Stroke="#FFcccccc" Fill="#FFFFFFFF"/>';
			XamlTemplateString += '  <Image Width="74" Height="74" x:Name="TN_Image_NUM_" Canvas.Left="3" Canvas.Top="3" />';
			XamlTemplateString += '</Canvas>';

			// 60
//			var XamlTemplateString = '<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="60" Height="60" Canvas.Top="_TOP_" x:Name="TN_Canvas_NUM_" MouseEnter="handleTNMouseEnter" MouseLeftButtonDown="handleTNMouseLeftButtonDown" Cursor="Hand" > ';
//			XamlTemplateString += '  <Rectangle Opacity="1" x:Name="TN_Frame_NUM_" Width="56" Height="56" Canvas.Left="2" Canvas.Top="2" Stroke="#FFcccccc" Fill="#FFFFFFFF"/>';
//			XamlTemplateString += '  <Image Width="54" Height="54" x:Name="TN_Image_NUM_" Canvas.Left="3" Canvas.Top="3" />';
//			XamlTemplateString += '</Canvas>';
			
			var thisXamlString = XamlTemplateString.replace(/_NUM_/g, i);			
			thisXamlString = thisXamlString.replace(/_TOP_/g, i * 80);
			//sender.findName("txtMsg").text = thisXamlString;


			var plugin = sender.getHost();
			//sender.findName("txtMsg").text = thisXamlString + " : " + plugin.version;
			
			var newCanvas = plugin.content.createFromXaml( thisXamlString, false );
			
			plugin.content.findName("TN_Container").children.add(newCanvas);
			
		}
	}





	// change the background color for the images
	// being used to white
	/*
	for (i=0; i < photoArray.length; i++) {
		if (photoArray[i] != "") {
			nameString = "TN_Image" + i;
			sender.findName(nameString).Opacity = 1;
			sender.findName(nameString).Visibility = "Visible";
		}
	}
	*/



	// load the images from the array into the thumbnail canvases
	for (i=0; i<photoArray.length; i++)
	{
		if (photoArray[i] != "") 
		{
		    nameString = "TN_Image" + i;
		    sender.findName(nameString).Source = photoArray[i];
		}
	}

	
}





var SelectedCategory = "";

function handleTNMouseEnter(sender, mouseEventArgs)
{

	//sender.findName("txtGalleryTitle").text = sender.name.charAt(9);
	
	nameString = "TN_Image" + sender.name.charAt(9);

	


	// Retrieve the Storyboard resource.
    var myStoryboard = sender.findName("MainImageFadeOut");

    // Retrieve the DoubleAnimation.
    var myDoubleAnimation = sender.findName("MainImageFadeOutOpacity");
    
    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    myStoryboard.stop();

    // Change the TargetName of the animation to the name of the
    // rectangle that was clicked.
    //myDoubleAnimation["Storyboard.TargetName"] = sender.Name;
    myDoubleAnimation["Storyboard.TargetName"] = "DetailImage";

    // Begin the animation.
    myStoryboard.begin();


	sender.findName("DetailImage").Source = sender.findName(nameString).Source; 



	// Retrieve the Storyboard resource.
    myStoryboard = sender.findName("MainImageFadeIn");

    // Retrieve the DoubleAnimation.
    myDoubleAnimation = sender.findName("MainImageFadeInOpacity");
    
    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    myStoryboard.stop();

    // Change the TargetName of the animation to the name of the
    // rectangle that was clicked.
    //myDoubleAnimation["Storyboard.TargetName"] = sender.Name;
    myDoubleAnimation["Storyboard.TargetName"] = "DetailImage";

    // Begin the animation.
    myStoryboard.begin();


	// Save selected category
	SelectedCategory = CategoryTitleArray[sender.name.charAt(9)];

    // Display category text
    var thisCategoryTitleTextBlock = sender.findName("CategoryTitleTextBlock");
	thisCategoryTitleTextBlock.text = "Select Works - " + SelectedCategory;

    // Center category text
    //var thisLeft = ( (400 - thisCategoryTitleTextBlock.ActualWidth) / 2 ) + 40;
    //thisCategoryTitleTextBlock["Canvas.Left"] = thisLeft;

}


function handleTNMouseLeftButtonDown(sender, mouseEventArgs)
{
	window.location = "SelectWorks.aspx?Category=" + SelectedCategory;
}






function myhandleMouseDown(sender, mouseEventArgs)
{
    /*
		// Retrieve the Storyboard resource.
	    var myStoryboard = sender.findName("InitialFadeIn");

	    // Retrieve the DoubleAnimation.
	    var myDoubleAnimation = sender.findName("InitialFadeInOpacity");
	    
	    // If the Storyboard is running and you try to change
	    // properties of its animation objects programmatically, 
	    // an error will occur.
	    myStoryboard.stop();

	    // Change the TargetName of the animation to the name of the
	    // rectangle that was clicked.
	    myDoubleAnimation["Storyboard.TargetName"] = sender.Name;

	    // Begin the animation.
	    myStoryboard.begin();
	*/

	window.location = "SelectWorks.aspx?Category=" + SelectedCategory;
	
}




function handleMouseDown_CategoryTitleTextBlock(sender, mouseEventArgs)
{
	//sender.findName("CategoryTitleTextBlock").text = "<a href='SelectWorks.aspx?Category=" + CategoryTitleArray[sender.name.charAt(9)] + ">" + CategoryTitleArray[sender.name.charAt(9)] + "</a>";

	//window.location = "SelectWorks.aspx?Category=" + sender.findName("CategoryTitleTextBlock").text;
	window.location = "SelectWorks.aspx?Category=" + SelectedCategory;
}








function handleScrollUpThumbnailsButtonMouseEnter(sender, mouseEventArgs)
{

	// Retrieve the Storyboard resource.
    var myStoryboard = sender.findName("TN_Container_ScrollUp");

    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    //myStoryboard.stop();

    // Begin the animation.
    myStoryboard.begin();

}



function handleScrollUpThumbnailsButtonMouseLeave(sender, mouseEventArgs)
{

	// Retrieve the Storyboard resource.
    var myStoryboard = sender.findName("TN_Container_ScrollUp");

    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    myStoryboard.pause();

}



function handleScrollDownThumbnailsButtonMouseEnter(sender, mouseEventArgs)
{

	// Retrieve the Storyboard resource.
    var myStoryboard = sender.findName("TN_Container_ScrollDown");

    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    //myStoryboard.stop();

    // Begin the animation.
    myStoryboard.begin();

}



function handleScrollDownThumbnailsButtonMouseLeave(sender, mouseEventArgs)
{

	// Retrieve the Storyboard resource.
    myStoryboard = sender.findName("TN_Container_ScrollDown");

    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    myStoryboard.pause();

}













function handleFullScreenButtonMouseEnter(sender, mouseEventArgs)
{
    sender.findName("FullScreenTooltipTextBlock").opacity = 1;
}

function handleFullScreenButtonMouseLeave(sender, mouseEventArgs)
{
    sender.findName("FullScreenTooltipTextBlock").opacity = 0;
}

function handleFullScreenButtonMouseLeftButtonDown(sender, mouseEventArgs)
{
    var plugin = sender.getHost();
//    var thisPage = sender.findName("Page");
//    var thisMasterContainerScaleTransform = sender.findName("MasterContainerScaleTransform");

    plugin.content.fullScreen = !plugin.content.fullScreen;
    
//    if( plugin.content.fullScreen == true )
//    {
//        thisMasterContainerScaleTransform = 2;
//        thisPage.Top = 100;
//    }
//    else
//    {
//        thisMasterContainerScaleTransform = 1;
//        thisPage.Top = 0;
//    }

    sender.findName("FullScreenTooltipTextBlock").opacity = 0;

}





function handleRestartButtonMouseEnter(sender, mouseEventArgs)
{


	// Retrieve the Storyboard resource.
    var myStoryboard = sender.findName("GlobalStoryboard");

    
    // If the Storyboard is running and you try to change
    // properties of its animation objects programmatically, 
    // an error will occur.
    myStoryboard.stop();


    // Begin the animation.
    myStoryboard.begin();


    // Reload initial values
	sender.findName("DetailImage").Source = "OurCollection_SL/DetailImages/SelectWorks400.jpg";
	sender.findName("CategoryTitleTextBlock").Text = "";
    SelectedCategory = "";

}
