﻿if ( !window.Controls )
    window.Controls = {};

Controls.TabNavigatorSmall = function( owner )
{
    this.owner = owner;
}

Controls.TabNavigatorSmall.prototype.owner = null;
Controls.TabNavigatorSmall.prototype.tabs = [];
Controls.TabNavigatorSmall.prototype.selectedIndex = -1;

Controls.TabNavigatorSmall.prototype.addTab = function( checkbox, canvas )
{
    var item = new SLx.CheckBox ( checkbox );
    item._wireTriggers();
    item.add_Checked( Silverlight.createDelegate ( this , this.onSelectionChanged ));
    this.tabs[this.tabs.length] = { name: checkbox.Name, item: item, checkbox: checkbox, canvas: canvas };
}
Controls.TabNavigatorSmall.prototype.onSelectionChanged = function(sender, eventArgs)
{
    for ( var i=0; i<this.tabs.length; i++ )
    {
        if ( this.tabs[i].name != sender.get_visual().Name )
        {
            this.tabs[i].item.set_isChecked (false);
            this.tabs[i].canvas.Visibility = "Collapsed";
            this.tabs[i].canvas["Canvas.ZIndex"] = 10;
        }
    }
    this.showNamedTab( sender.get_visual().Name );
}
Controls.TabNavigatorSmall.prototype.showTab = function( index )
{
    if ( index == 1 )
        this.owner.control.content.root.FindName("Halo3_wmv").Play();
    else
        this.owner.control.content.root.FindName("Halo3_wmv").Stop();
    this.tabs[ index ].canvas.Visibility = "Visible";
    this.tabs[ index ].canvas["Canvas.ZIndex"] = 20;
    this.selectedIndex = index;
}
Controls.TabNavigatorSmall.prototype.showNamedTab = function( name )
{
    this.showTab( this.findTabIndex( name ) );
}
Controls.TabNavigatorSmall.prototype.findTabIndex = function( name )
{
    for ( var i=0; i<this.tabs.length; i++ )
        if ( this.tabs[i].name == name )
            return i;
    return -1;
}
Controls.TabNavigatorSmall.prototype.getItemByIndex = function( index )
{
    return this.tabs[index].item;
}
Controls.TabNavigatorSmall.prototype.getSelectedIndex = function()
{
    return this.selectedIndex;
}