public void Show(string imageUrl, int guiDepth, Action onDoneCallback)
        {
            if (string.IsNullOrEmpty(imageUrl)) return;

            this.imageUrl = imageUrl;

            OnDoneCallback = onDoneCallback;

            textureCoordsBackground = FresviiGUIColorPalette.GetTextureCoods(FresviiGUIColorPalette.ModalBackground);

            this.guiDepth = guiDepth;

            loadingSpinnerSize *= FresviiGUIManager.Instance.ScaleFactor;

            loadingSpinnerPosition = new Rect(Screen.width * 0.5f - loadingSpinnerSize.x * 0.5f, Screen.height * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y);

            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinnerPosition, guiDepth - 10);

            FresviiGUIManager.Instance.resourceManager.TextureFromCacheOrDownloadOrMemory(this.imageUrl, true, delegate(Texture2D tex)
            {
                loadingSpinner.Hide();

                this.texture = tex;

                imagePosition = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);

                imageRect = new Rect(0f, 0f, Screen.width, Screen.width * texture.height / texture.width);

                if (imageRect.height > Screen.height)
                {
                    float w = texture.width * Screen.height / texture.height;

                    imageRect = new Rect(0.5f * (Screen.width - w), 0f, w, Screen.height);
                }
            });
        }
        public void OnPullUpReflesh()
        {
            if (loading || loadBlock) return;

            loading = true;

            loadBlock = true;

            loadingSpinnerPlace = LoadingSpinnerPlace.Bottom;

            loadingSpinnerPosition = new Rect(baseRect.x + baseRect.width * 0.5f - loadingSpinnerSize.x * 0.5f, baseRect.y + baseRect.height - reloadHeight * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y);

            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinnerPosition, FASGui.GuiDepthBase);

            loadedPage++;

            pullRefleshing = true;

            FASForum.GetThreadComments(Thread.Id, loadedPage, delegate(IList<Fresvii.AppSteroid.Models.Comment> _comments, Fresvii.AppSteroid.Models.Error _error)
            {
                bool added = false;

                pullRefleshing = false;

                loadingSpinner.Hide();

                OnCompletePullReflesh(scrollViewRect, baseRect, threadTopMenu.height, threadBottomMenu.height);

                if (_error == null)
                {
                    foreach (Fresvii.AppSteroid.Models.Comment _comment in _comments)
                    {
                        if (!commentIds.Contains(_comment.Id))
                        {
                            FresviiGUICommentCard card = ((GameObject)Instantiate(Resources.Load("GuiPrefabs/CommentCard"))).GetComponent<FresviiGUICommentCard>();

                            card.transform.parent = this.transform;

                            card.Init(_comment, scaleFactor, Thread, Screen.width - 2f * sideMargin, this);

                            cards.Add(card);

                            comments.Add(_comment);

                            commentIds.Add(_comment.Id);

                            added = true;
                        }
                        else
                        {
                            foreach (FresviiGUICommentCard card in cards)
                            {
                                if (card.Comment.Id == _comment.Id)
                                {
                                    card.Comment = _comment;
                                    break;
                                }
                            }
                        }
                    }

                    cards.Sort((a, b) => System.DateTime.Compare(a.Comment.CreatedAt, b.Comment.CreatedAt));

                    if (cards.Count > cardMaxNum)
                    {
                        for (int i = 0; i < cardMaxNum - cards.Count; i++)
                        {
                            FresviiGUICommentCard card = cards[0];
                            cards.RemoveAt(0);
                            Destroy(card.gameObject);
                        }
                    }

                }
                else
                {
                    loadedPage--;
                }

                if (!added) loadedPage--;

                loading = false;

                if (!FASGesture.IsTouching && !added)
                {
                    iTween.ValueTo(this.gameObject, iTween.Hash("from", scrollViewRect.y, "to", - scrollViewRect.height + baseRect.height - threadBottomMenu.height, "time", tweenTime, "easetype", tweenEaseType, "onupdatetarget", this.gameObject, "onupdate", "OnUpdateScrollPosition"));
                }
            });
        }
        void OnGUI()
        {
            GUI.depth = GuiDepth;

            GUI.DrawTextureWithTexCoords(menuRect, palette, texCoordsMenu);

            GUI.DrawTextureWithTexCoords(new Rect(menuRect.x, menuRect.y - 1, Screen.width, 1), palette, texCoordsBorderLine);

            GUI.BeginGroup(menuRect);

            Event e = Event.current;

            if (!imageLoading)
            {
                if (clipImage == null)
                {
                    GUI.DrawTexture(addButtonPosition, addButton, ScaleMode.ScaleToFit);
                }
                else
                {
                    GUI.DrawTexture(addButtonPosition, clipImage, ScaleMode.ScaleAndCrop);
                }
            }

            if (!imageLoading)
            {
                if (GUI.Button(addButtonHitPosition, "", GUIStyle.none) && !parentFrame.ControlLock)
                {
                    if (!sendEnableAtAction)
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(sendUnableAtActionMessage, delegate(bool del) { });
                    }
                    else
                    {

                        List<string> buttons = new List<string>();

                        buttons.Add(FresviiGUIText.Get("TakePhoto"));

                        buttons.Add(FresviiGUIText.Get("ChoosePhoto"));

                        buttons.Add(FresviiGUIText.Get("ChooseMovie"));

                        if (clipImage != null)
                            buttons.Add(FresviiGUIText.Get("CancelPhoto"));

                        if (video != null)
                        {
                            buttons.Add(FresviiGUIText.Get("CancelVideo"));
                        }

                        actionSheet = Fresvii.AppSteroid.Gui.ActionSheet.Show(scaleFactor, postFix, this.GuiDepth - 10, buttons.ToArray(), (selectedButton) =>
                        {
                            if (selectedButton == FresviiGUIText.Get("TakePhoto")) // TakePhoto
                            {
                                imageLoading = true;

                                loadingSpinnerPosition = new Rect(menuRect.x + addButtonPosition.x, menuRect.y + addButtonPosition.y, addButtonPosition.width, addButtonPosition.height);

                                loadingSpiner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinnerPosition, GUI.depth);

                                Fresvii.AppSteroid.Util.ImagePicker.Show(this, Fresvii.AppSteroid.Util.ImagePicker.Type.Camera, delegate(Texture2D loadedTexture)
                                {
                                    imageLoading = false;

                                    loadingSpiner.Hide();

                                    if (loadedTexture != null)
                                    {
                                        if (clipImage != null)
                                        {
                                            Destroy(clipImage);

                                            clipImage = null;
                                        }

                                        clipImage = loadedTexture;

                                        video = null;

                                        if (autoSendImageLoaded)
                                        {
                                            Send("", clipImage, video);
                                        }
                                    }
                                });
                            }
                            else if (selectedButton == FresviiGUIText.Get("ChoosePhoto")) // Choose Photo from library
                            {
                                imageLoading = true;

                                loadingSpiner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(new Rect(menuRect.x + addButtonPosition.x, menuRect.y + addButtonPosition.y, addButtonPosition.width, addButtonPosition.height), GUI.depth);

                                Fresvii.AppSteroid.Util.ImagePicker.Show(this, Fresvii.AppSteroid.Util.ImagePicker.Type.Gallery, delegate(Texture2D loadedTexture)
                                {
                                    imageLoading = false;

                                    loadingSpiner.Hide();

                                    if (loadedTexture != null)
                                    {
                                        if (clipImage != null)
                                        {
                                            Destroy(clipImage);

                                            clipImage = null;
                                        }

                                        clipImage = loadedTexture;

                                        video = null;

                                        if (autoSendImageLoaded)
                                        {
                                            Send("", clipImage, video);
                                        }
                                    }
                                });
                            }
                            else if (selectedButton == FresviiGUIText.Get("ChooseMovie")) // Choose Video from library
                            {
                                imageLoading = true;

                                loadingSpiner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(new Rect(menuRect.x + addButtonPosition.x, menuRect.y + addButtonPosition.y, addButtonPosition.width, addButtonPosition.height), GUI.depth);

                                FresviiGUIVideoList.Show(parentFrame, int.MinValue + 1000, delegate(Fresvii.AppSteroid.Models.Video _video, Texture2D loadedTexture)
                                {
                                    imageLoading = false;

                                    loadingSpiner.Hide();

                                    if (loadedTexture != null)
                                    {
                                        if (clipImage != null)
                                        {
                                            Destroy(clipImage);

                                            clipImage = null;
                                        }

                                        clipImage = loadedTexture;

                                        this.video = _video;

                                        if (autoSendImageLoaded)
                                        {
                                            Send("", clipImage, video);
                                        }
                                    }
                                });
                            }
                            else if (selectedButton == FresviiGUIText.Get("CancelPhoto")) // Cancel photo
                            {
                                if (clipImage != null)
                                {
                                    Destroy(clipImage);

                                    clipImage = null;

                                    video = null;
                                }
                            }
                            else if (selectedButton == FresviiGUIText.Get("CancelVideo")) // Cancel video
                            {
                                if (clipImage != null)
                                {
                                    Destroy(clipImage);

                                    clipImage = null;

                                    video = null;
                                }
                            }
                        });
                    }
                }
            }

            FresviiGUIUtility.DrawButtonFrameX9(textFieldPosition, textFiled);

            if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor)
            {
                textInputField = GUI.TextField(textFieldPosition, textInputField, guiStyleTextFiled);
            }
            else{

                if (e.type == EventType.MouseUp && textFieldPosition.Contains(e.mousePosition) && !FASGesture.IsDragging)
                {
                    e.Use();

                    FresviiGUIPopUpShield shield = gameObject.GetComponent<FresviiGUIPopUpShield>();

                    if(shield == null)
                    {
                        shield = gameObject.AddComponent<FresviiGUIPopUpShield>();
                    }

                    shield.Enable(delegate ()
                    {
                        if(keyboard != null)
                        {
                            keyboard.active = false;

                            keyboard.text = "";

                            keyboard = null;
                        }
                    });

                    keyboard = TouchScreenKeyboard.Open(textInputField, TouchScreenKeyboardType.Default, false, true, false, false);
                }

                if (keyboard != null)
                {
                    textInputField = keyboard.text;

                    if(keyboard.done || keyboard.wasCanceled || !keyboard.active)
                    {
                        gameObject.GetComponent<FresviiGUIPopUpShield>().Done();

                        keyboard = null;
                    }
                }

                GUI.Label(textFieldPosition, textInputField, guiStyleTextFiled);
            }

            bool sendOK = ((clipImage != null) || !string.IsNullOrEmpty(textInputField));

            guiStyleSendButton.normal.textColor = (sendOK) ? buttonTextEnableColor : buttonTextUnableColor;

            Texture2D sendButtonTexture = (sendOK) ? sendButton : sendButtonD;

            if (sending)
            {
                sendButtonTexture = sendButtonH;

                guiStyleSendButton.normal.textColor = buttonTextHitColor;
            }

            FresviiGUIUtility.DrawButtonFrameX9(sendButtonPosition, sendButtonTexture);

            GUI.Label(sendButtonPosition, FresviiGUIText.Get("send"), guiStyleSendButton);

            if (e.type == EventType.MouseUp && sendButtonPosition.Contains(e.mousePosition) && sendOK && !FASGesture.IsDragging && !parentFrame.ControlLock)
            {
                e.Use();

                if (!sendEnableAtAction)
                {
                    Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                    if (string.IsNullOrEmpty(sendUnableAtActionDialogTitle))
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(sendUnableAtActionMessage, delegate(bool del) { });
                    }
                    else
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(sendUnableAtActionDialogTitle, sendUnableAtActionMessage, delegate(bool del) { });
                    }

                }
                else
                {
                    Send(textInputField, clipImage, video);

                    textInputField = "";

                    if (keyboard != null)
                    {
                        keyboard.text = "";
                    }

                    keyboard = null;

                    clipImage = null;

                    video = null;
                }
            }

            GUI.EndGroup();
        }
        public void OnPullUpReflesh()
        {
            if (loading || loadBlock) return;

            uint loadPage = 2;

            if (pullUpListMeta != null)
            {
                if (pullUpListMeta.NextPage.HasValue)
                {
                    loadPage = (uint)pullUpListMeta.NextPage;
                }
                else
                {
                    loadPage = pullUpListMeta.TotalCount / pullUpListMeta.PerPage + 1;
                }
            }

            loading = true;

            loadBlock = true;

            loadingSpinnerPlace = LoadingSpinnerPlace.Bottom;

            loadingSpinner.Position = new Rect(Position.x + baseRect.x + baseRect.width * 0.5f - loadingSpinnerSize.x * 0.5f, Position.y + baseRect.y + baseRect.height - reloadHeight * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y);

            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinner.Position);

            pullRefleshing = true;

            FASForum.GetForumThreads(loadPage, delegate(IList<Fresvii.AppSteroid.Models.Thread> _threads, Fresvii.AppSteroid.Models.ListMeta _meta, Fresvii.AppSteroid.Models.Error _error)
            {
                pullUpListMeta = _meta;

                pullRefleshing = false;

                loading = false;

                loadingSpinner.Hide();

                if (_error == null)
                {
                    float addedHeight = 0.0f;

                    foreach (Fresvii.AppSteroid.Models.Thread thread in _threads)
                    {
                        addedHeight += UpdateThread(thread);
                    }

                    SortCards();

                    if (addedHeight > 0.0f)
                    {
                        //scrollViewRect.y -= addedHeight;
                    }
                    else
                    {
                        OnCompletePullReflesh(scrollViewRect, baseRect, forumTopMenu.height, tabBar.height);
                    }
                }
                else
                {
                    OnCompletePullReflesh(scrollViewRect, baseRect, forumTopMenu.height, tabBar.height);
                }
            });
        }
        public void OnPullDownReflesh()
        {
            if (loading || loadBlock) return;

            loading = true;

            loadBlock = true;

            loadingSpinnerPlace = LoadingSpinnerPlace.Top;

            loadingSpinner.Position = new Rect(Position.x + baseRect.x + baseRect.width * 0.5f - loadingSpinnerSize.x * 0.5f, Position.y + baseRect.y + reloadHeight * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y);

            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinner.Position);

            pullRefleshing = true;

            FASForum.GetForumThreads(delegate(IList<Fresvii.AppSteroid.Models.Thread> _threads, Fresvii.AppSteroid.Models.Error error)
            {
                pullRefleshing = false;

                loading = false;

                OnCompletePullReflesh(scrollViewRect, baseRect);

                loadingSpinner.Hide();

                if (error == null)
                {
                    foreach (Fresvii.AppSteroid.Models.Thread thread in _threads)
                    {
                        UpdateThread(thread);
                    }

                    SortCards();
                }
            });
        }
        void OnGUI()
        {
            GUI.DrawTextureWithTexCoords(backgroundRect, FresviiGUIColorPalette.Palette, textureCoordsBackground);

			if(user == null) return;

            if (!hasError)
            {
                GUI.depth = GuiDepth;

                GUI.BeginGroup(baseRect);

                GUI.BeginGroup(scrollViewRect);

       			//	User Image
                GUI.DrawTexture(userImagePosition, (textureUserProfile == null) ? textureUserProfileDefault : textureUserProfile, ScaleMode.ScaleToFit);

                Color tmp = GUI.color;

                GUI.color = bgColor;

                GUI.DrawTexture(userImagePosition, textureUserProfileMask, ScaleMode.ScaleToFit);

                GUI.color = tmp;

                GUI.DrawTexture(userImagePosition, textureUserProfileCircle, ScaleMode.ScaleToFit);

                //  User name
                GUI.Label(userNamePosition, userNameContent, guiStyleLabelUserName);

                if (!string.IsNullOrEmpty(user.Description))
                {
                    GUI.Label(userDescriptionPosition, userDescriptionContent, guiStyleLabelUserProfile);
                }

                if (user.Official)
                {
                    GUI.EndGroup();

                    GUI.EndGroup();

                    return;
                }

                Event e = Event.current;

                //  Holding  - menu apper
                if (userNamePosition.Contains(e.mousePosition) && FASGesture.IsHolding && !FASGesture.IsDragging && !ControlLock)
                {
                    List<string> buttons = new List<string>();

                    buttons.Add(FresviiGUIText.Get("Copy"));

                    Vector2 postion = new Vector2(baseRect.x + scrollViewRect.x + userNamePosition.x + userNamePosition.width * 0.5f, baseRect.y + scrollViewRect.y + userNamePosition.y);

                    ControlLock = true;

                    popOverBalloonMenu = Fresvii.AppSteroid.Gui.PopOverBalloonMenu.Show(scaleFactor, postFix, this.GuiDepth - 30, postion, buttons.ToArray(), (selectedButton) =>
                    {
                        ControlLock = false;

                        if (selectedButton == FresviiGUIText.Get("Copy"))
                        {
                            Fresvii.AppSteroid.Util.Clipboard.SetText(user.Name);
                        }
                    });

                    popOverBalloonMenu.Name = "UserName";
                }      

                // User Code
                GUI.Label(userCodePosition, userCodeContent, guiStyleLabelUserCode);


                //  Holding  - menu apper
                if (userCodePosition.Contains(e.mousePosition) && FASGesture.IsHolding && !FASGesture.IsDragging && !ControlLock)
                {
                    List<string> buttons = new List<string>();

                    buttons.Add(FresviiGUIText.Get("Copy"));

                    Vector2 postion = new Vector2(baseRect.x + scrollViewRect.x + userCodePosition.x + userCodePosition.width * 0.5f, baseRect.y + scrollViewRect.y + userCodePosition.y);

                    ControlLock = true;

                    popOverBalloonMenu = Fresvii.AppSteroid.Gui.PopOverBalloonMenu.Show(scaleFactor, postFix, this.GuiDepth - 30, postion, buttons.ToArray(), (selectedButton) =>
                    {
                        ControlLock = false;

                        if (selectedButton == FresviiGUIText.Get("Copy"))
                        {
                            Fresvii.AppSteroid.Util.Clipboard.SetText(user.UserCode);
                        }
                    });

                    popOverBalloonMenu.Name = "UserCode";
                }

                if (userInfoEnable)
                {
                    #region Friend button

                    if (user.FriendStatus == Fresvii.AppSteroid.Models.User.FriendStatuses.Requesting)
                    {
						guiStyleButtonFriend.normal.textColor = btnNegativeColor;

                        buttonFriend.IsTap(e, friendButtonPosition, friendButtonPosition, FresviiGUIButton.ButtonType.FrameAndLabel, textureButton03, textureButton03, textureButton03, FresviiGUIText.Get("RequestSent"), guiStyleButtonFriend);
                    }
                    /*else if (user.FriendStatus == User.FriendStatuses.Requested)
                    {
						guiStyleButtonFriend.normal.textColor = btnNegativeColor;

						buttonFriend.IsTap(e, friendButtonPosition, friendButtonPosition, FresviiGUIButton.ButtonType.FrameAndLabel, textureButton03, textureButton03, textureButton03, FresviiGUIText.Get("Requested"), guiStyleButtonFriend);
                    }*/
                    else if (user.FriendStatus == Fresvii.AppSteroid.Models.User.FriendStatuses.Friend)
                    {
						guiStyleButtonFriend.normal.textColor = btnPositiveColor;

                        if (buttonFriend.IsTap(e, friendButtonPosition, friendButtonPosition, FresviiGUIButton.ButtonType.FrameAndLabel, textureButton01, textureButton01H, textureButton01H, FresviiGUIText.Get("Unfriend"), guiStyleButtonFriend))
                        {
                            Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("Unfriend"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                            Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSelectDialog(FresviiGUIText.Get("ConfirmUnfriend"), delegate(bool del)
                            {
#if UNITY_EDITOR
                                if (true)
#else
                            	if(del)
#endif
                                {
                                    if (Application.internetReachability == NetworkReachability.NotReachable)
                                    {
                                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool _del) { });
                                    }
                                    else
                                    {
                                        FASFriendship.UnFriend(this.user.Id, delegate(Fresvii.AppSteroid.Models.Error error)
                                        {
                                            if (error == null)
                                            {
                                                user.SetFriendStatus(Fresvii.AppSteroid.Models.FriendshipRequest.Statuses.none.ToString());

                                                DeletePairGroupMessages(user.Id, deleteGroupRetryCount, deleteGroupRetryInterval);
                                            }
                                            else
                                            {
                                                if (FASConfig.Instance.logLevel <= FAS.LogLevels.Error)
                                                {
                                                    Debug.LogError(error.ToString());
                                                }

                                                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("UnknownError"), delegate(bool _del) { });
                                            }
                                        });
                                    }
                                }
                            });

                        }
                    }
                    else
                    {
						guiStyleButtonFriend.normal.textColor = btnPositiveColor;

                        if (buttonFriend.IsTap(e, friendButtonPosition, friendButtonPosition, FresviiGUIButton.ButtonType.FrameAndLabel, textureButton01, textureButton01H, textureButton01H, FresviiGUIText.Get("AddFriend"), guiStyleButtonFriend))
                        {
                            if (Application.internetReachability == NetworkReachability.NotReachable)
                            {
                                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool del) { });
                            }
                            else
                            {
                                user.SetFriendStatus(Fresvii.AppSteroid.Models.FriendshipRequest.Statuses.requesting.ToString());

                                FASFriendship.SendFriendshipRequest(this.user.Id, delegate(Fresvii.AppSteroid.Models.FriendshipRequest friendshipRequest, Fresvii.AppSteroid.Models.Error error)
                                {
                                    if (error == null)
                                    {
                                        user.SetFriendStatus(friendshipRequest.Status.ToString());
                                    }
                                    else
                                    {
                                        if (FASConfig.Instance.logLevel <= FAS.LogLevels.Error)
                                            Debug.LogError(error.ToString());

                                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("UnknownError"), delegate(bool del) { });

                                        user.SetFriendStatus(Fresvii.AppSteroid.Models.FriendshipRequest.Statuses.none.ToString());
                                    }
                                });
                            }
                        }
                    }
                }
                #endregion

                #region Message button

                if (buttonMessage.IsTap(e, messageButtonPosition, messageButtonPosition, FresviiGUIButton.ButtonType.TextureOnly, textureIconMessage, textureIconMessage, textureIconMessage))                  
                {
                    if (Application.internetReachability == NetworkReachability.NotReachable)
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool del) { });
                    }
                    else
                    {
                        FresviiGUIFrame framePairChat = ((GameObject)Instantiate(prfbGUIFramePairChat)).GetComponent<FresviiGUIFrame>();

                        framePairChat.transform.parent = this.transform;

                        framePairChat.gameObject.GetComponent<FresviiGUIChat>().SetPairUser(this.user);

                        framePairChat.Init(null, postFix, scaleFactor, this.GuiDepth - 1);

                        framePairChat.SetDraw(true);

                        framePairChat.PostFrame = this;

                        this.tabBar.enabled = false;

                        this.Tween(Vector2.zero, new Vector2(-Screen.width, 0.0f), moveDelayTime, delegate()
                        {
                            this.SetDraw(false);
                        });

                        framePairChat.Tween(new Vector2(Screen.width, 0.0f), Vector2.zero, moveDelayTime, delegate() { });
                    }
                }

                GUI.Label(messageLabelPosition, messageLabelContent, guiStyleButtonLabel);

                #endregion

                #region Call button

#if GROUP_CONFERENCE
                if (!user.Official)
                {
                    bool isCalling = FASConference.IsCalling();

                    Texture2D textureCall = (isCalling) ? textureIconCallD : textureIconCall;

                    if (buttonMessage.IsTap(e, callButtonPosition, callButtonPosition, FresviiGUIButton.ButtonType.TextureOnly, textureCall, textureCall, textureCall))
                    {

#if !UNITY_EDITOR
					if (isCalling)
                    {
						Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

						Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("VoiceChatAlredayExists"), delegate(bool del) { });

                        return;
                    }
#endif
                        if (Application.internetReachability == NetworkReachability.NotReachable)
                        {
                            Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool del) { });
                        }
                        else
                        {
                            loadingSpinnerPosition = new Rect(Screen.width * 0.5f - loadingSpinnerSize.x * 0.5f, Screen.height * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y);

                            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinnerPosition, this.GuiDepth - 10);

                            FASGroup.CreatePair(user.Id, delegate(Fresvii.AppSteroid.Models.Group group, Fresvii.AppSteroid.Models.Error error)
                            {
                                if (error != null)
                                {
                                    loadingSpinner.Hide();

                                    if (FASConfig.Instance.logLevel <= FAS.LogLevels.Error)
                                    {
                                        Debug.LogError("CreatePair : " + error.ToString());
                                    }

                                    Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog("Error : CreatePair " + error.ToString(), delegate(bool del) { });
                                }
                                else
                                {
                                    loadingSpinner.Hide();

                                    group.FetchMembers(delegate(Fresvii.AppSteroid.Models.Error error2)
                                    {
                                        if (error2 != null)
                                        {
                                            if (FASConfig.Instance.logLevel <= FAS.LogLevels.Error)
                                            {
                                                Debug.LogError("FetchMembers : " + error.ToString());
                                            }

                                            Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                                            if (error.Code == (int)Fresvii.AppSteroid.Models.Error.ErrorCode.NetworkNotReachable)
                                            {
                                                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool del) { });
                                            }
                                            else
                                            {
                                                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(error.Detail, delegate(bool del) { });
                                            }
                                        }
                                        else
                                        {
                                            OnCallButtonTapped(group);
                                        }
                                    });
                                }
                            });
                        }
                    }

                    GUI.Label(callLabelPosition, callLabelContent, guiStyleButtonLabel);
                }
#endif

                #endregion

                //  User FriendTitleBar
                if (friendCountLabelContent != null)
                {
                    GUI.DrawTextureWithTexCoords(friendMenuTitleBarPosition, palette, buttonFriendList.IsActive ? texCoordsFriendTitleBgH : texCoordsFriendTitleBg);

                    GUI.Label(friendMenuTitleBarPosition, friendCountLabelContent, guiStyleFriendMenuTitle);

                    GUI.DrawTexture(friendMenuRightIconPosition, textureRight);
                }

#if UNITY_IOS
                //  VideoTitleBar
                if (FASConfig.Instance.videoEnable)
                {
                    GUI.DrawTextureWithTexCoords(videoTitleBarPosition, palette, buttonVideoList.IsActive ? texCoordsFriendTitleBgH : texCoordsFriendTitleBg);

                    GUI.Label(videoTitleBarPosition, videoListLabelContent, guiStyleFriendMenuTitle);

                    GUI.DrawTexture(videoRightIconPosition, textureRight);

                    if (buttonVideoList.IsTap(e, videoTitleBarPosition))
                    {
                        GoToVideoList(true);
                    }
                }
#endif

                if(buttonFriendList.IsTap(e, friendMenuTitleBarPosition))
                {
                    frameFriendList = ((GameObject)Instantiate(prfbFriendList)).GetComponent<FresviiGUIFrame>();

                    frameFriendList.transform.parent = this.transform;

                    frameFriendList.gameObject.GetComponent<FresviiGUIFriendList>().SetUser(this.user);

                    frameFriendList.Init(null, postFix, scaleFactor, this.GuiDepth - 1);

                    frameFriendList.SetDraw(true);

                    frameFriendList.PostFrame = this;

                    this.Tween(Vector2.zero, new Vector2(-Screen.width, 0.0f), delegate()
                    {
                        this.SetDraw(false);
                    });

                    frameFriendList.Tween(new Vector2(Screen.width, 0.0f), Vector2.zero, delegate() { });

                }

                GUI.EndGroup();

                GUI.EndGroup();
            }
        }       
        void OnGUI()
        {
            GUI.depth = GuiDepth;

            GUI.DrawTextureWithTexCoords(menuRect, palette, texCoordsMenu);

            GUI.DrawTextureWithTexCoords(new Rect(menuRect.x, menuRect.y - 1, Screen.width, 1), palette, texCoordsBorderLine);

            GUI.BeginGroup(menuRect);

            Event e = Event.current;

            if (!imageLoading)
            {
                if (clipImage == null)
                {
                    GUI.DrawTexture(addButtonPosition, addButton, ScaleMode.ScaleToFit);
                }
                else
                {
                    GUI.DrawTexture(addButtonPosition, clipImage, ScaleMode.ScaleAndCrop);
                }
            }

            if (!imageLoading)
            {
                if (GUI.Button(addButtonHitPosition, "", GUIStyle.none))
                {
                    List<string> buttons = new List<string>();

                    buttons.Add(FresviiGUIText.Get("TakePhoto"));

                    buttons.Add(FresviiGUIText.Get("ChoosePhoto"));

                    buttons.Add(FresviiGUIText.Get("ChooseMovie"));

                    if (clipImage != null)
                        buttons.Add(FresviiGUIText.Get("CancelPhoto"));

                    if (video != null)
                        buttons.Add(FresviiGUIText.Get("CancelVideo"));

                    actionSheet = Fresvii.AppSteroid.Gui.ActionSheet.Show(scaleFactor, postFix, this.GuiDepth - 10, buttons.ToArray(), (selectedButton) =>
                    {
                        if (selectedButton == FresviiGUIText.Get("TakePhoto")) // TakePhoto
                        {
                            imageLoading = true;

                            loadingSpinnerPosition = new Rect(menuRect.x + addButtonPosition.x, menuRect.y + addButtonPosition.y, addButtonPosition.width, addButtonPosition.height);

                            loadingSpiner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinnerPosition, GUI.depth);

                            Fresvii.AppSteroid.Util.ImagePicker.Show(this, Fresvii.AppSteroid.Util.ImagePicker.Type.Camera, delegate(Texture2D loadedTexture)
                            {
                                imageLoading = false;

                                loadingSpiner.Hide();

                                if (loadedTexture != null)
                                {
                                    if (clipImage != null)
                                    {
                                        Destroy(clipImage);
                                        clipImage = null;
                                    }

                                    clipImage = loadedTexture;

                                    video = null;
                                }
                            });
                        }
                        else if (selectedButton == FresviiGUIText.Get("ChoosePhoto")) // Choose Photo from library
                        {
                            imageLoading = true;

                            loadingSpiner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(new Rect(menuRect.x + addButtonPosition.x, menuRect.y + addButtonPosition.y, addButtonPosition.width, addButtonPosition.height), GUI.depth);

                            Fresvii.AppSteroid.Util.ImagePicker.Show(this, Fresvii.AppSteroid.Util.ImagePicker.Type.Gallery, delegate(Texture2D loadedTexture)
                            {
                                imageLoading = false;

                                loadingSpiner.Hide();

                                if (loadedTexture != null)
                                {
                                    if (clipImage != null)
                                    {
                                        Destroy(clipImage);
                                        clipImage = null;
                                    }

                                    clipImage = loadedTexture;

                                    video = null;
                                }
                            });
                        }
                        else if (selectedButton == FresviiGUIText.Get("ChooseMovie")) // Choose Video from library
                        {
                            imageLoading = true;

                            loadingSpiner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(new Rect(menuRect.x + addButtonPosition.x, menuRect.y + addButtonPosition.y, addButtonPosition.width, addButtonPosition.height), GUI.depth);

                            FresviiGUIVideoList.Show(frameThread, frameThread.GuiDepth - 500, delegate(Fresvii.AppSteroid.Models.Video _video, Texture2D loadedTexture)
                            //ImagePicker.ShowMoviePicker(this, delegate(string path, Texture2D loadedTexture)
                            {
                                imageLoading = false;

                                loadingSpiner.Hide();

                                if (loadedTexture != null)
                                {
                                    if (clipImage != null)
                                    {
                                        Destroy(clipImage);

                                        clipImage = null;
                                    }

                                    clipImage = loadedTexture;

                                    this.video = _video;
                                }
                            });
                        }
                        else if (selectedButton == FresviiGUIText.Get("CancelPhoto")) // Cancel photo
                        {
                            if (clipImage != null)
                            {
                                Destroy(clipImage);

                                clipImage = null;

                                video = null;
                            }
                        }
                        else if (selectedButton == FresviiGUIText.Get("CancelVideo")) // Cancel video
                        {
                            if (clipImage != null)
                            {
                                Destroy(clipImage);

                                clipImage = null;

                                video = null;
                            }
                        }
                    });
                }
            }

            FresviiGUIUtility.DrawButtonFrame(textFieldPosition, textFiled, scaleFactor);

            #if UNITY_EDITOR

            textInputField = GUI.TextField(textFieldPosition, textInputField, guiStyleTextFiled);

            #elif UNITY_ANDROID || UNITY_IOS

            if (e.type == EventType.MouseUp && textFieldPosition.Contains(e.mousePosition) && !FASGesture.IsDragging)
            //if (GUI.Button(textFieldPosition, textInputField, guiStyleTextFiled))
            {
                e.Use();

                FresviiGUIPopUpShield shield = gameObject.GetComponent<FresviiGUIPopUpShield>();

                if(shield == null)
                {
                    shield = gameObject.AddComponent<FresviiGUIPopUpShield>();
                }

                shield.Enable(delegate ()
                {
                    if(keyboard != null)
                    {
                        keyboard.active = false;

                        keyboard.text = "";

                        keyboard = null;
                    }
                });

                keyboard = TouchScreenKeyboard.Open(textInputField, TouchScreenKeyboardType.Default, false, true, false, false);
            }

            if (keyboard != null)
            {
                textInputField = keyboard.text;

                if(keyboard.done || keyboard.wasCanceled || !keyboard.active)
                {
                    gameObject.GetComponent<FresviiGUIPopUpShield>().Done();

                    keyboard = null;
                }
            }

            GUI.Label(textFieldPosition, textInputField, guiStyleTextFiled);

            #endif

            bool sendEnable = (clipImage != null) || !string.IsNullOrEmpty(textInputField);

            guiStyleSendButton.normal.textColor = (sendEnable) ? buttonTextEnableColor : buttonTextUnableColor;

            Texture2D sendButtonTexture = (sendEnable) ? sendButton : sendButtonD;

            if (sending)
            {
                sendButtonTexture = sendButtonH;

                guiStyleSendButton.normal.textColor = buttonTextHitColor;
            }

            FresviiGUIUtility.DrawButtonFrame(sendButtonPosition, sendButtonTexture, scaleFactor);

            GUI.Label(sendButtonPosition, FresviiGUIText.Get("send"), guiStyleSendButton);

            if(e.type == EventType.MouseUp && sendButtonPosition.Contains(e.mousePosition) && sendEnable && !FASGesture.IsDragging)
            {
                e.Use();

                if (Application.internetReachability == NetworkReachability.NotReachable)
                {
                    Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool del) { });

                    return;
                }

                frameThread.AddComment(frameThread.Thread.Id, textInputField, clipImage, video);

                StartCoroutine(SendingAnimation());

                textInputField = "";

                if(keyboard != null)
                    keyboard.text = "";

                keyboard = null;

                clipImage = null;

                video = null;
            }

            GUI.EndGroup();
        }
        public override void Init(Texture2D appIcon, string postFix, float scaleFactor, int guiDepth)
        {
            FASGesture.Resume();

            this.GuiDepth = guiDepth;

            textureCoordsBackground = FresviiGUIColorPalette.GetTextureCoods(FresviiGUIColorPalette.MainBackground);

            chatTopMenu = GetComponent<FresviiGUIChatTopMenu>();

            addCommentBottomMenu = GetComponent<FresviiGUIAddCommentBottomMenu>();

            chatTopMenu.Init(appIcon, postFix, scaleFactor, GuiDepth - 1, this);

            addCommentBottomMenu.Init(postFix, scaleFactor, GuiDepth - 1, this, AddComment);

            addCommentBottomMenu.autoSendImageLoaded = true;

            this.scaleFactor = scaleFactor;

            this.postFix = postFix;

            loadingSpinnerSize *= scaleFactor;

            sideMargin *= scaleFactor;

            topMargin *= scaleFactor;

            balloonMargin *= scaleFactor;

            balloonMatTexture = FresviiGUIManager.Instance.resourceManager.LoadTextureFromResource(FresviiGUIConstants.ResouceTextureFolderName + "/" + FresviiGUIConstants.ChatBalloonTextureName + this.postFix, false);

            balloonTriangleTexture = FresviiGUIManager.Instance.resourceManager.LoadTextureFromResource(FresviiGUIConstants.ResouceTextureFolderName + "/" + FresviiGUIConstants.ChatBalloonTriangleTextureName + this.postFix, false);

            videoPlaybackIconTexture = FresviiGUIManager.Instance.resourceManager.LoadTextureFromResource(FresviiGUIConstants.ResouceTextureFolderName + "/" + FresviiGUIConstants.VideoPlaybackIconTextureName, false);

            chatDateBg = FresviiGUIManager.Instance.resourceManager.LoadTextureFromResource(FresviiGUIConstants.ResouceTextureFolderName + "/" + FresviiGUIConstants.ChatDateBgTextureName + postFix, false);

            loadingSpinnerPosition = new Rect(Screen.width * 0.5f - loadingSpinnerSize.x * 0.5f, Screen.height * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y);

            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(loadingSpinnerPosition, this.GuiDepth - 10);

            heightDate *= scaleFactor;

            guiStyleDate.fontSize = (int)(guiStyleDate.fontSize * scaleFactor);

            guiStyleDate.normal.textColor = FresviiGUIColorPalette.GetColor(FresviiGUIColorPalette.CardText1);

            guiStyleDate.padding = FresviiGUIUtility.RectOffsetScale(guiStyleDate.padding, scaleFactor);

            chatBalloonColor = FresviiGUIColorPalette.GetColor(FresviiGUIColorPalette.ChatBalloon);

            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                guiStyleDate.font = null;
            }

            SetScrollSlider(scaleFactor * 2.0f);

            StartCoroutine(PollingGetMessages());

            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("Offline"), delegate(bool del) { });

                loadingSpinner.Hide();

                return;
            }
        }
        public void Submit()
        {
            loadingSpinner = Fresvii.AppSteroid.Gui.LoadingSpinner.Show(new Rect(Screen.width * 0.5f - loadingSpinnerSize.x * 0.5f, Screen.height * 0.5f - loadingSpinnerSize.y * 0.5f, loadingSpinnerSize.x, loadingSpinnerSize.y), FASGui.GuiDepthBase - 100);

            FresviiGUIBlocker blocker = this.gameObject.AddComponent<FresviiGUIBlocker>();

            blocker.guiDepth = FASGui.GuiDepthBase + blockerGUIDepth;

            FASUser.PatchAccount(inputUsername, inputDescription, (loadedTexture != null) ? loadedTexture : null, delegate(Fresvii.AppSteroid.Models.User user, Fresvii.AppSteroid.Models.Error error)
            {
                loadingSpinner.Hide();

                Destroy(blocker);

                Fresvii.AppSteroid.Util.DialogManager.Instance.SetLabel(FresviiGUIText.Get("OK"), FresviiGUIText.Get("Cancel"), FresviiGUIText.Get("Close"));

                if (error == null)
                {
                    Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("ProfileUpdateSuccess"), delegate(bool del) { });

                    guiMyProfile.SetUserProfile(inputUsername, inputDescription, loadedUserIcon);

                    FresviiGUIMyProfile.currentUser = user;

                    guiMyProfile.SetDraw(true);

                    this.Tween(Vector2.zero, new Vector2(0.0f, Screen.height), delegate()
                    {
                        this.SetDraw(false);
                    });

                    Destroy(loadedTexture);

                    loadedTexture = null;

                    loadedUserIcon = null;
                }
                else
                {
                    Debug.Log(error.ToString());

                    if (error.Code == (int)Fresvii.AppSteroid.Models.Error.ErrorCode.NameHasAlreadyBeenTaken)
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("NameHasAlredyBeenTaken"), (del) => { });

                        inputUsername = me.Name;
                    }
                    else
                    {
                        Fresvii.AppSteroid.Util.DialogManager.Instance.ShowSubmitDialog(FresviiGUIText.Get("ProfileUpdateError"), (del) => { });
                    }

                }
            });
        }