package rainbowPackage;

import java.io.File;

import org.jcodec.common.io.SeekableByteChannel;

/*import java.nio.channels.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintWriter;

import javax.imageio.ImageIO;

import java.io.*;

import org.jcodec.api.SequenceEncoder;
import org.jcodec.api.SequenceEncoder.*;
import org.jcodec.api.awt.AWTSequenceEncoder;
import org.jcodec.common.Codec;
import org.jcodec.common.Format;
import org.jcodec.common.io.NIOUtils;

import org.jcodec.common.model.Rational;
import org.jcodec.scale.AWTUtil;
import org.jcodec.api.*;

//import java.nio.channels.SeekableByteChannel;
import org.jcodec.*;//Keep For .mp4 Video Creation */

import java.awt.*;
//import java.awt.image.*;
import java.util.Set;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener.Change;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
//import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.Label;
import javafx.scene.*;
import javafx.scene.image.*;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Screen;
import javafx.stage.Stage;

/*import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.IOException;// */

public class RainbowSystem
{
	/*Screen screen = Screen.getPrimary();
	Rectangle2D bounds = screen.getVisualBounds();
	Dimension dimension = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight() );
	Dimension Dim = dimension;
	SnapshotParameters sP = new SnapshotParameters();
	WritableImage secondaryBufferPicture = new WritableImage( Dim.width, Dim.height );
	WritableImage nextTextPicture = new WritableImage( Dim.width, Dim.height ), secondaryBufferPicture = new WritableImage( Dim.width, Dim.height );
	Image origionalBrowserImage = null;
	PixelReader origionalpr = origionalBrowserImage.getPixelReader();
	PixelWriter origionalpw = secondaryBufferPicture.getPixelWriter();
	ImageView origionalImageView = new ImageView();
	PixelReader basispr = null;
	WritableImage secondaryWritableImage = nextTextPicture; //USE FOR ???
	PixelReader pr = secondaryWritableImage.getPixelReader();
	PixelWriter secondaryPW = secondaryWritableImage.getPixelWriter();
	ImageView secondaryImageView = new ImageView();
	double secondaryNumberOfScrollFrames = 9999;//Testing 2; Normally 11;
	ColorSlider black = new ColorSlider( new double[]{0,0,0} );
	//ColorSlider color = black;
	Diagnostics diagnostics = null;
	RainbowSoftColor color = new RainbowSoftColor( new double[]{0,0,0,1} );//????????????????????????????
	RainbowPattern2D pattern2D = new RainbowPattern2D( new double[]{0,0,0,1} );
	RainbowSoft2D rainbowSoft2D = new RainbowSoft2D( new double[]{0,0,0,1} );
	TransparencySlider transparencySlider = new TransparencySlider( new double[]{0,0,0,1} );
	RainbowSoftColor rainbowSoftColor = new RainbowSoftColor( new double[]{0,0,0,1} );
	Color tempFXColor = Color.BLACK;
	TransparencySlider redTransparencySlider = new TransparencySlider( new double[]{193,0,0,1} );
	TransparencySlider blueTransparencySlider = new TransparencySlider( new double[]{0,0,192,1} );
	String typeOfDisplay = "FullDisplay";
	Color colorTooSimilarReplacementColor = Color.color( 0., 1., 0., 1. );
	double colorDifference = 164.;
	ColorTooSimilar neonGreenCheck = new ColorTooSimilar();
	int numberOfColorsInTheRainbow = 7;//asdf Always Worry About This!
	int x = 0, y = 0;
	double xSlider = 0; //MUST START OUT AS 0 Or Else Video Won't Produce Or Potentially Scroll At All!
	Dimension HalfedDim = new Dimension();
	//double radialDistance = Math.pow(Math.pow(HalfedDim.width + 1, 2) + Math.pow(HalfedDim.height + 1, 2), 0.5);
	double halfSreenDiagionalLength = Math.pow(Math.pow( HalfedDim.getWidth(), 2) + Math.pow( HalfedDim.getHeight(), 2), 0.5);
	//double radialDistance = Math.pow(Math.pow(HalfedDim.width, 2) + Math.pow(HalfedDim.height, 2), 0.5);//HalfedDim.width + 1 HalfedDim.height + 1
	double fullAngle = Math.PI * halfSreenDiagionalLength;
	//double archimedesZoomFactor = 1;
	//int varGradAdjGradChoiceNum = 0;//Variated = 0, Graduated = 1, Adjusted-Graduated = 2
	//double fullAngle = Math.PI * radialDistance;
	//double sliderInterval = fullAngle / SecondFRateDivisor;// / 10 For Rainbow Spotlight Last Division Determines The Frame Rate
	SeekableByteChannel SecondaryVideoOut = null;
	RainbowVideo rainbowVideo = null;// */

	public static void System (Stage SecondaryStage, Image SecondaryBasisImage, Image SecondaryBackgroundBasisImage, WebEngine SecondBrowserEngine, WebView SecondBrowser, StackPane SecondStackPane, Scene SecondScene, Screen SecondScreen,
			double SecondFRateDivisor, Label SecondStateLabel, File SecondFile, File SecondJavaScriptFile, File SecondXSliderFile, Thread SecondaryThread, boolean SecondaryIsFullScreened,
			Image SecondaryBackupWorkAroundImage, Parent SecondaryRoot)//SequenceEncoder SecondEnc, Image SecondBackupWorkAroundImage, 
	{
		System.out.println("Got To The Top Of Worker");
		/*SecondaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>()
		{
			@Override
			public void handle(MouseEvent event)
			{
				System.exit(0);
			}
		});// */
		//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
		/*try ( PrintWriter out = new PrintWriter(SecondJavaScriptFile.getPath() ) )
		{

			out.println("function scrollContinuously( timeInterval )\r\n" + 
					"{\r\n" + 
					"	timeInterval = 444;\r\n" + 
					"	window.setInterval( scrollWin, timeInterval );\r\n" + 
					"}\r\n" + 
					"function scrollWin()\r\n" + 
					"{\r\n" + 
					"    window.scrollBy( 0, 0 );\r\n" + 
					"}");
			out.close();
		}
		catch(IOException ie) { ie.printStackTrace(); }// Important For Browser AutoScrolling */


		/*SecondaryStage.fullScreenProperty().addListener((observable, oldValue, newValue) -> {
			if ( newValue != SecondaryStage.isFullScreen() )
			{
				SecondaryStage.setFullScreen(SecondaryIsFullScreened);
				//SecondaryStage.setWidth( primaryBounds.getWidth() );
				// SecondaryStage.setHeight( SecondaryBounds.getHeight() );
				return;
			}
			else
				return;
		});// Important For Full Screened */

		/*SecondaryStage.fullScreenProperty().addListener((observable, oldValue, newValue) -> {
			if ( newValue == SecondaryStage.isFullScreen() )
			{
				SecondaryStage.setFullScreen(SecondaryIsFullScreened);
				SecondaryStage.setWidth( SecondScreen.getBounds().getWidth() );
				SecondaryStage.setHeight( SecondScreen.getBounds().getHeight() );
				return;
			}
			else
				return;
		});// Important For Not Full Screened */

		System.out.println("Got In Worker Past Full Screening");
		// This is how you know how much screen you can write to.
		Screen screen = Screen.getPrimary();
		Rectangle2D bounds = screen.getVisualBounds();
		System.out.println(bounds);

		//SecondaryStage.setMaximized(true);
		//SecondaryStage.setFullScreen(true); Improtant For Full Screened
		//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
		Dimension dimension = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight() );
		//Dimension dimension = new Dimension( 666, 888 );// 666, 888
		//dimension.width = (int)bounds.getWidth();// All Around Here Important For Full Screened
		//dimension.height = (int)bounds.getHeight();// + 40;
		Dimension Dim = dimension;// */

		//Dimension Dim = new Dimension();
		//Dim.width = (int)SecondaryStage.getWidth(); // Important For Full Screened
		//Dim.height = (int)SecondaryStage.getHeight();// + 40; // Important For Full Screened Without + 40
		//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
		try { SecondaryThread.sleep(2000);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */
		SecondaryStage.setFullScreen(SecondaryIsFullScreened);
		SecondaryStage.setTitle(SecondBrowser.getEngine().getLocation());
		SecondStateLabel.setText("Finish!");
		//SequenceEncoder enc = new SequenceEncoder(SecondFile);
		//try { SequenceEncoder enc = new SequenceEncoder(SecondFile); }
		//catch (IOException e) {	throw new RuntimeException(e); }//*/

		try { SecondaryThread.sleep(500);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */

		if ( SecondaryIsFullScreened == false )
		{
			SecondBrowser.autosize();
			SecondBrowser.resize( 666, 888 );
		}
		SnapshotParameters sP = new SnapshotParameters();
		//sP.setViewport( new Rectangle2D(-8, -19, 666, 888 ) );
		//SecondBrowser.resizeRelocate( -8, -19, 666, 888 );

		//WritableImage origionalTextPicture = new WritableImage( Dim.width, Dim.height );
		WritableImage secondaryBufferPicture = new WritableImage( Dim.width, Dim.height );
		WritableImage secondaryBufferPictureForBrowser = new WritableImage( Dim.width, Dim.height );
		WritableImage secondaryBufferPictureForBrowserTransitionImage = new WritableImage( Dim.width, Dim.height );
		//WritableImage secondaryBufferPictureForBrowser = new WritableImage( Dim.width, Dim.height );//nextTextPicture = new WritableImage( Dim.width, Dim.height ), 
		//origionalTextPicture = SecondBrowser.snapshot(null, secondaryBufferPicture);
		//SecondBrowser.snapshot(sP, secondaryBufferPicture);
		SecondaryStage.show();
		//SecondBrowser.snapshot(sP, nextTextPicture);
		/*//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//browser.snapshot(sP, nextTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
			//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Test.png");//browser.snapshot(sP, nextTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
			stackPane[0].getChildren().add(browser);

			scene[0] = new Scene(stackPane[0]);
			SecondaryStage.setScene(scene[0]);

			SecondaryStage.setFullScreen(true);
			SecondaryStage.show();

			//boolean encFinished = false;
			//while (encFinished =  false)
				//if ( stateLabel.getText() == "Finish!")//SecondaryStage.isShowing() && SecondaryStage.isFullScreen() )
				//{*/
		//SecondStackPane[0].getChildren().add(SecondBrowser);
		//Image origionalBrowserImage = SecondaryBackupWorkAroundImage;
		//Image origionalBrowserImage = SecondBrowser.snapshot(sP, nextTextPicture);		/*sP.setViewport(SecondScreen.getBounds());
		//SecondStackPane[0] = new StackPane();
		//while ( SecondBrowser.isVisible() == false )//fdsa
		//try { SecondaryThread.wait();
		//} catch (InterruptedException e) {
		//	System.out.println("Interrupted.");
		//}
		//SecondStackPane[0].getChildren().add(SecondBrowser);//For Browser Only
		//SecondScene[0] = SecondStackPane[0].getScene(); //For Rainbow Browser Durability //HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE 
		//SecondScene[0] = new Scene(SecondStackPane[0]); //For Rainbow Browser Durability
		//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
		//while ( SecondBrowser.isVisible() && SecondaryStage.isShowing() )//fdsa
		//	try {

		//double xSlider = 0; //MUST START OUT AS 0 Or Else Video Won't Produce Or Potentially Scroll At All!
		SecondBrowser.autosize();

		//SecondBrowser.resize(1080, 1930 );
		System.out.println("Got To Main Listener");
		SecondBrowserEngine.getLoadWorker().stateProperty().addListener(
				new ChangeListener<Object>() {
					public void changed(ObservableValue observable, Object oldValue, Object newValue) {
						SecondaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>()
						{
							@Override
							public void handle(MouseEvent event) 
							{
								System.exit(0);
							}
						});
						System.out.println("oldValue: " + oldValue);
						System.out.println("newValue: " + newValue);
						//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
						if (newValue == Worker.State.SUCCEEDED) {
							//document finished loading
							System.out.println("Worker State:" + Worker.State.values());
							//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
							System.out.println("Worked Till After Here");
							//sP.setViewport(SecondScreen.getBounds());
							//sP.setViewport( new Rectangle2D(-8, -19, 666, 888 ) );
							//SecondStackPane[0] = new StackPane();
							//while ( SecondBrowser.isVisible() == false )//fdsa
							//try { SecondaryThread.wait();
							//} catch (InterruptedException e) {
							//	System.out.println("Interrupted.");
							//}
							SecondStackPane.getChildren().add(SecondBrowser);
							//SecondScene[0] = SecondStackPane[0].getScene(); //For Rainbow Browser Durability
							//SecondScene[0] = new Scene(SecondStackPane[0]);  //For Rainbow Browser Durability
							//SecondaryStage.setFullScreen(SecondaryIsFullScreened);
							SecondaryStage.show();
							System.out.println("Worked Till After 1.5");
							//origionalBrowserImage = SecondBrowser.snapshot(sP, nextTextPicture);
							//Image secondaryCurrentBrowserImage = origionalBrowserImage;// !!!!! Uncomment To Show Video !!!!!
							System.out.println("Worked Till After 1.6");
							//origionalBrowserImage = SecondScene[0].snapshot(nextTextPicture);
							//origionalBrowserImage = SecondStackPane[0].getScene().snapshot(secondaryBufferPicture);
							//SecondaryStage.setScene(SecondScene[0]); //For Rainbow Browser
							System.out.println("Worked Till After 1.7");
							////SecondaryStage.setFullScreen(SecondaryIsFullScreened);
							System.out.println("Worked Till After 1.8");
							/*try { SecondaryThread.sleep(4000);
							} catch (InterruptedException e) {
								System.out.println("Interrupted.");
							}// */
							SecondaryStage.show();// !!!!! Uncomment To Show Video !!!!!
							//origionalBrowserImage = SecondBrowser.snapshot(sP, secondaryBufferPicture);
							System.out.println("Got Stopped Up Show Command In");
							//origionalBrowserImage = SecondBrowser.snapshot(sP, secondaryBufferPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");
							//secondaryCurrentBrowserImage = origionalBrowserImage;// !!!!! Uncomment To Show Video !!!!!
							///TEST
							//SecondStackPane[0].getChildren().add(SecondBrowser);
							
							double secondaryBackgroundBasisImageWidth = SecondaryBackgroundBasisImage.getWidth(), secondaryBackgroundBasisImageHeight = SecondaryBackgroundBasisImage.getHeight();
							
							
							ImageView secondaryCurrentBrowserImageView = new ImageView(), secondaryCurrentTransitionBrowserImageView = new ImageView(), secondaryBackupWorkAroundImageView = new ImageView(), secondaryBasisImageView = new ImageView(), secondaryBackgroundBasisImageView = new ImageView();
							
							secondaryCurrentBrowserImageView.setImage( SecondBrowser.snapshot(sP, secondaryBufferPicture) );
							secondaryCurrentBrowserImageView.autosize();
							secondaryCurrentBrowserImageView.setFitWidth( Dim.getWidth() );
							secondaryCurrentBrowserImageView.setFitHeight( Dim.getHeight() );
							Image secondaryImageForBrowser = secondaryCurrentBrowserImageView.snapshot(sP, secondaryBufferPicture);
							PixelReader secondarycurrentbrowserimagePR = secondaryImageForBrowser.getPixelReader();
							
							
							secondaryCurrentTransitionBrowserImageView.setImage( SecondBrowser.snapshot(sP, secondaryBufferPicture) );
							secondaryCurrentTransitionBrowserImageView.autosize();
							secondaryCurrentTransitionBrowserImageView.setFitWidth( Dim.getWidth() );
							secondaryCurrentTransitionBrowserImageView.setFitHeight( Dim.getHeight() );
							WritableImage secondaryWritableImageForBrowser = secondaryCurrentTransitionBrowserImageView.snapshot(sP, secondaryBufferPicture);
							PixelReader secondarybrowsertransitionimagePR = secondaryWritableImageForBrowser.getPixelReader();
							PixelWriter secondarybrowsertransitionPW = secondaryWritableImageForBrowser.getPixelWriter();
							
							//PixelWriter secondarycurrentbrowserimagePW = secondaryWritableImage.getPixelWriter();
							
							secondaryBackupWorkAroundImageView.setImage( SecondaryBackupWorkAroundImage );
							secondaryBackupWorkAroundImageView.autosize();
							secondaryBackupWorkAroundImageView.setFitWidth( Dim.getWidth() );
							secondaryBackupWorkAroundImageView.setFitHeight( Dim.getHeight() );
							Image secondaryBackupWorkAroundImage = secondaryBackupWorkAroundImageView.snapshot(sP, secondaryBufferPicture);
							PixelReader secondarybackupworkaroundimagePR = secondaryBackupWorkAroundImage.getPixelReader();
							
							secondaryBackgroundBasisImageView.setImage( SecondaryBackgroundBasisImage );
							secondaryBackgroundBasisImageView.autosize();
							secondaryBackgroundBasisImageView.setFitWidth( Dim.getWidth() );
							secondaryBackgroundBasisImageView.setFitHeight( Dim.getHeight() );
							Image secondaryBackgroundBasisImage = secondaryBackgroundBasisImageView.snapshot(sP, secondaryBufferPicture);
							PixelReader secondarybackgroundbasisimagePR = secondaryBackgroundBasisImage.getPixelReader();
							
							secondaryBasisImageView.setImage( SecondaryBasisImage );
							secondaryBasisImageView.autosize();
							secondaryBasisImageView.setFitWidth( Dim.getWidth() );
							secondaryBasisImageView.setFitHeight( Dim.getHeight() );
							Image secondaryBasisImage = secondaryBasisImageView.snapshot(sP, secondaryBufferPicture);
							PixelReader secondarybasisimagePR = secondaryBasisImage.getPixelReader();
							
							System.out.println("Worked Till After Here 2");
							//PixelReader basispr = SecondaryBasisImage.getPixelReader();
							//basispr = SecondaryBasisImage.getPixelReader();
							//PixelReader backgroundbasispr = SecondaryBackgroundBasisImage.getPixelReader();
							//backgroundbasispr = SecondaryBackgroundBasisImage.getPixelReader();
							WritableImage secondaryWritableImage = secondaryBufferPicture; //USE FOR ???
							WritableImage secondaryBufferPictureForBrowserImage = secondaryBufferPictureForBrowser;
							WritableImage secondaryBufferPictureForWritableBrowserImage = secondaryBufferPictureForBrowserTransitionImage;
							//PixelReader pr = secondaryWritableImage.getPixelReader();
							PixelWriter secondaryPW = secondaryWritableImage.getPixelWriter();
							PixelWriter secondaryBrowserPW = secondaryWritableImage.getPixelWriter();
							//ImageView secondaryImageView = new ImageView();
							//secondaryImageView.setImage(secondaryWritableImage);// */

							// hide webview scrollbars whenever they appear.
							SecondBrowser.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {//.getChildrenUnmodifiable
								@Override public void onChanged(Change<? extends Node> change) {
									Set<Node> deadSeaScrolls = SecondBrowser.lookupAll(".scroll-bar");
									for (Node scroll : deadSeaScrolls) {
										scroll.setVisible(false);
									}
								}
							});

							//PixelReader origionalpr = SecondaryBackupWorkAroundImage.getPixelReader();
							//origionalpr = SecondaryBackupWorkAroundImage.getPixelReader();//ASDF HERE HERE For Rainbow Browser
							//PixelReader origionalpr = SecondBackupWorkAroundImage.getPixelReader();
							//origionalpr = SecondScene[0].snapshot(secondaryBufferPicture).getPixelReader();//ASDF HERE HERE For Rainbow Browser
							//secondaryBufferPicture = new WritableImage( Dim.width, Dim.height );
							//origionalpr = SecondStackPane[0].getScene().snapshot(secondaryBufferPicture).getPixelReader();
							//PixelWriter origionalpw = secondaryBufferPicture.getPixelWriter();
							
							//BufferedImage bufferedImage = ImageIO.read(null);
							//Image secondaryBasisImage = bufferedImage.getScaledInstance( Dim.width, Dim.height );
							//origionalImageView.autosize();origionalImageView.setImage(origionalBrowserImage); //ASDF FOR RAINBOW BROWSER
							//origionalImageView.setImage(SecondBackupWorkAroundImage);



							//SecondScene[0].setRoot(SecondBrowser);

							//SecondStackPane[0].getChildren().add(origionalImageView);
							//SecondStackPane[0].getChildren().add(SecondBrowser);


							/*File tempFile;
					//WebDriver driver=new FirefoxDriver();

					// Maximize the window
					driver.manage().window().maximize();

					// Pass the url
					driver.get("http://www.pixies.zone/PixiesTest.html");

					// Take screenshot and store as a file format
					File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
					try {// now copy the  screenshot to desired location using copyFile //method
						FileUtils.copyFile(src, new File("C:/TempImage.png"));
					}

					catch (IOException e)
					{
						System.out.println(e.getMessage());

					}// */

							double secondaryNumberOfScrollFrames = 9999;//Testing 2; Normally 11;

							ColorSlider black = new ColorSlider( new double[]{0,0,0} );

							//ColorSlider color = black;
							Diagnostics diagnostics = new Diagnostics( SecondScreen.getBounds() );
							RainbowSoftColor color = new RainbowSoftColor( new double[]{0,0,0,1} );//????????????????????????????
							RainbowPattern2D pattern2D = new RainbowPattern2D( new double[]{0,0,0,1} );
							RainbowSoft2D rainbowSoft2D = new RainbowSoft2D( new double[]{0,0,0,1} );
							TransparencySlider transparencySlider = new TransparencySlider( new double[]{0,0,0,1} );
							RainbowSoftColor rainbowSoftColor = new RainbowSoftColor( new double[]{0,0,0,1} );
							Color tempFXColor = Color.BLACK;

							TransparencySlider redTransparencySlider = new TransparencySlider( new double[]{193,0,0,1} );
							TransparencySlider blueTransparencySlider = new TransparencySlider( new double[]{0,0,192,1} );

							String typeOfDisplay = "FullDisplay";
							Color colorTooSimilarReplacementColor = Color.color( 0., 1., 0., 1. );
							double colorDifference = 164.;

							ColorTooSimilar neonGreenCheck = new ColorTooSimilar();

							int numberOfColorsInTheRainbow = 7;//asdf Always Worry About This!

							int x = 0, y = 0;

							double xSlider = 0; //MUST START OUT AS 0 Or Else Video Won't Produce Or Potentially Scroll At All!
							Dimension HalfedDim = new Dimension();
							//HalfedDim.width = Math.round( ( Dim.width + 1 ) / 2 - 1 );
							//HalfedDim.height = Math.round( ( Dim.height + 1 ) / 2 - 1 );
							HalfedDim.width = Math.round( 1920 );//Dim.width / 2 );
							HalfedDim.height = Math.round( 1080 );//Dim.height / 2 );
							//double radialDistance = Math.pow(Math.pow(HalfedDim.width + 1, 2) + Math.pow(HalfedDim.height + 1, 2), 0.5);
							double halfSreenDiagionalLength = Math.pow(Math.pow( HalfedDim.getWidth(), 2) + Math.pow( HalfedDim.getHeight(), 2), 0.5);
							//double radialDistance = Math.pow(Math.pow(HalfedDim.width, 2) + Math.pow(HalfedDim.height, 2), 0.5);//HalfedDim.width + 1 HalfedDim.height + 1
							double fullAngleForUHD = Math.PI * halfSreenDiagionalLength;
							//double archimedesZoomFactor = 1;
							//int varGradAdjGradChoiceNum = 0;//Variated = 0, Graduated = 1, Adjusted-Graduated = 2

							//double fullAngle = Math.PI * radialDistance;
							//double sliderInterval = fullAngle / SecondFRateDivisor;// / 10 For Rainbow Spotlight Last Division Determines The Frame Rate


							SeekableByteChannel SecondaryVideoOut = null;

							RainbowVideo rainbowVideo = new RainbowVideo ( SecondaryStage, secondaryBasisImage, secondaryBackgroundBasisImage, secondaryImageForBrowser, secondaryBackupWorkAroundImage,
									SecondBrowserEngine, SecondBrowser, SecondStackPane, SecondScene, SecondScreen, SecondStateLabel, SecondFile, SecondJavaScriptFile, SecondXSliderFile, SecondaryThread,
									SecondaryVideoOut, secondaryWritableImage, secondaryBufferPicture, secondaryWritableImageForBrowser, secondaryBufferPictureForWritableBrowserImage,
									secondarycurrentbrowserimagePR, secondarybrowsertransitionimagePR, secondarybackupworkaroundimagePR, secondarybackgroundbasisimagePR, secondarybasisimagePR,
									secondaryPW, secondarybrowsertransitionPW, secondaryCurrentBrowserImageView, secondaryCurrentTransitionBrowserImageView, secondaryBackupWorkAroundImageView,
									secondaryBackgroundBasisImageView, secondaryBasisImageView, SecondaryIsFullScreened, SecondFRateDivisor, 0,	fullAngleForUHD, secondaryBackgroundBasisImageWidth,
									secondaryBackgroundBasisImageHeight, secondaryNumberOfScrollFrames, SecondaryRoot );

							try
							{
								rainbowVideo.Runner();
							}
							catch (IndexOutOfBoundsException e) { System.err.println("IndexOutOfBoundsException: " + e.getMessage()); }
							//catch(IOException ie) { ie.printStackTrace(); }
							//finally {
							//	NIOUtils.closeQuietly(SecondaryVideoOut);
							//}
							System.exit(0);
							//return;
						}
						//return;
					}
				}
				);

		/*synchronized ( SecondaryThread )
						{

							System.out.println("Before Wait");
							SecondaryThread.wait(10000);
							System.out.println("Past Wait");
						}//SecondaryThread.wait(1000);
			} catch (InterruptedException ex) {
				System.err.println("An InterruptedException was caught: " + ex.getMessage());
				ex.printStackTrace();
			}*/
		//SecondaryStage.show();
		//origionalBrowserImage = SecondBrowser.snapshot(sP, nextTextPicture);
		//Image origionalBrowserImage = SecondBrowser.snapshot(sP, nextTextPicture);
		//nextTextPicture = SecondBrowser.snapshot(sP, nextTextPicture);
		//Image origionalBrowserImage = SecondScene[0].snapshot(nextTextPicture);
		/*origionalBrowserImage = SecondScene[0].snapshot(nextTextPicture);
		origionalBrowserImage = SecondStackPane[0].getScene().snapshot(secondaryBufferPicture);
		SecondaryStage.setScene(SecondScene[0]);
		SecondaryStage.setFullScreen(true);
		try { SecondaryThread.sleep(4000);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}
		SecondaryStage.show();// */
		/*SecondScene[(int)(SecondFRateDivisor * xSlider/fullAngle)].setOnKeyReleased(new EventHandler<KeyEvent>()
		{
			@Override
			public void handle(KeyEvent event)
			{
				if ( event.isAltDown() == true)
				{
					switch (event.getCode())
					{
					case ENTER: SecondaryStage.setFullScreen(!SecondaryStage.isFullScreen()); break;
					}
				}
			}
		});//*/

		//VBox root = new VBox();
		//root.getChildren().addAll(addressBar, goButton, stateLabel, progressBar, browser);
		//SecondScene[0] = new Scene(SecondStackPane[0]);
		//SecondaryStage.setScene(SecondScene[0]);



		//SecondaryStage.setFullScreen(true);
		//SecondaryStage.show();

		//WritableImage nextTextPicture = new WritableImage( Dim.width, Dim.height );
		//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//browser.snapshot(sP, nextTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
		//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Test.png");//browser.snapshot(sP, nextTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
		//SecondStackPane[0].getChildren().add(browser);

		//SecondScene[0] = new Scene(SecondStackPane[0]);
		//SecondaryStage.setScene(SecondScene[0]);

		//SecondaryStage.setFullScreen(true);
		//SecondaryStage.show();
		//JUST THIS DISPLAYS BROWSER!!!!!






		//nextTextPicture = SecondScene[0].snapshot(null);

		//Image origionalBrowserImage = SecondScene[0].snapshot(null);//browser.snapshot(sP, nextTextPicture);
		//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/FatLevels.png");

		///TEST


		/*try { SecondEnc.finish(); }
		catch(IOException ie) { ie.printStackTrace(); }//*/

		//encFinished = true;
		//}
		/*webEngine.getLoadWorker().stateProperty().addListener(
	        new ChangeListener<State>() {
	            public void changed(ObservableValue ov, State oldState, State newState) {
	                if (newState == State.SUCCEEDED) {
	                    SecondaryStage.setTitle(webEngine.getLocation());
	                }
	            }
	        });*/
		/*browser.getEngine().getLoadWorker().stateProperty().addListener(
			  (ObservableValue<? extends worker.State> observable,
			    worker.State oldValue,
			    worker.State newValue) -> {
			    if( newValue != worker.State.SUCCEEDED ) {
			      return;
			    }

			    // Your logic here
			  } );*/

		//if (worker.State.SUCCEEDED == true)
		//{


		//}
		/*SecondScene.setOnKeyReleased(new EventHandler<KeyEvent>()
	{
		@Override
		public void handle(KeyEvent event)
		{
			if ( event.isAltDown() == true)
			{
				switch (event.getCode())
				{
					case ENTER: SecondaryStage.setFullScreen(!SecondaryStage.isFullScreen()); break;
				}
			}
		}
	});//*
		SecondScene[(int)SecondFRateDivisor].setOnKeyReleased(new EventHandler<KeyEvent>()
		{
			@Override
			public void handle(KeyEvent event)
			{
				if ( event.isAltDown() == true)
				{
					switch (event.getCode())
					{
					case ENTER: SecondaryStage.setFullScreen(!SecondaryStage.isFullScreen()); break;
					}
				}
			}
		});
	//*/
		//browser.snapshot(sP, nextTextPicture);
	}
}
