﻿///<reference path="Page.xaml.js"/>

function TomatoTool(page)
{
    this.Page = page;
    this.Control = page.control;
    this.Button = page.control.content.findName("Tomato");
    this.Overlay = page.control.content.findName("Overlay");
    this.Media = page.control.content.findName("Media");
    this.Xaml = page.XamlFiles["Tomato.xaml"];
    this.Button.IsHitTestVisible = true;
}

TomatoTool.prototype.toString = function()
{
    return "TomatoTool";
}

TomatoTool.prototype.Update = function(shape)
{
}

TomatoTool.prototype.LeftButtonDown = function(sender, eventArgs)
{
    var tomato = this.Control.content.createFromXaml(this.Xaml, true);
    
    var position = eventArgs.getPosition(this.Overlay);
    
    tomato["Canvas.Left"] = position.X;
    tomato["Canvas.Top"] = position.Y;
    
    var name = "Overlay" +  this.Page.Overlays.length;
    
    //var xaml = '<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="' + name + '"/>';
    
    //var tomatoParent = this.Control.content.createFromXaml(xaml);
    
    //tomatoParent.children.Add(tomato);
    
    this.Overlay.children.Add(tomato);
    
    var animation = tomato.findName("Animation");
    
    animation.Begin();
    
    var overlay = new Overlay(name, new TomatoOverlay(position, this.Xaml), this.Page.Timeline);
    
    this.Page.SelectedOverlay = overlay;
    
    overlay.AddKeyFrame(this.Page);
    
    this.Page.Overlays.push(overlay);
    this.Page.TimelineMarkers.push('<TimelineMarker xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Type="Name" Time="' + formatTime(this.Page.Media.Position.seconds) + '" Text="' + name + '" x:Name="' + name + '" />');
    
    this.Page.UpdateXaml();
    
    TrackEvent("TomatoThrown");
}   


TomatoTool.prototype.MouseMove = function(sender, eventArgs)
{
}

TomatoTool.prototype.LeftButtonUp = function(sender, eventArgs)
{
}

TomatoTool.prototype.Activate = function()
{
}

TomatoTool.prototype.Deactivate = function()
{
}