private void selectProduct(int id)
        {
            if (animating || id == currentProduct)
            {
                return;
            }
            animating      = true;
            currentProduct = id;
            Storyboards.Fade(productImages[lastProduct], FadeTime, 0.5, 1, null);
            Storyboards.FadeOut(centerGrid, FadeTime / 2, fadeInNewProduct);
            setUsersImage();
            if (currentProduct == 0)
            {
                Storyboards.FadeIn(assetImages[0], AppearTime, null);
            }

            for (int i = 2; i < NrOfAssets; i++)
            {
                bool hasFeature = ProductFeatures[currentProduct][i - 2];
                assetImages[i].Source  = hasFeature ? colorAssetSource[i] : grayAssetSource[i];
                assetImages[i].Opacity = hasFeature ? 1.0 : GrayedOpacity;
            }

            setInfoBoxText(id);
            showAssets();
            waveAssets();

            lastProduct = currentProduct;
            Storyboards.Fade(productImages[currentProduct], FadeTime, 1, 0.5, doneAnimating);
        }
 private void hideVideo(object sender, object e)
 {
     video.Visibility = Visibility.Collapsed;
     updatePositions();
     Storyboards.FadeIn(homeButton, AppearTime, splitCenterGrids);
     Storyboards.FadeIn(infoIcon, AppearTime, null);
 }
 private void fadeInNewProduct(object sender, object e)
 {
     productImage.Source = productImages[currentProduct].Source;
     productTitle.Text   = productName[currentProduct];
     setProductHeader();
     Storyboards.FadeIn(centerGrid, FadeTime / 2, null);
 }
 private void hideFeaturesDetails(object sender, TappedRoutedEventArgs e)
 {
     Storyboards.DissapearBottom(featuresDetails, AppearTime, collapseFeaturesDetails);
     useScaleTargets     = true;
     featuresDetailsMode = false;
     Storyboards.FadeIn(aUsersText, FadeTime, null);
     Storyboards.FadeIn(aDeviceText, FadeTime, null);
     aDevice.Source = singleDevice;
     showAssets();
 }
        private void showQuestion(int id)
        {
            //Debug.WriteLine("Show Question Animation.");

            animating  = true;
            questionId = id;
            questionTextBlock.Opacity = 0;
            questionTextBlock.Text    = questionText[id];
            Storyboards.FadeIn(questionTextBlock, AnswerPopInTime, popInAnswers);
            infoBox.Title        = infoBoxTitle[id];
            infoBox.Description  = infoBoxDescription[id];
            button_click_numbers = 0;
        }
        private void moveCenterGridUp(object sender, object e)
        {
            videoClosed = true;
            double toX = 0;
            double toY = -App.Height * yShift;

            Storyboards.MoveXY(video, AppearTime, 0, 0, toX, toY, hideVideo);
            Storyboards.MoveXY(centerGrid, AppearTime, 0, 0, toX, toY, null);
            Storyboards.MoveXY(subscriptionVsOneTimeGrid, AppearTime, 0, 0, toX, toY, null);
            productsPanel.Visibility = Visibility.Visible;
            Storyboards.MoveX(productsPanel, App.ProductStackPanelWidth, 0, AppearTime, null);
            Storyboards.FadeIn(whatsIncludedBtn, AppearTime, null);
            showAssets();
        }
        private void splitCenterGrids(object sender, object e)
        {
            centerGridAnimating   = true;
            centerGridShowCompare = true;
            double toX = -App.Width * xShift;
            double toY = -App.Height * yShift;

            Storyboards.MoveXY(subscriptionVsOneTimeGrid, CenterGridSplitTime, 0, toY, -toX * xShiftCompareFactor, toY, finishCenterGridAnimation);
            if (useScalingOnCenterGridAnimation)
            {
                Storyboards.MoveXYAndScale(centerGrid, CenterGridSplitTime, 0, toY, toX, toY, CenterGridScaleUp, CenterGridScaleUpTime, null);
            }
            else
            {
                Storyboards.MoveXY(centerGrid, CenterGridSplitTime, 0, toY, toX, toY, null);
            }
            Storyboards.FadeIn(subscriptionVsOneTimeGrid, CenterGridSplitTime, null);
        }
 private void hideInfoBox(object sender, TappedRoutedEventArgs e)
 {
     Storyboards.FadeOut(infoBox, AppearTime, collapseInfoBox);
     Storyboards.FadeIn(infoIcon, AppearTime, null);
     infoIcon.Visibility = Visibility.Visible;
 }
 private void fadeInCompareChart(object sender, object e)
 {
     comparisonGridHP.Visibility       = Visibility.Collapsed;
     comparisonGrid365_2016.Visibility = Visibility.Collapsed;
     Storyboards.FadeIn(comparisonChart, AppearTime, finishCompareTransition);
 }
        private void showAssetDetails(object sender, TappedRoutedEventArgs e)
        {
            if (featuresDetailsMode)
            {
                return;
            }
            Storyboards.FadeIn(featuresDetails, AppearTime / 2, showProductiInfoGrid);
            Storyboards.AppearBottom(featuresDetails, AppearTime / 2, null);
            learnMore365Button.Opacity = 0;
            productInfoGrid.Opacity    = 0;

            featuresDetailsMode = true;
            useScaleTargets     = true;
            Storyboards.FadeOut(aUsersText, FadeTime, null);
            Storyboards.FadeOut(aDeviceText, FadeTime, null);

            // TODO Rework this section
            for (int i = 0; i < NrOfAssets; i++)
            {
                var    transform = assetDummy[i].TransformToVisual(Window.Current.Content);
                Point  absolutePosition = transform.TransformPoint(new Point(0, 0));
                double ff = 1.0, xoff = 0;
                double size       = App.AssetDummySize;
                double originSize = aImgSize;
                if (i == 0)   // Ignore?
                {
                    size = App.AssetDummySizeUser;
                    xoff = size * 0.2;
                    ff   = 0.85;
                }
                else if (i == 1)
                {
                    size = App.AssetDummySizeDevice * 1.2;
                    xoff = currentProduct > 1 ? 0: size * 0.1;
                    ff   = 0.75;
                }
                double scale = size / originSize;
                xyScaleTargets[i].X = scale;
                xyScaleTargets[i].Y = scale;
                xyTargets[i].X      = absolutePosition.X + (scale - 1.0) * size / 4 + xoff;
                xyTargets[i].Y      = -App.Height + absolutePosition.Y + size * ff;
            }

            double x = xyTargets[1].X;

            if (currentProduct == 1)
            {
                x *= 0.75;
            }
            else if (currentProduct == 0)
            {
                x *= 0.9;
            }
            xyTargets[0].X = x;
            xyTargets[0].Y = xyTargets[1].Y - App.AssetDummySizeDevice / 1.7;

            loadSources();
            if (currentProduct == 0)
            {
                aDevice.Source = homeDevices;
                homeDevices.Stop();
                homeDevices.Play();
            }
            else if (currentProduct == 1)
            {
                aDevice.Source = personalDevices;
                personalDevices.Stop();
                personalDevices.Play();
            }
            else
            {
                aDevice.Source = singleDevice;
                singleDevice.Stop();
                singleDevice.Play();
            }
        }
 private void showProductiInfoGrid(object sender, object e)
 {
     Storyboards.FadeIn(learnMore365Button, AppearTime, null);
     Storyboards.FadeIn(productInfoGrid, AppearTime, null);
 }
        private void Timer_Tick(object sender, object e)
        {
            if (!videoClosed && stopwatch.ElapsedMilliseconds > StartVideoCloseAt && !centerGridAnimating)
            {
                stopwatch.Stop();
                centerGridAnimating = true;
                Storyboards.FadeIn(centerGrid, AppearTime, moveCenterGridUp);
            }

            if (videoClosed)
            {
                bool snapScale = false;
                for (int i = 0; i < NrOfAssets; i++)
                {
                    CompositeTransform ct = assetImages[i].RenderTransform as CompositeTransform;
                    ct.TranslateX += (xyTargets[i].X - ct.TranslateX) / AnimDivider;
                    ct.TranslateY += (xyTargets[i].Y - ct.TranslateY) / AnimDivider;
                    if (useScaleTargets)
                    {
                        ct.ScaleX += (xyScaleTargets[i].X - ct.ScaleX) / AnimDivider;
                        ct.ScaleY += (xyScaleTargets[i].Y - ct.ScaleY) / AnimDivider;
                        if (Math.Abs(xyScaleTargets[i].X - ct.ScaleX) < 0.02)
                        {
                            snapScale = true;
                        }
                    }
                }

                if (snapScale)
                {
                    useScaleTargets = false;
                    for (int i = 0; i < NrOfAssets; i++)
                    {
                        CompositeTransform ct = assetImages[i].RenderTransform as CompositeTransform;
                        ct.ScaleX = xyScaleTargets[i].X;
                        ct.ScaleY = xyScaleTargets[i].Y;
                    }
                }

                updateUserDeviceTexts();

                if (cgMoving)
                {
                    //dbg("cgMoving {0},{1} to {2},{3}", (int)cgTransform.TranslateX, (int)cgTransform.TranslateY, (int)cgTargetX, (int)cgTargetY);
                    if (Math.Abs(cgTargetX - cgTransform.TranslateX) < 1.0 && Math.Abs(cgTargetY - cgTransform.TranslateY) < 1.0)
                    {
                        dbg("cgMoving = false - snapped");
                        cgMoving = false;
                        cgTransform.TranslateX = cgTargetX;
                        cgTransform.TranslateY = cgTargetY;
                    }
                    else
                    {
                        dbg("cgTransformXY = {0},{1}", (int)cgTransform.TranslateX, (int)cgTransform.TranslateY);
                        cgTransform.TranslateX += (cgTargetX - cgTransform.TranslateX) / AnimDivider;
                        cgTransform.TranslateY += (cgTargetY - cgTransform.TranslateY) / AnimDivider;
                        centerGrid.UpdateLayout();
                    }
                }

                if (cgTransform != null)
                {
                    cgTransform.Rotation += (cgTargetRotation - cgTransform.Rotation) / AnimDivider;
                }
            }
        }
        private void cgReleased(object sender, PointerRoutedEventArgs e)
        {
            dbg("Release - enter");

            if (dragging)
            {
                centerGrid.ReleasePointerCapture(e.Pointer);
                e.Handled = true;
                dragging  = false;
                dbg("Release - dragging handled");
            }
            else
            {
                dbg("Release - not dragging - return");
                return;
            }

            if (centerGridAnimating)
            {
                dbg("Release - return: move = " + cgMoving + " / animate = " + centerGridAnimating);
                return;
            }
            PointerPoint pp = e.GetCurrentPoint(this);

            cgTargetRotation = 0;
            dbg("Release - is move || animate");

            if (startX == pp.Position.X && startY == pp.Position.Y)
            {
                dbg("Release - toggle and return");
                toggleCenterGrid();
                return;
            }

            CompositeTransform ct  = centerGrid.RenderTransform as CompositeTransform;
            double             toX = -App.Width * xShift;
            double             toY = -App.Height * yShift;

            centerGridAnimating = true;
            cgMoving            = true;
            dbg("Release - compare = " + centerGridShowCompare);
            if (centerGridShowCompare)
            {
                Storyboards.MoveXY(subscriptionVsOneTimeGrid, CenterGridSplitTime, -toX * xShiftCompareFactor, toY, 0, toY, null);
                Storyboards.FadeOut(subscriptionVsOneTimeGrid, CenterGridSplitTime, finishCenterGridAnimation);
                dbg("Release - cgTargetX = " + cgTargetX);

                /*if (cgTransform != null && Math.Abs(cgTargetX) < 5) {
                 *  dbg("Release Point - set TranslateX" + toX);
                 *  cgTransform.TranslateX = toX;
                 *  cgTransform.TranslateY = toY;
                 * }*/
                cgTargetX             = 0;
                cgTargetY             = toY;
                centerGridShowCompare = false;
                dbg("Release - hide compare");
            }
            else
            {
                Storyboards.MoveXY(subscriptionVsOneTimeGrid, CenterGridSplitTime, 0, toY, -toX * xShiftCompareFactor, toY, null);
                Storyboards.FadeIn(subscriptionVsOneTimeGrid, CenterGridSplitTime, finishCenterGridAnimation);
                dbg("Release - cgTargetX = " + cgTargetX);

                /*if (cgTransform != null && Math.Abs(cgTargetX) < 5) {
                 *  dbg("Release Point - set TranslateX = 0");
                 *  cgTransform.TranslateX = 0;
                 *  cgTransform.TranslateY = toY;
                 * }*/
                cgTargetX             = toX;
                cgTargetY             = toY;
                centerGridShowCompare = true;
                dbg("Release - show compare");
            }
        }
        public ProductPage()
        {
            Debug.WriteLine("Production Page.");

            this.InitializeComponent();
            this.Width  = Double.NaN;
            this.Height = Double.NaN;

            for (int i = 0; i < 6; i++)
            {
                string str = (i + 1).ToString();
                productName[i] = App.ResourceLoader.GetString("Product" + str);
                productInfoBoxDescription[i] = App.ResourceLoader.GetString("ProductInfoDescription" + str);
                productInfoBoxName[i]        = App.ResourceLoader.GetString("ProductTitle" + str);
                productDeviceInfo[i]         = App.ResourceLoader.GetString("ProductDeviceInfo" + str);
                productDeviceTitle[i]        = App.ResourceLoader.GetString("ProductDeviceTitle" + str);
            }

            assetDummy      = new Image[] { dummyUsers, dummyDevice, aDummy1, aDummy2, aDummy3, aDummy4, aDummy5, aDummy6, aDummy7, aDummy8, aDummy9, aDummy10 };
            comparisonGrids = new Grid[] { comparisonGrid0, comparisonGrid1, comparisonGrid3, comparisonGrid2, comparisonGrid5, comparisonGrid4 };
            //comparisonImages = new Image[] { comparisonImage0, comparisonImage1, comparisonImage2, comparisonImage3, comparisonImage4, comparisonImage5 };
            productImages    = new Image[] { pImg1, pImg2, pImg3, pImg4, pImg5, pImg6 };
            assetImages      = new Image[] { aUsers, aDevice, aImg1, aImg2, aImg3, aImg4, aImg5, aImg6, aImg7, aImg8, aImg9, aImg10 };
            NrOfAssets       = assetImages.Length;
            NrOfProducts     = productName.Length;
            xyTargets        = new Point[NrOfAssets];
            xyScaleTargets   = new Point[NrOfAssets];
            colorAssetSource = new ImageSource[NrOfAssets];
            grayAssetSource  = new ImageSource[NrOfAssets];

            for (int i = 0; i < NrOfAssets; i++)
            {
                colorAssetSource[i] = assetImages[i].Source;
                if (i >= 2)
                {
                    grayAssetSource[i] = (ImageSource)Application.Current.Resources["GrayAsset" + (i - 1)];
                }
                assetDummy[i].Opacity          = 0.0;
                assetImages[i].RenderTransform = new CompositeTransform();
                assetImages[i].Tag             = i;
                xyTargets[i]      = new Point();
                xyScaleTargets[i] = new Point(1, 1);
            }

            homeButton.Opacity       = 0;
            infoIcon.Opacity         = 0;
            whatsIncludedBtn.Opacity = 0;
            video.Opacity            = 0;
            centerGrid.Opacity       = 0;
            productsPanel.Visibility = Visibility.Collapsed;

            centerVideo();
            video.Source = MediaSource.CreateFromUri(new Uri((String)Application.Current.Resources["CircleFlipVideo"]));
            mediaplayer  = video.MediaPlayer;
            mediaplayer.Play();

            timer.Interval = TimeSpan.FromMilliseconds(Interval);
            timer.Tick    += Timer_Tick;
            timer.Start();

            if (App.SelectedProduct >= 0)
            {
                currentProduct = App.SelectedProduct;
                lastProduct    = currentProduct;
            }
            productImage.Source = productImages[currentProduct].Source;
            productTitle.Text   = productName[currentProduct];
            productImages[currentProduct].Opacity = 0.5;
            setProductHeader();
            setUsersImage();

            infoBox.Visibility = Visibility.Collapsed;
            setInfoBoxText(currentProduct);

            subscriptionVsOneTimeGrid.Opacity = 0;

            App.productsPage = this;
            updatePositions();
            initAssets();

            // Slide in grids animation preparation / workaround
            assetDetails.Opacity    = 0;
            assetDetails.Visibility = Visibility.Visible;
            Storyboards.DissapearRight(assetDetails, restoreOpacity);
            comparisonGrid.Opacity    = 0;
            comparisonGrid.Visibility = Visibility.Visible;
            Storyboards.DissapearRight(comparisonGrid, null);
            featuresDetails.Opacity    = 0;
            featuresDetails.Visibility = Visibility.Visible;
            Storyboards.DissapearBottom(featuresDetails, 100, null);

            // Fade in video
            Storyboards.FadeIn(video, AppearTime * 2, null);
            if (FadeoutCircle)
            {
                Storyboards.FadeOut(questionCircle, AppearTime, null);
            }
            else
            {
                questionCircle.Opacity = 0;
            }
            FadeoutCircle = false;
        }
 private void infoImage_Tapped(object sender, TappedRoutedEventArgs e)
 {
     infoBox.Visibility = Visibility.Visible;
     infoBox.Opacity    = 0;
     Storyboards.FadeIn(infoBox, AnswerPopInTime, null);
 }