//***************************************************************************
// Globals
//***************************************************************************

// Pixel variables
var colors = "ffd461ffa760ff7b5cff6a75ff6ca2ff6ed6ff6ff9f070ffd06effa56cff7a6dff5f72ff5c91ff54bbff57e7ff51fbfc4ffbe153fbbe57fa9454fa6d67fa639cfa63cafb60effc60fff560ffc620ff8e21ff5b25ff4044ff448c";
var pixelOutput = "";

// False function prevents cascading events (apparently)
//function falsefunc() { return false; }


//***************************************************************************
// Setup Functions
//***************************************************************************

// Sets up application
function Initialize()
{
	// Draws random pattern
	GeneratePixels();
}

//***************************************************************************
// Mode Drawing
//***************************************************************************

// Generates random pattern
function GeneratePixels()
{
	PixelClear();
	
	// Loop through random number of boxes and generate them
	var numberOfBoxes = Math.random()*5 + 50;
	for(i = 0; i < numberOfBoxes; i++)
	{
		var corX = Math.floor(Math.random()*25);
		var corY = Math.floor(Math.random()*6);
		PixelGen(corX, corY);
	}
	
	PixelDraw();
}

//***************************************************************************
// Pixel Manipulators
//***************************************************************************

// Clears pixel output
function PixelClear()
{
	pixelOutput = "";
}

// Generates pixel at given coordinates
function PixelGen(corX, corY)
{
	pixelOutput += "<div class=\"p\" style=\"left:";
	pixelOutput += corX*36+1;
	pixelOutput += "px;top:";
	pixelOutput += corY*23+1;
	pixelOutput += "px;background:#";
	pixelOutput += colors.substr(corX*6+corY*6,6);
	pixelOutput += ";\"></div>";
}

// Draws pixels
function PixelDraw()
{
	document.getElementById("pixels").innerHTML = pixelOutput;
}
