﻿if (!window.ArtsAndArchitecture)
    window.ArtsAndArchitecture = {};
    
ArtsAndArchitecture.ViewSelect = function(control, target, x, y)
{
    this.control = control;
    this.target = target;
    
    this._viewSelectSlideIn = this.target.findName("ViewSelectSlideIn");
    this._viewSelectSlideOut = this.target.findName("ViewSelectSlideOut");
    this._viewSelectButtonsSlideIn = this.target.findName("ViewSelectButtonsSlideIn");
    this._viewSelectButtonsSlideOut = this.target.findName("ViewSelectButtonsSlideOut");
    
    this._viewSelectButtonNorth = this.target.findName("ViewSelectButtonNorth");
    this._viewSelectButtonEast = this.target.findName("ViewSelectButtonEast");
    this._viewSelectButtonSouth = this.target.findName("ViewSelectButtonSouth");
    
    this._viewSelectButtonNorth.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_ButtonNorth));
    this._viewSelectButtonEast.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_ButtonEast));
    this._viewSelectButtonSouth.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_ButtonSouth));
        
    this.target["Canvas.Top"] = y;
    this.target["Canvas.Left"] = x;
}

ArtsAndArchitecture.ViewSelect.prototype = 
{
    slideButtonsIn: function()
    {
        this._viewSelectButtonsSlideIn.Begin(); 
    },
    
    slideButtonsOut: function()
    {
        this._viewSelectButtonsSlideOut.Begin();
    },
    
    slideIn: function()
    {
        // TODO: hack
        if (AAPanelAttract.Visibility != "Visible") {
            this._viewSelectSlideIn.Begin(); 
        }
    },
    
    slideOut: function()
    {
        this._viewSelectSlideOut.Begin();
    },
    
    selectNorth: function()
    {

		AACurrentData = AAData["north"];
        this._viewSelectButtonEast.source = "Content/view_select/view_select_east_btn_u.png";
        this._viewSelectButtonSouth.source = "Content/view_select/view_select_south_btn_u.png";
        this._viewSelectButtonNorth.source = "Content/view_select/view_select_north_btn_d.png";

		AAMainView.loadMainView();
    },
    
    selectEast: function()
    {

		AACurrentData = AAData["east"];
        this._viewSelectButtonSouth.source = "Content/view_select/view_select_south_btn_u.png";
        this._viewSelectButtonNorth.source = "Content/view_select/view_select_north_btn_u.png";            
        this._viewSelectButtonEast.source = "Content/view_select/view_select_east_btn_d.png";
		AAMainView.loadMainView();
    },
    
    selectSouth: function()
    {

		AACurrentData = AAData["south"];
        this._viewSelectButtonEast.source = "Content/view_select/view_select_east_btn_u.png";
        this._viewSelectButtonNorth.source = "Content/view_select/view_select_north_btn_u.png"; 
        this._viewSelectButtonSouth.source = "Content/view_select/view_select_south_btn_d.png";
		AAMainView.loadMainView();
    },

    handleMouseLeftButtonDown_ButtonNorth: function (sender, args)
    {
        if (AACurrentData == AAData["north"]) return;
        this.selectNorth();
        AAMainView.tweenToStart();
    },
    
    handleMouseLeftButtonDown_ButtonEast: function (sender, args)
    {
        if (AACurrentData == AAData["east"]) return;    
        this.selectEast();
        AAMainView.tweenToStart();
    },
    
    handleMouseLeftButtonDown_ButtonSouth: function (sender, args)
    {
        if (AACurrentData == AAData["south"]) return;    
        this.selectSouth();
        AAMainView.tweenToStart();
    }
}