using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Globalization;
using System.IO;
using System.Collections;
using iTripLog.Map.Map;
using iTripLog.Map.Controler;
using XTransMobile;
using iTripLog.Friends;
using FlickrNet;

namespace iTripLog.Map
{
    public partial class MapBGFrom : Form
    {
        public int photoCount;
        public Bitmap[] photo;
        public ImageButton[] photoView;
        public PictureBox p;
        public PictureBox cover;
        public double latitude = 32;
        public double longitude = 118;
        public LocationMap map;
        public MapUrlBuilder builder = new MapUrlBuilder();
        public Coordinate coordinate;
        public int zoomLevel = 4;
        public ControlButton[] button = new ControlButton[8];  //suhan
       // public XTImageButton[] button = new XTImageButton[8];//hehe
        public PPTView ppt;
        public bool timerOn = false;
        public int index = 0;
        Point[] oldLocation = new Point[8];
        string title = "Storage Card\\";
        FriendPanel friendsForm;
        bool friendClick=false;
        SearchPanel searchPanel;
        bool searchClick = false;
        CalendarPanel calendarPanel;
        bool calendarClick = false;
        bool circleClick=false;
        int circleCount=3;
        ImageButton[] circleImage;
        ImageButton[] friendImage;
        bool clicked = false;
        bool circle = false;
        Image oldMap;
        int x = 460;
        int y = 640;


        public MapBGFrom()
        {
            InitializeComponent();
            Initial();
        }


        private void Initial()
        {
            
            panel1.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height - 28);
            coordinate = new Coordinate(latitude, longitude);
            builder.CenterCoordinate = coordinate;
            builder.MapType = "mobile";
            builder.ZoomLevel = zoomLevel;
            p = new PictureBox();
            builder.XSize = Screen.PrimaryScreen.Bounds.Width;
            builder.YSize = Screen.PrimaryScreen.Bounds.Height - 28;
            p.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            builder.GoogleMapsAPIKey = "ABQIAAAA6MSmMtmGwgMrJCF464aLohRXH-mWPfrlBv7NHCtlWAF7CKPaARRe5JO4d6vkTBojIlX7cVSnwimEqw";
            map = new LocationMap(builder.MapUrl);
            oldMap = map.Map;
            p.Image = map.Map;
            for (int i = 0; i < 8; i++)
            {
                string s = title+"picture\\iconc_00" + (i + 1) + ".png";
                Bitmap temp = new Bitmap(s);
                button[i] = new ControlButton(temp, (i + 1), this);
                panel1.Controls.Add(button[i]);
                button[i].Size = new System.Drawing.Size(25*x/240,25*x/240);
                button[i].Visible = false;
            }

            oldLocation[0] = xtImageButton1.Location;
            oldLocation[1] = xtImageButton2.Location;
            oldLocation[2] = xtImageButton3.Location;
            oldLocation[3] = xtImageButton4.Location;
            oldLocation[4] = xtImageButton5.Location;
            oldLocation[5] = xtImageButton6.Location;
            oldLocation[6] = xtImageButton7.Location;
            oldLocation[7] = xtImageButton8.Location;
            int allDecrise = 25;
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;
            int screenHeight = Screen.PrimaryScreen.Bounds.Height;
            button[0].Location = new Point(10*x/240, builder.YSize - allDecrise - button[7].Size.Height-45*y/290);
            button[1].Location = new Point(40 *x/240, builder.YSize - allDecrise - button[7].Size.Height - 45 *y/290);
            button[2].Location = new Point(70 *x/240, builder.YSize - allDecrise - button[7].Size.Height - 45 *y/290);
            button[3].Location = new Point(100 *x/240, builder.YSize - allDecrise - button[7].Size.Height - 45 *y/290);
            button[4].Location = new Point(130 *x/240, builder.YSize - allDecrise - button[7].Size.Height - 45 *y/290);
            button[5].Location = new Point(160 *x/240, builder.YSize - allDecrise - button[7].Size.Height - 45 *y/290);
            button[6].Location = new Point(-100,-100);
            button[7].Location = new Point(190 *x/240, builder.YSize - allDecrise - button[7].Size.Height - 45 *y/290);

            //p.Image = new Bitmap("Storage Card\\GetMap\\picture\\back.jpg");

            photoCount = 2;//This is require Chen Xu's paramter.
            photo = new Bitmap[photoCount];
            photoView = new ImageButton[photoCount];
            for (int i = 0; i < photoCount; i++)
            {
                photo[i] = new Bitmap("Storage Card\\photo\\photo00" + (i + 1) + ".jpg");
                photoView[i] = new ImageButton(photo[i]);
                panel1.Controls.Add(photoView[i]);
                photoView[i].Visible = true;
             }
            photoView[0].Location = new Point(110*x/240, 130*y/290);
            photoView[1].Location = new Point(115*x/240, 133*y/290);
            //photoView[2].Location = new Point(124, 10);
            //photoView[3].Location = new Point(116, 130);
            //photoView[4].Location = new Point(116, 130);
            panel1.Controls.Add(p);
            ppt = new PPTView(this);
            ppt.Size = new System.Drawing.Size(builder.XSize, builder.YSize);
        }






        public void ChangeMap(int i)
        {
            coordinate = new Coordinate(latitude, longitude);
            builder.CenterCoordinate = coordinate;
            builder.MapType = "mobile";
            builder.ZoomLevel = zoomLevel;
            builder.XSize = Screen.PrimaryScreen.Bounds.Width;
            builder.YSize = Screen.PrimaryScreen.Bounds.Height - 28;
            builder.GoogleMapsAPIKey = "ABQIAAAA6MSmMtmGwgMrJCF464aLohRXH-mWPfrlBv7NHCtlWAF7CKPaARRe5JO4d6vkTBojIlX7cVSnwimEqw";
            string s="Storage Card\\picture\\map";
            switch (i)
            {
                case 1: s = s + i + ".jpg"; break;
                case 2: s = s + i + ".jpg"; break;
                case 3: s = s + i + ".jpg"; break;
                case 4: s = s + i + ".jpg"; break;
                case 5: s = s + i + ".jpg"; break;
                case 6: s = s + i + ".jpg"; break;
            }

            p.Image = new Bitmap(s);
            if (i == 2 || i == 4||i==6)
            {
                p.Image = oldMap;
            }
            if (i == 1)
            {
                photoView[0].Location = new Point(235, 441);
                photoView[1].Location = new Point(237, 430);
                button[4].BringToFront();
            }

            else if (i == 3)
            {
                photoView[0].Location = new Point(368, 329);
                photoView[1].Location = new Point(360, 310);
            }
            else
            {
                photoView[0].Location = new Point(230, 320);
                photoView[1].Location = new Point(210, 310);
            }
        }


        public void ViewPictures()
        {
            panel1.Controls.Add(ppt);
            ppt.BringToFront();
            ppt.BackgroundImage = photo[index];
            timer1.Interval = 3000;
            timer1.Enabled = true;
        }

        public void nextPPT()
        {
            index = (index + 1) % photoCount;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            index++;
            index = index % photoCount;
            ViewPictures();
        }

       

        public void StopTimer()
        {
            timer1.Enabled = false;
            ppt.Visible = false;
        }

        public void Exit()
        {
            this.Close();
        }

        private void panel1_GotFocus(object sender, EventArgs e)
        {
            if (circle)
            {
                circleImage = new ImageButton[circleCount];
                for (int i = 0; i < circleCount; i++)
                {
                    string s = "Storage Card\\photo\\circle"+(i+1)+".jpg";
                    circleImage[i] = new ImageButton(new System.Drawing.Bitmap(s));
                    panel1.Controls.Add(circleImage[i]);
                    circleImage[i].BringToFront();
                    circleImage[i].Visible = true;
                }


            }
        }

        private void xtImageButton3_Click(object sender, EventArgs e)
        {
           
        }

        private void xtImageButton1_Click(object sender, EventArgs e)//Climate
        {
            iTripLog.WeatherF.FrmDefaultCityWeather weather=new iTripLog.WeatherF.FrmDefaultCityWeather();
            weather.Visible=true;
        }

        private void xtImageButton2_Click(object sender, EventArgs e)//Search
        {
            iTripLog.Search.SearchForm search = new iTripLog.Search.SearchForm();
            search.Show();
        }

        private void xtImageButton4_Click(object sender, EventArgs e)//Camera
        {
            iTripLog.Upload.SnapForm cameraForm = new iTripLog.Upload.SnapForm();
            cameraForm.Visible = true;
        }

        private void xtImageButton6_Click(object sender, EventArgs e)//Good Friend
        {
            if (!friendClick)
            {
                xtImageButton1.Location = new Point(0, 5*y/290);
                xtImageButton2.Location = new Point(30*x/240, 5 *y/290);
                xtImageButton3.Location = new Point(60 *x/240, 5 *y/290);
                xtImageButton4.Location = new Point(90 *x/240, 5 *y/290);
                xtImageButton5.Location = new Point(120 *x/240, 5 *y/290);
                xtImageButton6.Location = new Point(150 *x/240, 5 *y/290);
                xtImageButton7.Location = new Point(180 *x/240, 5 *y/290);
                xtImageButton8.Location = new Point(210 *x/240, 5 *y/290);

                friendsForm = new FriendPanel(this);panel1.Controls.Add(friendsForm);
                //friendsForm.Size = new Size(builder.XSize, ((int)builder.YSize / 2));
                friendsForm.Location = new Point(0, ((int)builder.YSize / 2));
                //friendsForm.Show();
                friendsForm.Visible = true;
                friendsForm.BringToFront();
                
                friendClick = true;
            }
            else
            {
                xtImageButton1.Location = oldLocation[0];
                xtImageButton2.Location = oldLocation[1];
                xtImageButton3.Location = oldLocation[2];
                xtImageButton4.Location = oldLocation[3];
                xtImageButton5.Location = oldLocation[4];
                xtImageButton6.Location = oldLocation[5];
                xtImageButton7.Location = oldLocation[6];
                xtImageButton8.Location = oldLocation[7];

                friendsForm.Visible = false;
                friendsForm = null;
                friendClick = false;
            }
        }

        private void xtImageButton5_Click(object sender, EventArgs e)//Circle
        {
            if (!circle)
            {

                for (int i = 0; i < photoCount; i++)
                {
                    photoView[i].Visible = false;
                }
                this.p.Image = new Bitmap("Storage Card\\Images\\image\\backgroundred.bmp");
                circleImage=new ImageButton[3];
                for (int i = 0; i < 3; i++)
                {
                    string s = "Storage Card\\photo\\circle" + (i + 1) + ".jpg";
                    circleImage[i] = new ImageButton(new Bitmap(s));
                    panel1.Controls.Add(circleImage[i]);
                    circleImage[i].Size = new System.Drawing.Size(40 *x/240, 30 *y/290);
                    circleImage[i].BringToFront();

                }
                circleImage[0].Location = new Point(100 *x/240, 160 *y/290);
                circleImage[1].Location = new Point(110 *x/240, 150 *y/290);
                circleImage[2].Location = new Point(115 *x/240, 140 *y/290);

                    circle = true;
                
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    photoView[i].Visible = true;
                }
                circle = false;
                this.p.Image = oldMap;
            }
                
        }

        private void xtImageButton3_Click_1(object sender, EventArgs e)//Calendar
        {
            iTripLog.Date.DateForm date = new iTripLog.Date.DateForm();
            date.Show();
        }

        private void xtImageButton7_Click(object sender, EventArgs e)//Control button
        {
            if (!button[0].Visible)
                for (int ii=0; ii < 8; ii++)
                {
                    button[ii].Visible = true;
                }
            else
            {
                for (int ii = 0; ii < 8; ii++)
                {
                    button[ii].Visible = false;
                }
            }
        }

        private void xtImageButton8_Click(object sender, EventArgs e)//Setting
        {
            iTripLog.Set.SetForm setting = new iTripLog.Set.SetForm();
            setting.Show();

        }

        public void FriendShow()
        {
            if (!clicked)
            {
                for (int i = 0; i < 2; i++)
                {
                    photoView[i].Visible = false;
                }
                    friendImage = new ImageButton[5];
                for (int i = 0; i < 5; i++)
                {
                    string s = "Storage Card\\photo\\" + (i + 1) + ".jpg";
                    friendImage[i] = new ImageButton(new Bitmap(s));
                    friendImage[i].Size = new System.Drawing.Size(40 *x/240, 40 *y/290);
                    friendImage[i].Visible = true;
                    panel1.Controls.Add(friendImage[i]);
                    friendImage[i].BringToFront();
                }
                friendImage[0].Location = new Point(68 *x/240, 55 *y/290);
                friendImage[1].Location = new Point(30 *x/240, 80 *y/290);
                friendImage[2].Location = new Point(114 *x/240, 23 *y/290);
                friendImage[3].Location = new Point(125 *x/240, 155 *y/290);
                friendImage[4].Location = new Point(90 *x/240, 36 *y/290);
                friendImage[0].BringToFront();
                friendImage[1].BringToFront();
                friendImage[2].BringToFront();
                friendImage[3].BringToFront();
                friendImage[4].BringToFront(); clicked = true;
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    friendImage[i].Visible = false;
                }
                for (int i = 0; i < 2; i++)
                {
                    photoView[i].Visible = true;
                    clicked = false;
                }
            }
        }

        public partial class FriendPanel :Panel 
        {
            MapBGFrom mp;
            ImageButton head;
            Flickr flickr = new Flickr("23589c82ce57562f2dbe6f9810b81a99", "529608c61cd85236", "72157622141823959-460ef5327a4ad8d5");
            public FriendPanel(MapBGFrom map)
            {
                this.mp = map;
                InitializeComponent();
                
            }

            private void btn_getFriends_Click(object sender, EventArgs e)
            {

                this.pictureBox1.Image = new Bitmap("Storage Card\\Images\\image\\backgroundhyc07.jpg");
                mp.FriendShow();
            }

            private void menuItem1_Click(object sender, EventArgs e)
            {
                //this.Close();
            }

            private void FriendForm_Load(object sender, EventArgs e)
            {

            }


            #region Windows 窗体设计器生成的代码

            /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FriendForm));
                this.txt_userName = new System.Windows.Forms.TextBox();
                this.btn_getFriends = new System.Windows.Forms.Button();
                this.lbl_friends = new System.Windows.Forms.Label();
                this.mainMenu1 = new System.Windows.Forms.MainMenu();
                this.menuItem1 = new System.Windows.Forms.MenuItem();
                this.menuItem2 = new System.Windows.Forms.MenuItem();
                this.SuspendLayout();
                // 
                // txt_userName
                // 
                this.txt_userName.AcceptsReturn = true;
                this.txt_userName.AcceptsTab = true;
                this.txt_userName.BackColor = System.Drawing.SystemColors.InactiveBorder;
                this.txt_userName.ForeColor = System.Drawing.SystemColors.InactiveCaptionText;
                this.txt_userName.Location = new System.Drawing.Point(39 * mp.x/240, 36 * mp.y/290);
                this.txt_userName.Multiline = true;
                this.txt_userName.Name = "txt_userName";
                this.txt_userName.Size = new System.Drawing.Size(100 * mp.x/240, 21 * mp.y/290);
                this.txt_userName.TabIndex = 0;
                // 
                // btn_getFriends
                // 
                this.btn_getFriends.Location = new System.Drawing.Point(39 * mp.x/240, 74 * mp.y/290);
                this.btn_getFriends.Name = "btn_getFriends";
                this.btn_getFriends.Size = new System.Drawing.Size(100 * mp.x/240, 23 * mp.y/290);
                this.btn_getFriends.TabIndex = 1;
                this.btn_getFriends.Text = "GetFriend";
                this.btn_getFriends.Click += new System.EventHandler(this.btn_getFriends_Click);
                // 
                // lbl_friends
                // 
                this.lbl_friends.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
                this.lbl_friends.Location = new System.Drawing.Point(39 * mp.x/240, 123 * mp.y/290);
                this.lbl_friends.Name = "lbl_friends";
                this.lbl_friends.Size = new System.Drawing.Size(164 * mp.x/240, 114 * mp.y/290);
                this.lbl_friends.Text = " ";
                this.lbl_friends.Visible = false;
                // 
                // mainMenu1
                // 
                this.mainMenu1.MenuItems.Add(this.menuItem1);
                this.mainMenu1.MenuItems.Add(this.menuItem2);
                // 
                // menuItem1
                // 
                this.menuItem1.Text = "Back";
                this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
                // 
                // menuItem2
                // 
                this.menuItem2.Text = "Menu";
                //closeButton
                //this.closeButton.ButtonImage=""
                // 
                // FriendForm
                // 
                //this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
                //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
                this.AutoScroll = true;
                //this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
                pictureBox1.Image = new Bitmap("Storage Card\\Images\\image\\background.jpg");
                pictureBox1.Size = new System.Drawing.Size(242 * mp.x/240, 150 * mp.y/290);
                this.Controls.Add(pictureBox1);
                this.Size = new System.Drawing.Size(242 * mp.x/240, 150 * mp.y/290);
                this.Location = new Point(0, 135 * mp.y/290);
                this.Controls.Add(this.lbl_friends); lbl_friends.BringToFront();
                this.Controls.Add(this.btn_getFriends); btn_getFriends.BringToFront();
                this.Controls.Add(this.txt_userName); txt_userName.BringToFront();
                //this.Menu = this.mainMenu1;
                this.Name = "FriendForm";
                //this.StretchImage = true;
                this.Text = "FriendForm";
                //this.Load += new System.EventHandler(this.FriendForm_Load);
                this.ResumeLayout(false);

            }

            #endregion
            //private XTransMobile.XTImageButton closeButton;
            private System.Windows.Forms.TextBox txt_userName;
            private System.Windows.Forms.Button btn_getFriends;
            private System.Windows.Forms.Label lbl_friends;
            private System.Windows.Forms.MenuItem menuItem1;
            private System.Windows.Forms.MenuItem menuItem2;
            private System.ComponentModel.IContainer components = null;
            private System.Windows.Forms.MainMenu mainMenu1;
            private System.Windows.Forms.PictureBox pictureBox1=new PictureBox();

            /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源，为 true；否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
        }

    }




    
}