<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
				horizontalAlign="center" paddingBottom="10"
				paddingRight="10" paddingLeft="10" paddingTop="10"
				backgroundColor="white" verticalAlign="middle"
				backgroundAlpha="1" width="100%" height="100%">
				
	<mx:Script>
        <![CDATA[
        	import org.pyamf.examples.ohloh.ApiExample;
        	
        	public var account: ApiExample;
        	
        	public function submit():void
        	{
        		submit_btn.enabled = false;
        		
        		account = new ApiExample( email.text );
				account.addEventListener( ApiExample.RESPONSE, showResponse );
				account.addEventListener( ApiExample.ERROR, showError );
				
				account.connect('http://localhost:8000');
        	}
        	
        	private function showResponse( evt:Event ):void
        	{
        		submit_btn.enabled = true;
        		results.visible = true;
        		
        		username.text = account.info.name;
        		avatar.source = account.info.avatar_url;
        		location.text = account.info.location;
        		website.htmlText = "<a href='" + account.info.homepage_url +
								   "'><font color='#1874CD'>" +
								   account.info.homepage_url + "</font></a>";
        	}
        	
        	private function showError( evt:Event ):void
        	{
        		submit_btn.enabled = true;
        		results.visible = false;
        	}
        ]]>
    </mx:Script>  

	<mx:Form>
		<mx:Label text="Ohloh API Example" fontWeight="bold" fontSize="14"
				  paddingBottom="15" width="100%"/>
		<mx:FormItem label="Email Address:">
			<mx:TextInput id="email" text="info@ohloh.net" width="300" textIndent="3"/>
		</mx:FormItem>
		<mx:FormItem>
			<mx:Button id="submit_btn" click="submit()" label="Submit"/>
		</mx:FormItem>
		<mx:FormItem label="Result:" paddingTop="20" id="results" visible="false">
			<mx:Panel title="Ohloh Profile" paddingBottom="20" paddingRight="20"
					  paddingLeft="20" paddingTop="20">
				<mx:HBox width="100%">
					<mx:Image id="avatar"/>
					<mx:VBox paddingTop="0" verticalGap="0" height="100%">
						<mx:Label id="username" fontWeight="bold" fontSize="12"/>
						<mx:Spacer height="100%"/>
						<mx:Label id="location" selectable="true"/>
						<mx:Label id="website" fontWeight="bold"/>
					</mx:VBox>
				</mx:HBox>
			</mx:Panel>
		</mx:FormItem>
	</mx:Form>
	
</mx:Application>