<?xml version="1.0" encoding="utf-8"?>
<!--
    JXLDownloads2
    
    Created by Jesse R. Warden a.k.a. "JesterXL"
    jesterxl@jessewarden.com
    http://www.jessewarden.com
    http://www.universalmind.com
    
    This is release under a Creative Commons license. 
    More information can be found here:
    
    http://creativecommons.org/licenses/by/2.5/
-->
<mx:Application 
    frameRate="30"
    preloader="com.jxl.downloads.views.JXLDownloadsPreloader"
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" 
    xmlns:views="com.jxl.downloads.views.*" 
    xmlns:business="com.jxl.downloads.business.*" 
    xmlns:controller="com.jxl.downloads.controller.*"
    creationComplete="initApp()" 
    currentState="login_state"
    defaultButton="{login_pb}">
    
    <mx:Script>
        <![CDATA[
            import com.jxl.downloads.callbacks.LoginCallback;
            import com.jxl.downloads.events.LoginEvent;
            import mx.managers.PopUpManager;
            import com.adobe.cairngorm.control.CairngormEventDispatcher;
            
            public function initApp():void
            {
                //DebugWindow.debugHeader();
                //DebugWindow.debug("JXLDownloads2::initApp");
                //PopUpManager.createPopUp(this, DebugWindow, false);
                doLogin();
            }
            
            private function doLogin():void
            {
                var event:LoginEvent = new LoginEvent(LoginEvent.LOGIN, onLogin_Result);
                //event.username = username_ti.text;
                //event.password = password_ti.text;
                event.username = "admin";
                event.password = "mad_cheese";
                CairngormEventDispatcher.getInstance().dispatchEvent(event);
            }
            
            private function onLogin_Result(p_event:LoginCallback):void
            {
                DebugWindow.debugHeader();
                DebugWindow.debug("JXLDownloads2::onLogin_Result");
                currentState = "loggedIn_state";
            }
            
        ]]>
    </mx:Script>
    
    <mx:Style source="index.css" />
    
    <business:Services id="dataServices" />
    <controller:Controller id="controller" />
    
    <mx:states>
        <mx:State name="login_state">
            <mx:AddChild position="lastChild">
                <mx:Panel x="163" y="156" width="311" height="170" layout="absolute" title="Login" 
                    id="login_panel">
                    <mx:Form x="0" y="0">
                        <mx:FormItem label="Username">
                            <mx:TextInput id="username_ti"/>
                        </mx:FormItem>
                        <mx:FormItem label="Password">
                            <mx:TextInput id="password_ti" displayAsPassword="true" />
                        </mx:FormItem>
                        <mx:FormItem>
                            <mx:Button id="login_pb" label="Login" click="doLogin()" />
                        </mx:FormItem>
                    </mx:Form>
                </mx:Panel>
            </mx:AddChild>
        </mx:State>
        <mx:State name="loggedIn_state">
            <mx:AddChild position="lastChild">
                <views:DownloadsPanel currentState="intro_state" />
            </mx:AddChild>
        </mx:State>
    </mx:states>
    
</mx:Application>