// JavaScript Document, by tGDA
function debug(mixed) {
	console.debug(mixed);
}

CodeBG={};
CodeBG.Code="#include &lt;iostream.h&gt;\n\
#include &lt;math.h&gt;\n\
#include &lt;conio.h&gt;\n\
\n\
";


CodeBG.Code+="main()\n\
{\n\
	cout&lt;&lt;&quot;For [ aX + bY + c = 0 ]: a, b, c are all integers (4 the time being!!)&quot;;\n\
	int a, b, c;\n\
	cout&lt;&lt;&quot;Enter the (a) Parameter: &quot;;\n\
	cin&gt;&gt;a;\n\
\n\
	cout&lt;&lt;&quot;Enter the (b) Parameter: &quot;;\n\
	cin&gt;&gt;b;\n\
	cout&lt;&lt;&quot;Enter the (c) Parameter: &quot;;\n\
	cin&gt;&gt;c;\n\
\n\
	for (double y=-33; y&lt;33; y++)	//Moving Vertically\n\
	{\n\
		for (double x=-39; x&lt;39; x++)	//Moving Horizontally\n\
		{\n\
			int xval=ceil(-(c+y*b)/a);\n\
			int yval=ceil(-(c+x*a)/b);\n\
            \n\
		 	if (xval==x || yval==y)       //draws  a pixel[i mean a solid char in the console output] if the equation is right!!\n\
				cout&lt;&lt;char(177);\n\
	   		else           //draws the center, coordinatons, or just a space\n\
				if (x==0)\n\
\n\
					if (y==0)\n\
						cout&lt;&lt;\'+\';     \n\
					else\n\
						cout&lt;&lt;\'|\';      \n\
                else\n\
\n\
					if(y==0)\n\
						cout&lt;&lt;\'_\';       \n\
					else\n\
						cout&lt;&lt;\' \';\n\
		}\n\
\n\
		cout&lt;&lt;endl;            \n\
	}\n\
\n\
    getch();\n\
	return 0;\n\
}";
if(navigator.userAgent.indexOf('MSIE')!=-1) {
	CodeBG.Code=CodeBG.Code.replace(/\n/g, '\n<br />');
	CodeBG.Code=CodeBG.Code.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;');
	//CodeBG.Code=CodeBG.Code.replace(/ /g, '&nbsp;');
	CodeBG.LineSeperator='\n<br />';
} else {
	CodeBG.LineSeperator='\n';
}
CodeBG.CodeChunks=[];
CodeBG.ChunkCode=function() {
	var CodeLines=CodeBG.Code.split(CodeBG.LineSeperator);
	var currentChunk=0;
	var CurrentLine;
	var CurrentChar;
	var SemiColonPos;
	for(var i=0; i<CodeLines.length; i++) {
		if ((CurrentLine=CodeLines[i])==''){
			CodeBG.CodeChunks[currentChunk++]=CodeBG.LineSeperator;
		} else {
			for(k=0; k<CurrentLine.length; k++) {
				if ((CurrentChar=CurrentLine.substr(k,1))!='&') {
					
					CodeBG.CodeChunks[currentChunk++]=CurrentChar;
				} else {
					SemiColonPos=CurrentLine.indexOf(';', k+1);
					CurrentChar=CurrentLine.substring(k, SemiColonPos+1);
					CodeBG.CodeChunks[currentChunk++]=CurrentChar;
					
					k=SemiColonPos;
				}
			}
		}
		CodeBG.CodeChunks[currentChunk++]=CodeBG.LineSeperator;
	}
}

CodeBG.putCode = function () {
	var preElem=document.createElement('PRE');
	preElem.style.margin='5px';
	CodeBG.CodeContainer=document.createElement('SPAIN');
	preElem.appendChild(CodeBG.CodeContainer);
	CodeBG.BlinkyCursor=document.createElement('SPAIN');
	CodeBG.BlinkyCursor.className='blinky';CodeBG.BlinkyCursor.innerHTML='&#x2588;';
	preElem.appendChild(CodeBG.BlinkyCursor);
	$('bgMagic').appendChild(preElem);
	
	//$'<pre style="margin: 5px;"><span id="code_container"></span><span class="blinky"></span></pre>';
	CodeBG.ChunkCode();
	CodeBG.putNextChunk();
	//=document.getElementById('code_container');
	
}
CodeBG.CurrentCode='';
CodeBG.CurrentChunkIndex='';
CodeBG.CodeContainer={};
CodeBG.putNextChunk = function () {
	var time2wait;
	if (CodeBG.CurrentChunkIndex<CodeBG.CodeChunks.length) {
		var nextChar=CodeBG.CodeChunks[CodeBG.CurrentChunkIndex++];
		time2wait=(nextChar==CodeBG.LineSeperator)? 511 :131;
		CodeBG.CurrentCode+=nextChar;
		CodeBG.CodeContainer.innerHTML=CodeBG.CurrentCode;
		
	} else {
		time2wait=3333;
		CodeBG.CurrentChunkIndex=0;CodeBG.CurrentCode="";
	}
	setTimeout('CodeBG.putNextChunk()', time2wait);
	
}

magicBG={
	doMagic:function() {
		CodeBG.putCode();
	}
};

