//Detects placeholders and doubles sites appropriately
        public HitTestResultBehavior sitesCallback(HitTestResult result)
        {
            if (result.VisualHit.GetType() == typeof(Grid))
            {
                Grid gridResult = (Grid)result.VisualHit;
                if (gridResult.Name == "sitesGrid" && ((Sites)gridResult.Parent).Sequence != "aatg")
                {
                    //add fusion site check

                    //Copy data into target Site
                    Sites target = (Sites)gridResult.Parent;
                    target.copySitesInfoFrom(this);

                    //Find and define neighbor Site
                    StackPanel parentPanel = (StackPanel)target.Parent;
                    int        targetIndex = pd2.PD2_manual.Children.IndexOf(target);

                    //catch bug when element returned is not a Sites object
                    object childElement = VisualTreeHelper.GetChild(parentPanel, neighborSiteIndex(targetIndex, parentPanel));

                    if (childElement is Sites)
                    {
                        Sites neighbor = (Sites)childElement;
                        neighbor.copySitesInfoFrom(this);
                    }
                    return(HitTestResultBehavior.Stop);

                    //if (targetIndex == 0)
                    //{ //If dropped into the first
                    //    Sites afterTarget = (Sites)VisualTreeHelper.GetChild(parentPanel, targetIndex + 1);
                    //    afterTarget.copySitesInfoFrom(this);
                    //}
                    //else if (targetIndex == pd2.PD2_manual.Children.Count - 1)
                    //{ //If dropped into the last
                    //    Sites beforeTarget = (Sites)VisualTreeHelper.GetChild(parentPanel, targetIndex - 1);
                    //    beforeTarget.copySitesInfoFrom(this);
                    //}
                    //else
                    //{ //if dropped into the in-between
                    //    if (VisualTreeHelper.GetChild(parentPanel, targetIndex - 1).GetType() == typeof(Sites))
                    //    { //If element in front is a Sites
                    //        Sites beforeTarget = (Sites)VisualTreeHelper.GetChild(parentPanel, targetIndex - 1);
                    //        beforeTarget.copySitesInfoFrom(this);
                    //    }
                    //    else
                    //    { //If element behind is a Sites
                    //        Sites afterTarget = (Sites)VisualTreeHelper.GetChild(parentPanel, targetIndex + 1);
                    //        afterTarget.copySitesInfoFrom(this);
                    //    }
                    //}
                }
            }
            return(HitTestResultBehavior.Continue);
        }
        private void permMaker_Click(object sender, RoutedEventArgs e)
        {
            permMaker.IsEnabled = false;

            try
            {
                //Set usedSites to empty List and clear all Sites if necessary
                usedSites = new List <int>();
                foreach (UIElement elem in PD2_auto.Children)
                {
                    if (elem.GetType() == typeof(Sites))
                    {
                        ((Sites)elem).copySitesInfoFrom(new Sites());
                    }
                }

                foreach (UIElement elem in PD2_auto.Children)
                {
                    //If the element is Sites and an empty placeholder
                    if (elem.GetType() == typeof(Sites))
                    {
                        if (((Sites)elem).Sequence == "site")
                        {
                            //Get a random index and checks if it's already used
                            int randIndex = (new Random()).Next(0, PD2_siteLibrary.Items.Count);
                            while (usedSites.Contains(randIndex))
                            {
                                randIndex = (new Random()).Next(0, PD2_siteLibrary.Items.Count);
                            }

                            //Copy in data from a random Site in the library
                            Sites current = (Sites)elem;
                            current.copySitesInfoFrom((Sites)PD2_siteLibrary.Items.GetItemAt(randIndex));

                            //Double the Site
                            int   nextIndex = PD2_auto.Children.IndexOf(current) + 1;
                            Sites next      = (Sites)VisualTreeHelper.GetChild(PD2_auto, nextIndex);
                            next.copySitesInfoFrom(current);

                            usedSites.Add(randIndex);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            permMaker.IsEnabled = true;
        }