<!--
  Copyright 2011-2014 Marvell Semiconductor, Inc.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<module xmlns="http://www.kinoma.com/kpr/1">
	<require path="./control" id="CONTROL"/>
	<require path="./dialog" id="DIALOG"/>

	<behavior id="BackBehavior" like="CONTROL.ButtonBehavior"><![CDATA[
		function onTap(container) {
			container.invoke(new Message("/back"));
		}
	]]></behavior>
	<container id="BackButton" width="50" top="0" bottom="0" skin="THEME.backButtonSkin" active="application.behavior.canGoBack()" behavior="BackBehavior">
		<content left="10" width="40" height="40" skin="applicationIconSkin"/>
	</container>
	
	<scroller id="HeaderTitle" left="0" right="0" top="0" bottom="0" clip="true" loop="true" skin="THEME.headerTitleSkin" behavior="CONTROL.HorizontalTickerBehavior">
		<label anchor="TITLE" top="0" bottom="0" string="$.title"/>
	</scroller>

	<behavior id="MenuButtonBehavior" like="CONTROL.ButtonBehavior"><![CDATA[
		function changeState(container, state) {
			CONTROL.ButtonBehavior.prototype.changeState.call(this, container.first, state);
		}
		function onCreate(button, data) {
			CONTROL.ButtonBehavior.prototype.onCreate.call(this, button, data);
			button.first.last.string = data.items[data.selection].title
		}
		function onTap(button) {
			this.data.button = button;
			application.run(new THEME.MenuOpenTransition, new DIALOG.Menu(this.data), button);
		}
	]]></behavior>
	
	<container id="MenuButton" skin="THEME.menuButtonSkin" style="THEME.menuButtonStyle" active="true" behavior="MenuButtonBehavior">
		<line top="0" bottom="0">
			<content width="30" height="30" skin="THEME.menuArrowSkin"/>
			<label top="0" bottom="0"/>
		</line>
	</container>
	
	<container id="NextButton" width="THEME.screenFooterHeight" height="THEME.screenFooterHeight" active="application.behavior.canGoBy(1)" exclusiveTouch="true">
		<behavior like="CONTROL.ButtonBehavior"><![CDATA[
			function onTap(container) {
				application.behavior.doGoBy(1);
			}
		]]></behavior>
		<content skin="THEME.toolSkin" variant="THEME.NEXT"/>
	</container>

	<container id="PreviousButton" width="THEME.screenFooterHeight" height="THEME.screenFooterHeight" active="application.behavior.canGoBy(-1)" exclusiveTouch="true">
		<behavior like="CONTROL.ButtonBehavior"><![CDATA[
			function onTap(container) {
				application.behavior.doGoBy(-1);
			}
		]]></behavior>
		<content skin="THEME.toolSkin" variant="THEME.PREVIOUS"/>
	</container>

	<container id="PreviousMediaButton" width="THEME.screenFooterHeight" height="THEME.screenFooterHeight" active="true" exclusiveTouch="true">
		<behavior like="CONTROL.ButtonBehavior"><![CDATA[
			function onTap(container) {
				var media = this.data.MEDIA;
				if ((media.time < 3000) && application.behavior.canGoBy(-1))
					application.behavior.doGoBy(-1);
				else
					media.time = 0;
			}
		]]></behavior>
		<content skin="THEME.toolSkin" variant="THEME.PREVIOUS"/>
	</container>
	
	<behavior id="SearchBehavior" like="CONTROL.ButtonBehavior"><![CDATA[
		function onTap(container) {
			container.invoke(new Message("/search"));
		}
	]]></behavior>
	<container id="SearchButton" width="50" top="0" bottom="0" skin="THEME.toolButtonSkin" active="true" behavior="SearchBehavior">
		<content skin="THEME.toolSkin" variant="THEME.SEARCH"/>
	</container>

	<container id="ToolButton" width="50" right="0" top="0" bottom="0" skin="THEME.toolButtonSkin" active="true" behavior="CONTROL.ButtonBehavior">
		<content anchor="TOOL" skin="$.skin" variant="$.variant"/>
	</container>
	

</module>
