<?xml version="1.0"?>
<!-- This demo demonstrates some of the capabilities of the Bindows animation library.
     Moving the mouse over the top buttons causes the thumbnail of the components on the
     left side to pulsate. Clicking on the same buttons expands the components and move
     them into the work area. The speed can be adjusted with the slider on the right side.
     The ticker speed can also be controlled by the slider, located above it. The current
     frame number is displayed by listeneing to a frameprogression event. When the ticker
     animation is fully displayed - the text "animation end" is displayed and then fades out.
     The ticker animation can be paused, started and rewinded with two small buttons next to it.
     Finally, when you move the mouse over the logo it blinks for few times. -->

<Application autoNameMapping="true">
	<Window caption="AnimationTest1" width="400" height="400" centered="true" resizable="false">
        <!--Genereric pulse-->
        <OpacityAnimator id="oa" autoStart="true" type="pulsate" speed="fast"/>

        <!--Work area-->
        <Component left="70" right="70" top="70" bottom="70" border="2 dashed" backColor="Gainsboro" opacity="0.5"/>

        <!--Button and thumbnail area background-->
        <Component top="0" height="40" left="0" right="0" backColor="teal" opacity="0.2"/>
        <Image id="logo" uri="bindows.gif" top="5" right="5" width="30" height="30" onmouseover="onMouseOverImage()"/>

        <!--Calendar Code-->
        <Button id="btn1" top="5" left="5" text="Calendar" onclick="onToggleCalendar()" onmouseover="onMouseOverCalendar()" onmouseout="onMouseOutCalendar()"/>
        <Calendar id="cal" width="50" height="50" top="70" left="5" showMonthButtons="false" showYearButtons="false" showCaption="false" opacity="0.5"/>

        <!--To do list-->
        <Button id="btn2" top="5" text="Todo List" left="80" onclick="onTodo()" onmouseover="onMouseOverTodo()" onmouseout="onMouseOutTodo()"/>
        <Component id="todo" left="5" top="140" width="50" height="50" border="1 inset" opacity="0.5">
            <VBox top="0" bottom="0" left="0" right="0">
                <Label text="ToDo" VBox.flex="1"/>
                <List id="todoList" top="15" overflow="hidden" VBox.flex="20">
                    <ListItem text="walk the dog"/>
                    <ListItem text="feed the cat"/>
                </List>
            </VBox>
        </Component>

        <!--Notes-->
        <Button id="btn3" text="Notes" left="155" top="5" onclick="onToggleNotes()" onmouseover="onMouseOverNotes()" onmouseout="onMouseOutNotes()"/>
        <TextArea id="notes" text="Notes" left="5" top="210" width="50" height="50" opacity="0.5"/>

        <!--Ticker area-->
        <Label top="322" left="5" text="Ticker speed"/>
        <Slider top="320" left="80" id="tsSlider" minimum="100" maximum="10000" orientation="horizontal" value="4000" unitIncrement="100" onchange="onTickerSpeedSlider()"/>
        <Label top="322" right="80" id="tickerVal" text="4000"/>

        <Label id="lblFrame" top="305" right="10"/>                                  <!-- fps counter -->
        <Label id="lblEnd" top="309" left="5" text="animation end" opacity="0.0"/>   <!-- ligthts up on ticker anim end -->

        <Button id="btnPause" text="||" top="322" right="5" onclick="onPause()"/>
        <Button html="&lt;&lt;" top="322" right="25" onclick="onRewind()"/>

        <Component top="342" bottom="0" left="0" right="0" backColor="silver" opacity="0.3"/>
        <Component top="346" bottom="0" left="0" right="0" backColor="silver" opacity="0.4"/>
        <Component top="350" bottom="0" left="0" right="0" backColor="silver" opacity="0.7"/>
        <Label id="ticker" text="Informational ticker" animation="#tickerAnim"/>
        <LocationAnimator id="tickerAnim" fromX="-100" fromY="354" toX="400" toY="354" autoStart="true" looping="true" speed="slow"/>

        <!--Speed slider for the boxes-->
        <Label text="Anim Speed" top="70" left="335"/>
        <Slider id="animSlider" orientation="vertical" top="88" left="351" width="22" bottom="80" minimum="100" maximum="1500" unitIncrement="10" value="500" onchange="onAnimSpeedSlider()"/>
        <Label id="animVal" text="500" bottom="65" left="353"/>
    </Window>

	<Resources>
		<Package name="Animation"/>

        <Script><![CDATA[

    _p = AnimationTest1.prototype;

    ////////// Calendar code //////////
    function onToggleCalendar() {
        if(AnimationTest1.calendarShowing) {                   // Close
            AnimationTest1.calLa.setFromTo(73,73,5,70);
            AnimationTest1.calLa.rewind();
            AnimationTest1.calSa.setFromTo(249,226,50,50);
//            AnimationTest1.calSa.setFromTo(249,249,50,50);
            AnimationTest1.calSa.rewind();
            cal.setOpacity(0.5);
            AnimationTest1.calSa.start();
            AnimationTest1.calLa.start();
            AnimationTest1.calendarShowing = false;
        } else {                                            // Open
            if(AnimationTest1.todoShowing || AnimationTest1.notesShowing) return;
            AnimationTest1.calLa.setFromTo(5,70,73,73);
            AnimationTest1.calLa.rewind();
            AnimationTest1.calSa.setFromTo(50,50, 249,226);
//            AnimationTest1.calSa.setFromTo(50,50, 249,249);
            AnimationTest1.calSa.rewind();
            cal.setOpacity(1.0);
            AnimationTest1.calLa.start();
            AnimationTest1.calSa.start();
            AnimationTest1.calendarShowing = true;
        }
    }

    function onMouseOverCalendar() {
        oa.addComponent(cal);
    }

    function onMouseOutCalendar() {
        btn1.setOpacity(1.0);   // Go back to full opacity
        oa.removeComponent(cal);
        if(AnimationTest1.calendarShowing)
            cal.setOpacity(1.0);
        else
            cal.setOpacity(0.5);
    }

    //////// The To Do List /////////
    function onTodo() {
        if(AnimationTest1.todoShowing) {                   // Close todo
            AnimationTest1.todoLa.setFromTo(73,73,5,140);
            AnimationTest1.todoLa.rewind();
            AnimationTest1.todoSa.setFromTo(249,226,50,50);
            AnimationTest1.todoSa.rewind();
            todo.setOpacity(0.5);
            AnimationTest1.todoSa.start();
            AnimationTest1.todoLa.start();
            AnimationTest1.todoShowing = false;
        } else {                                            // Open todo
            if(AnimationTest1.calendarShowing || AnimationTest1.notesShowing) return;
            AnimationTest1.todoLa.setFromTo(5,140,73,73);
            AnimationTest1.todoLa.rewind();
            AnimationTest1.todoSa.setFromTo(50,50,249,226);
            AnimationTest1.todoSa.rewind();
            todo.setOpacity(1.0);
            AnimationTest1.todoLa.start();
            AnimationTest1.todoSa.start();
            AnimationTest1.todoShowing = true;
        }
    }

    function onMouseOverTodo() {
        oa.addComponent(todo);
    }

    function onMouseOutTodo() {
        btn2.setOpacity(1.0);       // Go back to full opacity
        oa.removeComponent(todo);
        if(AnimationTest1.todoShowing)
            todo.setOpacity(1.0);
        else
            todo.setOpacity(0.5);
    }

    //////// Notes /////////
    function onToggleNotes() {
        if(AnimationTest1.notesShowing) {                   // Close
            AnimationTest1.notesLa.setFromTo(73,73,5,210);
            AnimationTest1.notesLa.rewind();
            AnimationTest1.notesSa.setFromTo(249,226,50,50);
            AnimationTest1.notesSa.rewind();
            notes.setOpacity(0.5);
            AnimationTest1.notesSa.start();
            AnimationTest1.notesLa.start();
            AnimationTest1.notesShowing = false;
        } else {                                            // Open
            if(AnimationTest1.calendarShowing || AnimationTest1.todoShowing) return;
            AnimationTest1.notesLa.setFromTo(5,210,73,73);
            AnimationTest1.notesLa.rewind();
            AnimationTest1.notesSa.setFromTo(50,50,249,226);
            AnimationTest1.notesSa.rewind();
            notes.setOpacity(1.0);
            AnimationTest1.notesLa.start();
            AnimationTest1.notesSa.start();
            AnimationTest1.notesShowing = true;
        }

    }

    function onMouseOverNotes() {
        oa.addComponent(notes);
    }

    function onMouseOutNotes() {
        oa.removeComponent(btn3);   // Stop button pulsate
        btn3.setOpacity(1.0);       // Go back to full opacity
        oa.removeComponent(notes);
        if(AnimationTest1.notesShowing)
            notes.setOpacity(1.0);
        else
            notes.setOpacity(0.5);
    }

    function onMouseOverImage() {
        BiOpacityAnimator.createLimitedBlink(logo, null, null, 4); // Make notes blink
    }

    function onTickerSpeedSlider() {
        var speed = tsSlider.getValue();
        speed = Math.abs(speed-10000) + 100;
        tickerVal.setText(speed);
        tickerAnim.setSpeed(speed);
    }

    function onPause() {
        if(AnimationTest1.tickerRunning) {
            tickerAnim.stop();
            AnimationTest1.tickerRunning = false;
            btnPause.setText(">");
        } else {
            tickerAnim.start();
            AnimationTest1.tickerRunning = true;
            btnPause.setText("||");
        }
    }

    function onRewind() {
        tickerAnim.rewind();
    }

    function onAnimSpeedSlider() {
        var speed = animSlider.getValue();
        animVal.setText(speed);
        AnimationTest1.calLa.setSpeed(speed);
        AnimationTest1.calSa.setSpeed(speed);
        AnimationTest1.todoLa.setSpeed(speed);
        AnimationTest1.todoSa.setSpeed(speed);
        AnimationTest1.notesLa.setSpeed(speed);
        AnimationTest1.notesSa.setSpeed(speed);
    }

    function showAnimationEnd() {
        AnimationTest1.fader.start();
    }

	// define constructor
	function AnimationTest1() {
        // boolean toggles
        AnimationTest1.calendarShowing = false;
        AnimationTest1.todoShowing     = false;
        AnimationTest1.notesShowing    = false;
        AnimationTest1.tickerRunning   = true;

        // Calendar location animator
        AnimationTest1.calLa = new BiLocationAnimator(null,null,null,null,500,false,BiComponentAnimation.FAST_TO_SLOW, null, 25);
	    AnimationTest1.calLa.addComponent(cal);

	    // Calendar size animator
	    AnimationTest1.calSa = new BiSizeAnimator(null,null,null,null, 500,false,BiComponentAnimation.FAST_TO_SLOW, null, 25);
	    AnimationTest1.calSa.addComponent(cal);

        // Todo location animator
        AnimationTest1.todoLa = new BiLocationAnimator(5,70,73,73,500,false,BiComponentAnimation.FAST_TO_SLOW, null, null);
	    AnimationTest1.todoLa.addComponent(todo);

	    // Todo size animator
	    AnimationTest1.todoSa = new BiSizeAnimator(50,50,249,226, 500,false,BiComponentAnimation.FAST_TO_SLOW, null, null);
	    AnimationTest1.todoSa.addComponent(todo);

        // Notes location animator
        AnimationTest1.notesLa = new BiLocationAnimator(5,70,73,73,500,false,BiComponentAnimation.FAST_TO_SLOW, null, null);
	    AnimationTest1.notesLa.addComponent(notes);

	    // Notes size animator
	    AnimationTest1.notesSa = new BiSizeAnimator(50,50,249,226, 500,false,BiComponentAnimation.FAST_TO_SLOW, null, null);
	    AnimationTest1.notesSa.addComponent(notes);

	    tickerAnim.addEventListener("animationend", function() {
	        showAnimationEnd();
	    });

	    tickerAnim.addEventListener("frameprogression", function(e) {
	        lblFrame.setText(e.getFPSGenerator().getCurrentFrame());
	    });

	    AnimationTest1.fader = new BiOpacityAnimator(0.0, 1000, null, BiComponentAnimation.SLOW_TO_FAST, lblEnd, null, false, null, false);
	    AnimationTest1.fader.addEventListener("animationend", function() {
            lblEnd.setOpacity(0.0);
            AnimationTest1.fader.stop();
	        AnimationTest1.fader.rewind();
	    });
    }

	// define static main method
	AnimationTest1.main = function() {
		new AnimationTest1();
	}


		]]></Script>
	</Resources>
</Application>