﻿function AdvBtn (control,namePrefix,IsMultiState,HasInOutEffect,actionFunc,getBtnStatusFunc)
{   
    this.control = control;
	this.prefix=namePrefix;
	this.btnName=namePrefix+"_Btn";
    this.target = this.control.content.findName(this.btnName);
	
    this.toggled=false;
    this.target.Cursor = "Hand";
	this.multiState=IsMultiState;
	this.hasInOutEffect=HasInOutEffect;
	this.actionFunc=actionFunc;
	this._media=this.control.content.findName("media");

	this.getBtnStatusFunc=getBtnStatusFunc;
	this.alphaDefaultEndPos="Bottom";
	this.alphaDefaultMovDirec="ToLeft";
	//hookEvent(this.mlSB,"Completed",Function.createDelegate(this, this.updateButton));
    //hookEvent(this.target, "MouseLeftButtonUp", Function.createDelegate(this, this.handleToggleMouseUp));

	this.target.addEventListener( "MouseLeftButtonUp",Function.createDelegate(this, this.handleToggleMouseUp));
	if (this.hasInOutEffect)
	{
		this.mlSB=this.control.content.findName(this.btnName+"_MouseLeave");
		this.mlSB.addEventListener("Completed",Function.createDelegate(this, this.updateButton));	

		hookEvent(this.target, "MouseEnter", Function.createDelegate(this, this.handleMouseEnter));
		hookEvent(this.target, "MouseLeave", Function.createDelegate(this, this.handleMouseLeave));
	}
	this.updateButton();
}
AdvBtn.prototype.handleToggleMouseUp = function(sender, eventArgs)
{	
	//just for functionality, not related to storyboard effect or updating multi-state symbols .
	if (this.actionFunc)
		this.actionFunc();
	this.toggled=!this.toggled;

	this.updateButton();

}
AdvBtn.prototype.updateButton=function(sender, eventArgs)
{	
	//updateBtn(this.control,this.target,this.toggled);
	if (this.getBtnStatusFunc)
		{ 
		this.toggled=this.getBtnStatusFunc();
		}
	if (this.multiState){
		
		var onSymb=this.control.content.findName(this.btnName+"_OnSymbol");
		var offSymb=this.control.content.findName(this.btnName+"_OffSymbol");
		//var onStoryBoard=this.control.content.findName(this.btnName+"_OnSB");
		if (onSymb) 
		{	
			//onSymb.Visibility=this.toggled?"Visible":"Collapsed";
			onSymb.Opacity=this.toggled?1:0;
		}
		if (offSymb) {
			//offSymb.Visibility=this.toggled?"Collapsed":"Visible";
			offSymb.Opacity=this.toggled?0:1;
		}
	}
}
AdvBtn.prototype.handleMouseEnter = function(sender, eventArgs)
{	
		var meSB=this.control.content.findName(this.btnName+"_MouseEnter");
		meSB.begin();
		

}
AdvBtn.prototype.handleMouseLeave = function(sender, eventArgs)
{	
	this.mlSB.begin();
}
AdvBtn.prototype.setToggleStatus=function(flag)
{
	
	this.toggled=flag;
}

