 //
// SubNav class
//
function SubNav (parent, id )
{
	var xaml = "<Canvas xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='subnav_" + id + "' Canvas.Left='-1000' Canvas.Top='0' Opacity='0'/>";
	var inst = agControl.content.createFromXaml (xaml );
	parent.children.add (inst );
}
//
// SubNavButton class
//
function SubNavButton (parent, parentID, _data, _format )
{
	var no = _data.no;
	var onOpacity = "1.0";
	var offOpacity = "0.7";
	var animDur = "0:0:0.05";
	var dotAnimDur = "0:0:0.3";
	var dotX = (_data.x + (_data.wOn / 2 )) - 7;
	var labelOffX = (_data.wOn - _data.wOff ) / 2;
	// create the label
	var xaml = "<Canvas xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='subnavbtn_" + parentID + "_" + no + "' Canvas.Left='" + _data.x + "' Canvas.Top='" + _data.y + "' Width='" + _data.w + "' Height='" + _data.h + "' RenderTransformOrigin='0.5,1.0'>";
	xaml += "<Canvas.Resources>";
	xaml += "<Storyboard x:Name='dot_subnavbtn_" + parentID + "_" + no + "_sb' Completed='reportx'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnav_dot_x' Storyboard.TargetProperty='X'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + dotAnimDur + "' Value='" + dotX + "' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "<Storyboard x:Name='subnavbtn_" + parentID + "_" + no + "_over_sb'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnavbtn_" + parentID + "_" + no + "' Storyboard.TargetProperty='(UIElement.Opacity)'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + animDur + "' Value='" + onOpacity + "' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "<Storyboard x:Name='subnavbtn_" + parentID + "_" + no + "_out_sb'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnavbtn_" + parentID + "_" + no + "' Storyboard.TargetProperty='(UIElement.Opacity)'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + animDur + "' Value='" + offOpacity + "' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "<Storyboard x:Name='subnavbtn_" + parentID + "_" + no + "_label_on_active_sb'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnavbtn_" + parentID + "_label_on_" + no + "' Storyboard.TargetProperty='(UIElement.Opacity)'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + animDur + "' Value='1.0' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "<Storyboard x:Name='subnavbtn_" + parentID + "_" + no + "_label_on_disable_sb'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnavbtn_" + parentID + "_label_on_" + no + "' Storyboard.TargetProperty='(UIElement.Opacity)'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + animDur + "' Value='0' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "<Storyboard x:Name='subnavbtn_" + parentID + "_" + no + "_label_off_active_sb'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnavbtn_" + parentID + "_label_off_" + no + "' Storyboard.TargetProperty='(UIElement.Opacity)'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + animDur + "' Value='1.0' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "<Storyboard x:Name='subnavbtn_" + parentID + "_" + no + "_label_off_disable_sb'>";
	xaml += "<DoubleAnimationUsingKeyFrames Storyboard.TargetName='subnavbtn_" + parentID + "_label_off_" + no + "' Storyboard.TargetProperty='(UIElement.Opacity)'>";
	xaml += "<SplineDoubleKeyFrame KeySpline='0.5,0.5,0.5,1' KeyTime='" + animDur + "' Value='0' />";
	xaml += "</DoubleAnimationUsingKeyFrames>";
	xaml += "</Storyboard>";
	xaml += "</Canvas.Resources>";
	xaml += "<Glyphs x:Name='subnavbtn_" + parentID + "_label_on_" + no + "' Canvas.Left='0' Canvas.Top='0' Fill='" + _format.fontColor + "' FontUri='assets/fonts/" + _format.fontNameOn + "' FontRenderingEmSize='" + _format.fontSize + "' UnicodeString='" + _data.label + "' Opacity='0' />";
	xaml += "<Glyphs x:Name='subnavbtn_" + parentID + "_label_off_" + no + "' Canvas.Left='" + labelOffX + "' Canvas.Top='0' Fill='" + _format.fontColor + "' FontUri='assets/fonts/" + _format.fontNameOff + "' FontRenderingEmSize='" + _format.fontSize + "' UnicodeString='" + _data.label + "' Opacity='" + offOpacity + "' />";
	xaml += "</Canvas>";
	var inst = agControl.content.createFromXaml (xaml );
	parent.children.add (inst );
	inst.addEventListener ("mouseEnter", this.over );
	inst.addEventListener ("mouseLeave", this.out );
	inst.addEventListener ("mouseLeftButtonUp", this.release );
}
// rollover
SubNavButton.prototype.over = SubNavButtonOver = function (sender )
{
	tempSender = sender.Name.split ("_");
	if (PAGE_NO != tempSender [2])
	{
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_over_sb" ).begin ();
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_label_on_disable_sb" ).begin ();
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_label_off_active_sb" ).begin ();
	}
}
// rollout
SubNavButton.prototype.out = SubNavButtonOut = function (sender )
{
	tempSender = sender.Name.split ("_");
	if (PAGE_NO != tempSender [2])
	{
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_out_sb" ).begin ();
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_label_on_disable_sb" ).begin ();
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_label_off_active_sb" ).begin ();
	}
}
// press
SubNavButton.prototype.down = SubNavButtonDown = function (sender )
{
}
// release
SubNavButton.prototype.release = SubNavButtonRelease = function (sender, args )
{
	tempSender = sender.Name.split ("_");
	if (PAGE_NO != tempSender [2])
	{
		var prev = PAGE_NO;
		PAGE_NO = tempSender [2];
		
		
		appNavigator.setHTMLFile(SECTION_NO + "_" + PAGE_NO);
		
		// activate this btn
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_over_sb" ).begin ();
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_label_on_active_sb" ).begin ();
		agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_label_off_disable_sb" ).begin ();
		agControl.content.findName ("dot_subnavbtn_" + tempSender [1] + "_" + tempSender [2] + "_sb" ).begin ();
		// notify the navigator
		//appNavigator.setLocation (SECTION_NO + "_" + tempSender [2]);
		if (prev)
		{
			// rollout prev btn
			var prevBtn = agControl.content.findName ("subnavbtn_" + tempSender [1] + "_" + prev);
			SubNavButtonOut (prevBtn );
		}
	}
}
