﻿// -----------------------------------------
// TOGGLE BUTTON CLASS
// -----------------------------------------
ToggleButton = function(control, name, nameON, nameOFF, scopeFunctions, clickFunctionON, clickFunctionOFF, isDefault, isLocked) 
{
    this.control = control;
    this.name = name;
	this.scopeFunctions = scopeFunctions;
	this.isLocked = isLocked;
    
    this.clickFunctionON = clickFunctionON;
    this.clickFunctionOFF = clickFunctionOFF;
    
	this.target = control.content.findName(this.name);
	
	this.buttonON = new Button(this.control, nameON);
	this.buttonOFF = new Button(this.control, nameOFF);
	this.targetOn = control.content.findName(nameON);
	this.targetOff = control.content.findName(nameOFF);
	
	this.target.AddEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.checkToggle));
	
	if (isDefault) this.toggle();
	
}

ToggleButton.prototype =
{
	checkToggle: function(sender, e)
    {
        if (this.targetOff.Visibility == "Visible")
        {	
            this.toggle();
        } else {
			if (!this.isLocked)
			{
	            this.unToggle();
			}
        }
    },
	
	toggle: function()
	{
		this.targetOff.Visibility = "Collapsed";
        this.targetOn.Visibility = "Visible";
        if (this.clickFunctionON != null) this.clickFunctionON(this.scopeFunctions);
	},
	
	unToggle: function()
	{
		this.targetOn.Visibility = "Collapsed";
	    this.targetOff.Visibility = "Visible";
		this.buttonOFF.reset();
	    if (this.clickFunctionOFF != null) this.clickFunctionOFF(this.scopeFunctions);
	}
}


