function webGLStart(){
 var d=new Date();
 scene=new ASH();
startTime=d/1000.0;
prevTime=0;
canvas=document.getElementById("renderscene");
gl=canvas.getContext("experimental-webgl");

canvas.width= 0;
canvas.height = 0;
document.body.style.background="#000000"




}
function DAOlength(DA){
 var i=0;
 while(typeof DA[i]!=="undefined"){
i++;
 }
 return i;
}
function getConstructorvalues(obj){
var params = getParamNames(eval(getTypeName(obj)));

 var ret=new Array();
 var i;
 for(i=0; i<DAOlength(params); i++){
ret[i]=eval("obj."+params[i]);
 }
 return ret;
}
function pushObject(newobject){
 var wholist=document.getElementById('who');
 var i;
 objects.push(newobject);
 objectsSize++;
 updateRemovelist();
 
}
function popObject(index){
 objects.splice(index,1);
 objectsSize--;
 updateRemovelist();
}
function pseudoRandom( seed, maximum ){
n = (314159265 * seed + 2718281) % 65536;
c = Math.round( ((n / 65536) * 100) % 100 );
output = Math.floor( c/100 * maximum );
 
return output;
}

document.getElementById('fullscreen').onmouseup=function(){
var isInFullScreen = (document.fullScreenElement && document.fullScreenElement !== null) || 
(document.mozFullScreen || document.webkitIsFullScreen);
var docElm = document.documentElement;
document.body.style.background="#000000"
if (!isInFullScreen) {

if (docElm.requestFullscreen) {
docElm.requestFullscreen();
}
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
}
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
}
}
document.body.style.background="#000000"
}

document.getElementById('windowed').onmouseup=function(){
console.log("pheep!");
document.body.style.background="#000000"
var kuva=document.getElementById('kuva');
kuva.innerHTML="";
var windowed=document.getElementById('windowed');
kuva.innerHTML="";
var fullscreen=document.getElementById('fullscreen');
kuva.innerHTML="";



go();
}
function go(){


updateObjectAdd();
initGL();
initShaders(shaderProgram);
pushObject(new ASHCUBE(0,0,-18,/*sides*/1,-1,1,-1,1,-1, /*rgb*/0.4,0.4,0));

//OUTOFEDITOR
for(var i=1; i<30; i++){
pushObject(new ASHCUBE( 0, 
0,
objects[i-1].z-0.3,
.6,-.6,.6,-.6,1,-1,
0.6,0.7,Math.sin(i*0.10)*0.6));

}
for(var i=30; i<90; i++){
pushObject(new ASHCUBE( 0, 
0,
objects[i-1].z-1,
0,0,0,0,0,0,
Math.sin(i)*0.2+0.75,Math.sin(i)*0.1+0.3,0.0));

}
importFunction("this.operateAwhile(160,\"this.x=Math.sin(realtime*0.1)*5\");", 0, 0);
importFunction("this.operateAwhile(80,\"this.rotation("+0*10+"+realtime*2.5,0,0,1);\");", 0, 0);
importFunction("this.operateAwhile(80,\"this.left=Math.abs(Math.sin(realtime*1)*2+4);this.right=-Math.abs(Math.sin(realtime*1)*2+4);\");", 0, 0);

for(var i=1; i<30; i++){
importFunction("this.showup();", i, i*0.25);
importFunction("this.operateAwhile(80,\"this.rotation("+i*10+"+realtime*2.5,0,0,1);\");", i, 0);
importFunction("this.operateAwhile("+280+",\"this.left=Math.abs(Math.sin(realtime*1+"+i+")*2+4);this.right=-Math.abs(Math.sin(realtime*1+"+i+")*2+4);\");", i, 0);

importFunction("this.operateAwhile(120,\"this.x=objects["+(i-1)+"].x+Math.cos(objects["+(i-1)+"].radius+realtime*0.025);\");", i, 0);
importFunction("this.operateAwhile(120,\"this.y=objects["+(i-1)+"].y+Math.sin(objects["+(i-1)+"].radius+realtime*0.025);\");", i, 0);


importFunction("this.operateAwhile(10,\"this.r=1*(10-realtime)/10+0.6\");", i, 0);
importFunction("this.operateAwhile(10,\"this.g=1*(10-realtime)/10+0.6\");", i, 0);
importFunction("this.operateAwhile(10,\"this.b=1*(10-realtime)/10+Math.sin("+i+"*0.25)*0.8\");", i, 0);




importFunction("this.operateAwhile(200,\"this.left+=((realtime-"+(80+i*0.25-0.1)+")/280)*500;this.right+=((realtime-"+(80+i*0.25-0.1)+")/280)*500;\");", i, (80+i*0.25-0.1));

importFunction("this.hideup();", i, 200+i*0.25+4);
}



for(var i=30; i<90; i++){
importFunction("this.showup();", i, i*0.25);
importFunction("this.setForcedTimeSide(5,.3,-.3,.3,-.3,.3,-.3);", i, i*0.5);
var j=Math.ceil(Math.random()*90);
console.log("rand"+j);
var k=Math.random()*objectsSize;
importFunction("this.operateAwhile(180,\"this.rotation("+i*10+"+realtime*4,0,0,1);\");", i, 0);

importFunction("this.operateAwhile(120,\"this.x=objects["+j+"].x+Math.cos(objects["+j+"].radius+realtime*0.1+"+k+")*1;\");", i, 0);
importFunction("this.operateAwhile(120,\"this.y=objects["+j+"].y+Math.sin(objects["+j+"].radius+realtime*0.1+"+k+")*1;\");", i, 0);
importFunction("this.operateAwhile(120,\"this.z=objects["+j+"].z-1;\");", i, 0);

importFunction("this.operateAwhile(100,\"this.r=0\");", i, 258);
importFunction("this.operateAwhile(100,\"this.g=0\");", i, 258);
importFunction("this.operateAwhile(100,\"this.b=0\");", i, 258);

importFunction("this.operateAwhile(10,\"this.r=(120-realtime)/10\");", i, 120);
importFunction("this.operateAwhile(10,\"this.g=(120-realtime)/10\");", i, 120);
importFunction("this.operateAwhile(10,\"this.b=(120-realtime)/10+Math.sin("+i+"*0.25)*0.4+0.8\");", i, 120);

importFunction("this.operateAwhile(10,\"if(this.r>0.0) this.r-=realtimetaken\");", i, 118.5);
importFunction("this.operateAwhile(10,\"if(this.g>0.0) this.g-=realtimetaken\");", i, 118.5);
importFunction("this.operateAwhile(10,\"if(this.b<0.8) this.b+=realtimetaken\");", i, 118.5);

importFunction("this.operateAwhile(362,\"this.left=Math.abs(Math.sin(realtime*.2+"+i+")*2*Math.sin(realtime*.2)+4);\");", i, 0);
importFunction("this.setForcedTimeSide(4,0,0,0,0,0,-0);", i, 258);


}



for(var i=90; i<190; i++){
var a=pseudoRandom( i, 200 );
var b=pseudoRandom( a, 200 );
var c=pseudoRandom( b, 200 );
pushObject(new ASHCUBE( -100+a, 
-100+b,
-100+c,
0,-0,0,-0,0,-0,
0.0,Math.sin(i)*0.18+0.8,Math.sin(i)*0.22+0.77));
importFunction("this.showup();", i, i*0.25);
importFunction("this.setForcedTimeSide(4,5,-5,5,-5,5,-5);", i, i*0.25);
importFunction("this.operateAwhile(180,\"this.left+=Math.floor(realtime/4)-realtime/4;this.right-=Math.floor(realtime/4)-realtime/4;\");", i, i*0.25+5);
importFunction("this.setForcedTimeSide(30,1,-1,20,-20,1,-1);", i, 80);

importFunction("this.operateAwhile(100,\"this.r=0\");", i, 258);
importFunction("this.operateAwhile(100,\"this.g=0\");", i, 258);
importFunction("this.operateAwhile(100,\"this.b=0\");", i, 258);
importFunction("this.setForcedTimeSide(4,0,0,0,0,0,-0);", i, 258);

}


for(var i=190; i<300; i++){
var a=pseudoRandom( i, 200 );
var b=pseudoRandom( a, 200 );
var c=pseudoRandom( b, 200 );
pushObject(new ASHCUBE( -100+a, 
-100+b,
-100+c,
0,-0,0,-0,0,-0,
0.5,0.8,0.2));
importFunction("this.showup();", i, i*0.25);
importFunction("this.setForcedTimeSide(4,1,-1,1,-1,1,-1);", i, i*0.25);
importFunction("this.operateAwhile(80,\"this.fx="+pseudoRandom( i, 100 )/100+";\");", i, 0);
importFunction("if(this.x>0)this.fx-=.1; if(this.x<0)this.fx=.1; if(this.y>0)this.fy-=.1; if(this.y<0)this.fy=.1; if(this.z>0)this.fz-=.1; if(this.z<0)this.fz=.1;", i, 120);

importFunction("this.operateAwhile(100,\"this.r=0\");", i, 258);
importFunction("this.operateAwhile(100,\"this.g=0\");", i, 258);
importFunction("this.operateAwhile(100,\"this.b=0\");", i, 258);
importFunction("this.setForcedTimeSide(4,0,0,0,0,0,-0);", i, 258);

}
document.getElementById('demoaudio').play();
//OUTOFEDITOR

console.log(objects[0]);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);

var animFrame=window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame||
window.oRequestAnimationFrame||
window.msRequestAnimationFrame ||
null;
if( animFrame !== null ){
var recurAnim=function(){
drawScene();
animFrame(recurAnim);
};
animFrame(recurAnim);
}
else{
setInterval(drawScene,1000/60);
}
}