if (!isObject(LevelButtonBehavior))
{
   %template = new BehaviorTemplate(LevelButtonBehavior);
   
   %template.friendlyName = "Level Button";
   %template.behaviorType = "GUI";
   %template.description  = "Loads a new level when clicked";

   %template.addBehaviorField(hoverImage, "The image to display when mousing over the object", object, "", t2dImageMapDatablock);
   %template.addBehaviorField(hoverFrame, "The frame of the hoverImage to display", int, 0);
   %template.addBehaviorField(clickImage, "The image to display when clicking on the object", object, "", t2dImageMapDatablock);
   %template.addBehaviorField(clickFrame, "The frame of the clickImage to display", int, 0);
   %template.addBehaviorField(level, "The level to load on mouse up", string, "");
}

function LevelButtonBehavior::onBehaviorAdd(%this)
{
   %this.owner.setUseMouseEvents(true);
   
   %this.startImage = %this.owner.getImageMap();
   %this.startFrame = %this.owner.getFrame();
}

function LevelButtonBehavior::onMouseDown(%this, %modifier, %worldPos)
{
echo("lol");
   if (!isObject(%this.clickImage))
      return;
   
   %this.owner.setImageMap(%this.clickImage, %this.clickFrame);
}

function LevelButtonBehavior::onMouseUp(%this, %modifier, %worldPos)
{
   if (isObject(%this.hoverImage))
      %this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
   else
      %this.owner.setImageMap(%this.startImage, %this.startFrame);
   
   sceneWindow2D.schedule("1","loadLevel",expandFilename( %this.level ) );   
}

function LevelButtonBehavior::onMouseEnter(%this, %modifier, %worldPos)
{
   if (!isObject(%this.hoverImage))
      return;
   
   %this.owner.setImageMap(%this.hoverImage, %this.hoverFrame);
}

function LevelButtonBehavior::onMouseLeave(%this, %modifier, %worldPos)
{
   %this.owner.setImageMap(%this.startImage, %this.startFrame);
}
