<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" backgroundColor="0xCCCCCC" viewSourceURL="srcview/index.html">

    <!--
    beta1開発メモ:
        ・日本語フォントはfontFamilyを指定しないと文字下部部がきれてしまう。
        ・HTTPにリクエストする場合、「&」は「&amp;」を使用する。
        ・XMLにnamespaceがある場合、E4Xでは正常に値が取り出せないのでデフォルトのnamespaceを指定する or namespace::でアクセスする
        ・アプリケーションの width、height、backgroundColor、backgroundImage の設定を変更して実行しても変更が反映されない場合、
        メニューバーから [プロジェクト]-[Clean] を選択する。(HTML ラッパーが正しく書き換えられていることを確認)
    -->
    <!--
    beta2への変更点:
        ・xmlns:mx="http://www.macromedia.com/2005/mxml" → xmlns:mx="http://www.adobe.com/2006/mxml"
        ・listItemRenderer → itemRenderer
        ・marginLeft → paddingLeft
        ・marginRight → paddingRight
        ・<mx:SetProperty>のproperty → name
        ・dataObject → data
    -->
    
    <!--HTTPサービス サムネイル用-->
    <mx:HTTPService id="itemSearchSrv" url="http://webservices.amazon.co.jp/onca/xml" useProxy="false"
        result="itemSearchResultHandler(event)" 
        fault="requestFaultHandler(event)" 
        showBusyCursor="true" resultFormat = "e4x"/>
    <!--HTTPサービス 詳細取得用-->
    <mx:HTTPService id="itemDetailsSrv" url="http://webservices.amazon.co.jp/onca/xml" useProxy="false" 
        result="showItemDetailsResultHandler(event)" 
        fault="requestFaultHandler(event)" 
        showBusyCursor="true" resultFormat = "e4x"/>
    
    
    <!--ツールチップのスタイル設定-->
    <mx:Style>
        ToolTip { 
            fontFamily: "_ゴシック"; 
            fontSize: 12; 
            backgroundColor: #FFCCCC;
        }
    </mx:Style>


    <!--レイアウト-->
    <mx:HBox x="10" y="10">
    
        <!--左側検索パネル-->
        <mx:VBox id="vboxLeft">
            <mx:Panel width="220" height="120" layout="absolute" title="商品検索" id="searchPanel" cornerRadius="8" fontSize="12" fontFamily="_ゴシック">
                <mx:Label x="10" y="10" text="サーチ:" id="keywordLabel" fontFamily="_ゴシック" fontSize="10"/>
                <mx:TextInput x="45" y="10" width="145" id="searchText" text="Amazon" fontSize="10" fontFamily="_ゴシック"></mx:TextInput>
                
                <!--コンボボックスにデータ登録 dataProvider用にArrayCollectionへ-->
                <mx:ComboBox x="10" y="50" width="120" id="categoryCombobox" fontFamily="_ゴシック">
                    <mx:dataProvider>
                        <mx:ArrayCollection>
                            <mx:source>
                                <mx:Object label="" data="Books"/>
                                <mx:Object label="ミュージック" data="Music"/>
                                <mx:Object label="ソフトウェア" data="Software"/>
                                <mx:Object label="DVD" data="DVD"/>
                            </mx:source>
                        </mx:ArrayCollection>
                    </mx:dataProvider>
                </mx:ComboBox>
                <!--ボタンクリックで検索&検索結果ステートへ-->
                <mx:Button x="140" y="50" id="searchButton" label="検索" fontFamily="_ゴシック" click="itemSearch(),currentState='searchResultState'"></mx:Button>
                <mx:ControlBar height="10" id="searchPanelControlBar"></mx:ControlBar>
            </mx:Panel>
        </mx:VBox>
        
        <mx:Spacer/>
        
        
        <!--右側検索結果パネル-->
        <mx:Panel id="resultPanel" width="600" height="370" cornerRadius="8" backgroundColor="#FFFFFF" fontFamily="_ゴシック" fontSize="12" visible="false" showEffect="Fade" title="検索結果" verticalScrollPolicy="off">
            <mx:VBox width="100%" id="vboxRight">
            
                <!--検索結果サムネイル thumbnailCollectionの値が変化するとTileList表示内容も同じように変化する
                itemClickで詳細表示・履歴登録 ドロップ可能-->
                <mx:TileList id="itemThumbnailList" dataProvider="{thumbnailCollection}" 
                    x="0" y="0" width="100%" height="290" columnCount="5" 
                    itemClick="getItemDetails(),setHistoryFromThumbnail(),currentState='moveItemListState'" 
                    dragEnabled="true" 
                    backgroundColor="#ffffff" selectionColor="0xFFCC66" rollOverColor="0xFFFF99">
                    
                    <!--カスタムitemRendererを設定-->
                    <mx:itemRenderer>
                        <mx:Component>
                            <!--VBoxにツールチップ表示-->
                            <mx:VBox height="140" horizontalAlign="center" toolTip="{data.TitleName}" borderColor="0xCCCCCC" borderStyle="inset">
                                <mx:Image id="itemImage" source="{data.imageURL}"  height="70" horizontalAlign="center" verticalAlign="middle"/>
                                <mx:Text id="itemTitle" height="30" width="100" text="{data.TitleName}" 
                                    fontFamily="_ゴシック" fontSize="12" textAlign="left" selectable="false"/>
                                <mx:Label id="itemPrice" width="100" text="{data.PriceAmount}" fontFamily="_ゴシック" fontSize="12"/>
                            </mx:VBox>
                        </mx:Component>
                    </mx:itemRenderer>
                        
                </mx:TileList>
            </mx:VBox>
            <mx:ControlBar id="resultPanelControlBar" height="50"></mx:ControlBar>
            
        </mx:Panel>
        
    </mx:HBox>
    
    
    
    <!--ステート-->
    <mx:states>
        <!--●検索結果表示ステート-->
        <mx:State name="searchResultState">
        
            <!--検索パネルリサイズ-->
            <mx:SetProperty target="{searchPanel}" name="height" value="180"/>
            
            <!--検索結果情報表示-->
            <mx:AddChild target="{searchPanelControlBar}" position="before">
                <mx:Label x="19" y="86" text="検索結果:" id="totalResultLabel" fontSize="12" fontFamily="_ゴシック"/>
            </mx:AddChild>
            <mx:AddChild target="{searchPanelControlBar}" position="before">
                <mx:Label x="14" y="112" text="総ページ数:" id="totalPageLabel" fontSize="12" fontFamily="_ゴシック"/>
            </mx:AddChild>
            <mx:AddChild target="{searchPanelControlBar}" position="before">
                <mx:TextArea id="searchTotal" text="{itemSearchSrv.result.Items.TotalResults}" x="86" y="85" height="20" 
                    fontFamily="_ゴシック" fontSize="12" width="60" textAlign="right" editable="false"/>
            </mx:AddChild>
            <mx:AddChild target="{searchPanelControlBar}" position="before">
                <mx:TextArea id="pageTotal" text="{itemSearchSrv.result.Items.TotalPages}" x="86" y="111" 
                    fontFamily="_ゴシック" fontSize="12" height="20" width="60" textAlign="right" editable="false"/>
            </mx:AddChild>
            <mx:AddChild target="{searchPanelControlBar}" position="before">
                <mx:Label x="148" y="88" text="" fontFamily="_ゴシック" fontSize="12"/>
            </mx:AddChild>
            <mx:AddChild target="{searchPanelControlBar}" position="before">
                <mx:Label x="148" y="113" text="ページ" fontFamily="_ゴシック" fontSize="12"/>
            </mx:AddChild>
            
            
            <!--検索結果パネルのvisibleをtrueに-->
            <mx:SetProperty target="{resultPanel}" name="visible" value="true"/>
            
            <!--検索結果パネル コントロールバーにページングボタン配置-->
            <mx:AddChild target="{resultPanelControlBar}" position="lastChild">
                <mx:Button label="次へ&gt;&gt;" id="nextPageButton" click="pageSearch(1)" fontFamily="_ゴシック" fontSize="12"/>
            </mx:AddChild>
            <mx:AddChild target="{nextPageButton}" position="before">
                <mx:Button label="&lt;&lt;前へ" fontFamily="_ゴシック" fontSize="12" click="pageSearch(-1)" id="backButton"/>
            </mx:AddChild>
            
        </mx:State>
    
    
        <!--●アイテム詳細表示ステート-->
        <mx:State name="showItemDetailsState" basedOn="searchResultState">
        
            <!--お気に入り・表示履歴パネル-->
            <mx:AddChild target="{vboxLeft}" position="lastChild">
                <mx:Panel id="favoriteAndHistoryPanel" width="220" height="485"  cornerRadius="8" title="お気に入り・表示履歴" fontFamily="_ゴシック" fontSize="12" >
                    
                    <mx:Accordion id="accordionSet" height="100%" openDuration="800">
                    
                        <mx:Canvas label="お気に入り" width="100%" height="100%">
                            <!--お気に入りリスト ドロップ可能 ドロップでfavoriteCollectionにデータが入る-->
                            <mx:List id="favoriteList" dataProvider="{favoriteCollection}" labelField="TitleName"  width="198" height="100%"  variableRowHeight="true" wordWrap="true" itemClick="getItemDetailsFromfavorite(),setHistoryFromFavorite()" dropEnabled="true">
                            </mx:List>
                        </mx:Canvas>
                        <mx:Canvas label="表示履歴" width="100%" height="100%">
                            <!--表示履歴リスト historyCollectionの値が変化するとList表示内容も同じように変化する-->
                            <mx:List id="histotyList" dataProvider="{historyCollection}" labelField="TitleName"  width="198" height="100%" variableRowHeight="true" wordWrap="true" itemClick="getItemDetailsFromHistory()">
                            </mx:List>
                        </mx:Canvas>
                        
                    </mx:Accordion>
                    
                </mx:Panel>
            </mx:AddChild>
        
            <!--検索結果パネルとvBoxのリサイズ-->
            <mx:SetProperty target="{resultPanel}" name="height" value="670"/>
            <mx:SetProperty target="{vboxRight}" name="height" value="590"/>
            
            
            <!--商品詳細-->
            <mx:AddChild target="{itemThumbnailList}" position="before">
                <mx:Canvas id="detailCanvas" width="100%" height="100%" >
                    <mx:HBox id="itemDetailsBox" height="100%" verticalAlign="middle">
                        <mx:VBox id="detailImageBox" height="200" width="180" verticalAlign="middle" horizontalAlign="center">
                            <!--詳細画像-->
                            <mx:Spacer/>
                            <mx:Image id="detailImage" y="20" width="180" horizontalAlign="center" showBusyCursor="true"/>
                            <mx:Spacer/>
                            <!--アマゾン商品へのリンク-->
                            <mx:Button id="itemLinkButton" label="Amazonの詳細ページへ" textAlign="center" click="gotoAmazon()" />
                        </mx:VBox>
                        <mx:VBox id="detailTextBox" height="100%" width="100%" >
                            <mx:Spacer height="10"/>
                            <!--商品名-->
                            <mx:HBox  width="100%">
                                <mx:Label text="商品名" width="50" fontSize="14" fontFamily="_ゴシック"/>
                                <mx:Text id="titleText" width="300" autoSize="true" fontSize="16" fontFamily="_ゴシック" fontWeight="bold"/>
                            </mx:HBox>
                            <mx:Spacer height="5"/>
                            <!--価格-->
                            <mx:HBox  width="100%">
                                <mx:Label text="価  格" width="50" fontSize="14" fontFamily="_ゴシック"/>
                                <mx:Text id="priceText" width="300" fontSize="16" fontFamily="_ゴシック" fontWeight="bold"/>
                            </mx:HBox>
                            <mx:Spacer height="5"/>
                            <!--商品レビュー-->
                            <mx:TextArea id="reviewText" editable="false"  width="95%" height="160" fontSize="12" fontFamily="_ゴシック" paddingLeft="5" paddingRight="5"/>
                        </mx:VBox>
                    </mx:HBox>    
                    </mx:Canvas>
            </mx:AddChild>
            
            <!--ページングボタンを消し、検索結果に戻るボタンを表示-->
            <mx:RemoveChild child="{backButton}"/>
            <mx:RemoveChild child="{nextPageButton}"/>
            
            <mx:AddChild target="{resultPanelControlBar}" position="lastChild">
                <mx:Button label="検索結果を表示" id="showResultButton" fontFamily="_ゴシック" fontSize="12" click="itemSearch()"/>
            </mx:AddChild>
            
        </mx:State>
        
        <!--●TileList移動用ステート-->
        <mx:State name="moveItemListState" basedOn="showItemDetailsState" enterState="currentState=('showItemDetailsState')">
            
            <!--TileList移動-->
            <mx:SetProperty target="{itemThumbnailList}" name="y" value="400"/>
            
            <!--stateに詳細表示はいらない-->
            <mx:RemoveChild child="{detailCanvas}"/>
            <!--空いたスペースにspacer-->
            <mx:AddChild target="{itemThumbnailList}" position="before">
                <mx:Spacer height="290" width="100%"/>
            </mx:AddChild>

        </mx:State>
        
    </mx:states>
    
    
    
    
    <!--Fadeのduration変更-->
    <!--
    <mx:Fade id="Fade" duration="400"/>
    -->
    
    <!--トランジション-->
    <mx:transitions>
        <!--検索件数パネルのリサイズ-->
        <mx:Transition id="searchTransition" fromState="*" toState="searchResultState">
            <!-- 順番に再生される複数のエフェクトを組み合わせる Sequenceタグ -->
            <!-- 
            <mx:Sequence id="searchParallel" targets="{[searchPanel]}">
                <mx:Move duration="400" />
                <mx:Resize duration="800" />
            </mx:Sequence>
            -->
            <mx:Resize target="{searchPanel}" duration="800" />
        </mx:Transition>
        
        <!--サムネイルの下ムーブ-->
        <mx:Transition id="moveDownTransition" fromState="searchResultState" toState="moveItemListState">
            <!-- 同時に再生される複数のエフェクトを組み合わせる Parallelタグ -->
            <!-- 
            <mx:Parallel id="moveDownItemParallel" targets="{[itemThumbnailList]}" effectEnd="currentState=('showItemDetailsState')">
                <mx:Move  duration="600" />
                <mx:Resize duration="800" />
            </mx:Parallel>
            -->
            <mx:Move target="{itemThumbnailList}" duration="800" />
        </mx:Transition>
    </mx:transitions>
    
    
    
    <!--ActionScript-->
    <mx:Script>
        <![CDATA[
        //CDATA以下を外部ASファイルにしてincludeしても同様

        //include "amazonAccordionView.as";

            
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;
            import mx.collections.ArrayCollection;
            
            
            //======================定数======================

            //ECSサービス

            private var _ECS_SERVICE:String="AWSECommerceService";
            //アマゾンのECSアカウント ●●AWSに登録し、取得した登録ID(Subscription ID)を設定する必要があります。●●

            private var _AWS_ACCESS_KEY_ID:String="[取得した登録ID(例:0123456789ABCDEFGHI)]";
            //================================================

            //<!--XMLにnamespaceがある場合、E4Xでは正常に値が取り出せないのでデフォルトのnamespaceを指定する-->

            default xml namespace = "http://webservices.amazon.com/AWSECommerceService/2005-10-05";
            
            
            //検索結果か履歴表示のどちらから詳細画面を表示したか

            private var _panelFlag:String="";
            //検索結果では詳細を表示した際にTileListその商品が消えてしまうので、amazonのリンク先を保存しておく

            private var _penalLinkURL:String="";
            
            //TileListに格納するデータを入れるArrayCollection

            //[Bindable]とpublicにすることで (beta2ではpublic以外も可)

            //「Data binding will not be able to detect assignments to」警告がでなくなる

            [Bindable]
            private var thumbnailCollection:ArrayCollection = new ArrayCollection();
            //histotyに格納するデータを入れるArrayCollection

            [Bindable]
            private var historyCollection:ArrayCollection = new ArrayCollection();
            //favoriteに格納するデータを入れるArrayCollection

            [Bindable]
            private var favoriteCollection:ArrayCollection = new ArrayCollection();
            
            //amazon.comのCrossdomain.xml

            Security.loadPolicyFile("http://xml.amazon.com/crossdomain.xml");

            
            //画像Embed 詳細表示用No image画像

            [Embed(source="images/no_image_mm.gif")]
            public var noImage_mm:Class;
            
            //検索結果のページング番号

            private var _paging_number:Number=0;
    
            
        //=====◆◆◆メソッド◆◆◆=============================

        //searchButton検索

        //HTTPServiceのsendパラメータを設定し検索実行

            private function itemSearch():void{
                //ページング・履歴初期化

                _paging_number=1;
                historyCollection.removeAll();
                //

                var operation_str:String="ItemSearch";
                var index_str:String=categoryCombobox.selectedItem.data;
                var keyword_str:String=searchText.text;
                var responseGroup_str:String="Medium";
                var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , 
                                            SearchIndex:index_str , Keywords:keyword_str,ResponseGroup:responseGroup_str};
                itemSearchSrv.send(sendObject);
            }
            
        //searchButtonページング

        //HTTPServiceのsendパラメータを設定し検索実行

            private function pageSearch(inNum:Number):void{
                _paging_number=_paging_number+inNum;
                //1より小さくなった時

                if(_paging_number<1){
                    _paging_number=1;
                }
                //総ページ数より大きくなった時

                if(_paging_number>Number(itemSearchSrv.result.Items.TotalPages)){
                    _paging_number=Number(itemSearchSrv.result.Items.TotalPages);
                }
                //

                var operation_str:String="ItemSearch";
                var index_str:String=categoryCombobox.selectedItem.data;
                var keyword_str:String=searchText.text;
                var responseGroup_str:String="Medium";
                var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , 
                                            SearchIndex:index_str , Keywords:keyword_str,ResponseGroup:responseGroup_str,ItemPage:String(_paging_number)};
                itemSearchSrv.send(sendObject);
            }
            
        //検索結果取得完了

        //取得したXMLから商品名と画像(小)・価格を取り出し、TileList用データに入れる

            private function itemSearchResultHandler(event:ResultEvent):void{
                /*
                trace("◆◆◆◆◆◆◆◆検索結果表示◆◆◆◆◆◆◆◆");
                trace(itemSearchSrv.result);
                trace("◆◆◆◆◆◆◆◆検索結果表示◆◆◆◆◆◆◆◆");
                */
                //

                //検索表示用データ消去

                thumbnailCollection.removeAll();
                //

                var _itemObj:Object=event.result;
                var itemXmlList:XMLList = _itemObj.Items.Item;
                //商品名と画像(小)・価格など必要な情報のみを取り出す

                for(var i:Number=0;i<itemXmlList.length();i++){
                    var currentItemsObj:Object=itemSearchSrv.result.Items.Item[i];
                    var itemAmazonURL:String=currentItemsObj.DetailPageURL;
                    var itemASIN:String=currentItemsObj.ASIN;
                    var itemTitle:String=currentItemsObj.ItemAttributes.Title;
                    var itemSmallImageURL:String=currentItemsObj.SmallImage.URL;
                    var itemPrice:String=currentItemsObj.OfferSummary.LowestNewPrice.FormattedPrice;
                    var itemListPrice:String=currentItemsObj.ItemAttributes.ListPrice.FormattedPrice;
                    //LowestNewPriceが無いときはListPriceを使う

                    if(itemPrice==""){
                        itemPrice=itemListPrice;
                    }
                    /*
                    trace("");
                    trace(itemASIN);
                    trace(itemTitle);
                    trace(itemSmallImageURL);
                    trace(itemPrice);
                    trace("");
                    */
                    //イメージが無いときはローカル画像のパス

                    if(itemSmallImageURL==""){
                        itemSmallImageURL="images/no_image_ss.gif";
                    }
                    //TileList用データをまとめる

                    var itemViewObj:Object={AmazonURL:itemAmazonURL , ASIN:itemASIN , TitleName:itemTitle , imageURL:itemSmallImageURL , PriceAmount:itemPrice};
                    
                    //TileList用データ格納

                    thumbnailCollection.addItem(itemViewObj);
                }
                
            }
            
        //アマゾン商品検索結果取得エラー

            private function requestFaultHandler(event:FaultEvent):void{
                Alert.show(event.fault.faultstring, "Error requesting data");
            }
            
        //アイテム詳細取得

        //HTTPServiceのsendパラメータを設定し詳細取得実行

            private function getItemDetails():void{
                //

                if(itemThumbnailList.selectedItem==null){
                    return;
                }
                _panelFlag="default";
                _penalLinkURL=itemThumbnailList.selectedItem.AmazonURL;
                //サムネイルクリックのアイテムitemIDを取得し、詳細を問い合わせる

                var operation_str:String="ItemLookup";
                var itemId_str:String=itemThumbnailList.selectedItem.ASIN;
                var responseGroup_str:String="Medium,Similarities,Accessories";
                var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , 
                                            ItemId:itemId_str ,ResponseGroup:responseGroup_str};
                itemDetailsSrv.send(sendObject);
            }
            
        //履歴リストに入れる

            private function setHistoryFromThumbnail():void{
                if(itemThumbnailList.selectedItem==null){
                    return;
                }
                var currentItem:Object=itemThumbnailList.selectedItem;
                historyCollection.addItemAt(currentItem,0);
            }
        //お気に入りリストに入れる

            private function setHistoryFromFavorite():void{
                if(favoriteList.selectedItem==null){
                    return;
                }
                var currentItem:Object=favoriteList.selectedItem;
                historyCollection.addItemAt(currentItem,0);
            }
                
        //アイテム詳細取得(履歴から)

        //HTTPServiceのsendパラメータを設定し詳細取得実行

            private function getItemDetailsFromHistory():void{
                if(histotyList.selectedItem==null){
                    return;
                }
                _panelFlag="history";
                //サムネイルクリックのアイテムitemIDを取得し、詳細を問い合わせる

                var operation_str:String="ItemLookup";
                var itemId_str:String=histotyList.selectedItem.ASIN;
                var responseGroup_str:String="Medium,Similarities,Accessories";
                var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , 
                                            ItemId:itemId_str ,ResponseGroup:responseGroup_str};
                itemDetailsSrv.send(sendObject);
            }
        //アイテム詳細取得(お気に入りから)

        //HTTPServiceのsendパラメータを設定し詳細取得実行

            private function getItemDetailsFromfavorite():void{
                if(favoriteList.selectedItem==null){
                    return;
                }
                _panelFlag="favorite";
                //サムネイルクリックのアイテムitemIDを取得し、詳細を問い合わせる

                var operation_str:String="ItemLookup";
                var itemId_str:String=favoriteList.selectedItem.ASIN;
                var responseGroup_str:String="Medium,Similarities,Accessories";
                var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , ItemId:itemId_str ,ResponseGroup:responseGroup_str};
                itemDetailsSrv.send(sendObject);
            }
            
        //アイテム詳細取得

        //取得したXMLを処理する

            private function showItemDetailsResultHandler(event:ResultEvent):void{
                /*
                trace("◆◆◆◆◆◆◆◆詳細取得表示◆◆◆◆◆◆◆◆");
                trace(itemDetailsSrv.result);
                trace("◆◆◆◆◆◆◆◆詳細取得表示◆◆◆◆◆◆◆◆");
                */
                //

                //詳細取得結果

                var _itemObj:Object=event.result;
                var itemMediumImageURL:String = _itemObj.Items.Item.MediumImage.URL;
                var itemEditorialReview:String = _itemObj.Items.Item.EditorialReviews.EditorialReview.Content;
                //関連商品

                // _itemObj.Items.SimilarProducts.SimilarProduct[i].ASIN;

                //_itemObj.Items.SimilarProducts.SimilarProduct[i].Title;

                //アクセサリ

                //_itemObj.Items.Accessories.Accessory[i].ASIN;

                //_itemObj.Items.Accessories.Accessory[i].Title;

                
                //関連商品ASINを取り出す        

                var similarItemXmlList:XMLList = _itemObj.Items.Item.SimilarProducts.SimilarProduct;
                var similarItemListArray:Array=[];
                for( var i:Number=0;i<similarItemXmlList.length();i++ ){
                    var itemSimilarASIN:String=_itemObj.Items.Item.SimilarProducts.SimilarProduct[i].ASIN;
                    similarItemListArray.push(itemSimilarASIN);
                }
                //

                //アクセサリASINを取り出す

                var itemAccessoryItemXmlList:XMLList = _itemObj.Items.Item.Accessories.Accessory;
                var accessoryItemListArray:Array=[];
                for( var i:Number=0;i<itemAccessoryItemXmlList.length();i++ ){
                    var itemAccessoryASIN:String=_itemObj.Items.Item.Accessories.Accessory[i].ASIN;
                    accessoryItemListArray.push(itemAccessoryASIN);
                }
                //関連商品とアクセサリのASIN番号をまとめる

                var getItemArray:Array=similarItemListArray.concat(accessoryItemListArray);
                //一度に送信できるASINの数は10個なので10以上は切り捨て

                getItemArray.splice(10);
                //関連商品orアクセサリがある場合

                if(getItemArray.length>0){
                    itemSimilarSearch(getItemArray);
                }
                
                //詳細画像情報

                //イメージが無いときEmbed画像を使用

                if(itemMediumImageURL==""){
                    detailImage.source=noImage_mm;
                    detailImage.load();
                }else{
                    detailImage.source=itemMediumImageURL;
                    detailImage.load();
                }
                
                //詳細テキスト情報(タイトル・金額)

                if(_panelFlag=="history"){
                    titleText.text=histotyList.selectedItem.TitleName;
                    priceText.text=histotyList.selectedItem.PriceAmount;
                    
                }else if(_panelFlag=="favorite"){
                    titleText.text=favoriteList.selectedItem.TitleName;
                    priceText.text=favoriteList.selectedItem.PriceAmount;
                
                }else if(_panelFlag=="default"){
                    titleText.text=itemThumbnailList.selectedItem.TitleName;
                    priceText.text=itemThumbnailList.selectedItem.PriceAmount;
                }
                
                //レビューが無いとき

                if(itemEditorialReview==""){
                    itemEditorialReview="レビュー情報は含まれていませんでした。";
                }
                //レビューはhtmlテキスト

                reviewText.htmlText=itemEditorialReview;
            }
            
        //関連とアクセサリ商品検索

        //HTTPServiceのsendパラメータを設定し検索実行

            private function itemSimilarSearch(inArray:Array):void{
                var operation_str:String="ItemLookup";
                var idType_str:String="ASIN";
                var itemID_str:String=inArray.toString();
                var responseGroup_str:String="Medium";
                var sendObject:Object = {Service:_ECS_SERVICE ,AWSAccessKeyId:_AWS_ACCESS_KEY_ID , Operation:operation_str , 
                                            IdType:idType_str, ItemId:itemID_str ,ResponseGroup:responseGroup_str};
                itemSearchSrv.send(sendObject);
            }
            
        //アマゾンへのリンク

        private function gotoAmazon():void{
            if(_panelFlag=="history"){
                navigateToURL(new URLRequest(histotyList.selectedItem.AmazonURL));
            }else if(_panelFlag=="favorite"){
                navigateToURL(new URLRequest(favoriteList.selectedItem.AmazonURL));
            }else if(_panelFlag=="default"){
                navigateToURL(new URLRequest(_penalLinkURL));
            }
        }
        
            ]]>
    </mx:Script>
    
</mx:Application>