var got=false;
var kasten = new Array();
for (x=0;x < 27;x++){
kasten[x] = new Array();
}
var dimmer_running=false;
var dim_stack = new Array(); 

var auto =0;
var ticktimer;
var checktimer;
function hide_impressum() {
document.getElementById('impressumbox').style.visibility="hidden";

 }

 var uploading=0;
 
 

function einstellerhoverin(el) {

mancss(el).backgroundColor="#555";


}

function einstellerhoverout(el) {

mancss(el).backgroundColor=mancss(el).color;


}
 

function cancell() {

auto=0;
killer();
document.getElementById('upfeld').style.visibility="visible";
document.getElementById('abdecker').style.visibility="hidden";
document.getElementById('knopf').value="upload        ";
}

function show_impressum() {

document.getElementById('impressumbox').style.visibility="visible";


gethttp('impressum.php', function(msg) {man('impressum').innerHTML = msg;})



}

function stoptimers() {


document.title = "daunlaut! - Imagehosting";
clearTimeout(ticktimer);
clearTimeout(checktimer);




}

function ajaxmacher(url) {

try {

if (window.XMLHttpRequest) {
request = new XMLHttpRequest(); 
} else if (window.ActiveXObject) {
try {
request = new ActiveXObject('Msxml2.XMLHTTP'); 
} catch (e) {
	try {
request = new ActiveXObject('Microsoft.XMLHTTP'); 
} catch (e) {}
}
}

if (!request) {
		
return false;
} else {
	
		
request.open('post', url, true);
request.send(null);
request.onreadystatechange = ausgabe;
	}
} catch (bla) {

}
}






var pressed;
var alt_ende;
var pressedz;
var starter;
var warte=2;
document.onkeydown=taste;

var l=0;var hell=0;
function checkfile() {


  if (document.getElementById('uploadedfile').value != "") {
    var ext1 = document.getElementById('uploadedfile').value;
     ext2 = ext1.split(".");
			ext1="";
    			ext1 = ext2[ext2.length-1];
   			 ext1 = ext1.toLowerCase();
   if( (ext1 != 'gif') && (ext1 != 'GIF') && (ext1 != 'TIF') && (ext1 != 'tif')  && (ext1 != 'TIFF') && (ext1 != 'tiff') && (ext1 != 'jpeg') && (ext1 != 'JPEG') && (ext1 != 'jpg') && (ext1 != 'JPG') && (ext1 != 'bmp') && (ext1 != 'BMP') && (ext1 != 'png') && (ext1 != 'PNG') ){ 
dunkler();
    }else{

			if (l==0) {
			document.getElementById('knopf').style.visibility="visible";
			document.getElementById('knopf').value="upload        ";
			hell=0;
			l=1;
			heller() ;

}
}
}

checktimer = self.setTimeout("checkfile()", 500);

}






function heller() {

if (hell <9) {

document.getElementById('knopf').style.opacity="0." + hell;
try{document.getElementById('knopf').style.filter="alpha(opacity = " + (hell*10) + ")";}catch(bla){}
hell++;

self.setTimeout("heller()", 60);
}
}


var dunk=9;

function dunkler() {

if (l==1) {

if (dunk >0) {

document.getElementById('knopf').style.opacity="0." + dunk;
try{document.getElementById('knopf').style.filter="alpha(opacity = " + (dunk*10) + ")";}catch(bla){}
dunk--;

self.setTimeout("dunkler()", 60);
}else{

document.getElementById('knopf').style.visibility="hidden";
dunk=9;
l=0;
}
}

}

function taste(e){
e=!e?event:e;
code=e.keyCode?e.keyCode:e.which;

//alert(code);

if (auto < 1) {
if(code==87) code=38;

if(code==65) code=37;

if(code==83) code=40;

if(code==68) code=39;


if (!pressed) {


if(code==38) richtung="o";
if(code==40) richtung="u";
if(code==37) richtung="r";
if(code==39) richtung="l";

if(code==77) grow();
pressed=true;
}else{

if(code==38) richtungz="o";
if(code==40) richtungz="u";
if(code==37) richtungz="r";
if(code==39) richtungz="l";

pressedz=true;

}

} 
}
var killit=false;
var started=0;

var richtung="u";
var punkte=0;

var schlange = new Array(new Array(1,1),new Array(2,1),new Array(3,1),new Array(4,1));



function make_cord(x,y) {


return x + "-" + y;



}



function get_cord(a) {

var x;
var y;

x=a.substring(0,a.indexOf("-"));

y=a.substring(a.indexOf("-")+1, a.length);

return new Array(x,y);

}




function frei(x,y) {


if (((((y == 16) || (y == 17)) && ((x >5) && (x<24)))) && (upload != 1)) return false;


if ((x > -1) && (x<27) && (y > -1) && (y<27)) {



for (i=1;i<schlange.length-1;i++) {



if ((schlange[i][0] == x) && (schlange[i][1] == y)) {



return false;

}
}



var faarbe = document.getElementById(make_cord(x,y)).style.backgroundColor;





var ding = kasten[x][y];

faarbe=faarbe.toLowerCase();
faarbe=faarbe.replace(/\s/g,"");


if (!((ding == 0)))   {


punkte++;

if (y<23) sternle();

}


return true;



}

return false;

}



function lade(id) {

if (document.getElementById('uploadedfile').value != "") {
    var ext1 = document.getElementById('uploadedfile').value;
     ext2 = ext1.split(".");
			ext1="";
    			ext1 = ext2[ext2.length-1];
   			 ext1 = ext1.toLowerCase();
   if( (ext1 != 'gif') && (ext1 != 'GIF') && (ext1 != 'TIF') && (ext1 != 'tif')  && (ext1 != 'TIFF') && (ext1 != 'tiff') && (ext1 != 'jpeg') && (ext1 != 'JPEG') && (ext1 != 'jpg') && (ext1 != 'JPG') && (ext1 != 'bmp') && (ext1 != 'BMP') && (ext1 != 'png') && (ext1 != 'PNG') ){ 
return false;}else{



if (auto >0) {
cancel_all();
return false;
}else{
killer();


document.getElementById('upfeld').style.visibility="hidden";
document.getElementById('configsbutton').style.visibility="hidden";
document.getElementById('abdecker').style.visibility="visible";
document.getElementById('knopf').value="cancel        ";

update_progress(id);
auto=1;
uploading=1;
return true;

}




}}
}

function cancel_all() {

 firstdata=0;

try {window.stop();}catch(bla){};
try {document.execCommand('Stop');}catch(gacker){};
cancell();

window.location.href = "snake.php";

}
function grow() { 


var neuschlang = new Array(schlange.length+1);


for (i=1;i<schlange.length  +1;i++) {

neuschlang[i] = schlange[i-1];

}


neuschlang[0] = alt_ende;

schlange=neuschlang;

wachse=true;

}


var schlange_alt=new Array();

function killer() {


if (started==1) {

killit=true;



var k=schlange_alt.length;

var t=1;

if ((starter > -1) ) t=1;else t=0;


for (i=t;i<schlange.length;i++) {

schlange_alt[k+i-t] = schlange[i];

}
started=0;

killit=false;


clearTimeout(ticktimer);


blink();
}


}


var ah=true;
var bh = 19;


function blink() {




if (bh>-1) {


if (bh>9) {

for (i=1;i<schlange_alt.length;i++) {


document.getElementById(make_cord(schlange_alt[i][0],schlange_alt[i][1])).style.opacity = "0." + (bh-10);
try{document.getElementById(make_cord(schlange_alt[i][0],schlange_alt[i][1])).style.filter="alpha(opacity = " + ((bh-10)*10) + ")";}catch(bla){}


}

}else{

for (i=1;i<schlange_alt.length;i++) {

stones = 10-bh;




document.getElementById(make_cord(schlange_alt[i][0],schlange_alt[i][1])).style.opacity = stones/10;

try{document.getElementById(make_cord(schlange_alt[i][0],schlange_alt[i][1])).style.filter="alpha(opacity = " + ((stones)*10) + ")";}catch(bla){}
document.getElementById(make_cord(schlange_alt[i][0],schlange_alt[i][1])).style.backgroundColor = "rgb(" + (schlange_alt[i][1] + 10) +"," + (schlange_alt[i][1] + 10) +"," + (schlange_alt[i][1] + 10) +")";

}
}




ah= !ah;
bh--;

self.setTimeout("blink()",40);




}else{
bh=19;
ah=true;
schlange_alt=new Array();

}

}


function tick() {


if (auto > 0) auto++;

if (auto == 20) richtung="u";
if (auto == 23) richtung="r";
if (auto == 42) richtung="o";
if (auto == 45) {richtung="l";auto=1}
if ( (started==1)) {




if (pressedz) {


var a;
a=richtung;
richtung=richtungz;
richtungz=a;


pressedz=false;


}


var blax = schlange[schlange.length-1][0];
var blay = schlange[schlange.length-1][1];

if (richtung == "l") blax = schlange[schlange.length-1][0]+1;
if (richtung == "r") blax = schlange[schlange.length-1][0]-1;
if (richtung == "o") blay = schlange[schlange.length-1][1]-1;
if (richtung == "u") blay = schlange[schlange.length-1][1]+1;


if (frei(blax,blay)) {
warte=2;
alt_ende = new Array(schlange[0][0],schlange[0][1]);

for (i=0;i<schlange.length-1;i++) {

schlange[i][0]  = schlange[i+1][0]
schlange[i][1]  = schlange[i+1][1]

}

if (richtung == "l") schlange[schlange.length-1][0] = schlange[schlange.length-1][0]+1;
if (richtung == "r") schlange[schlange.length-1][0] = schlange[schlange.length-1][0]-1;
if (richtung == "o") schlange[schlange.length-1][1] = schlange[schlange.length-1][1]-1;
if (richtung == "u") schlange[schlange.length-1][1] = schlange[schlange.length-1][1]+1;


var vvvv = document.getElementById(make_cord(schlange[0][0],schlange[0][1])).style.backgroundColor;

vvvv=vvvv.toLowerCase();
vvvv=vvvv.replace(/\s/g,"");


if ((vvvv == "#ff0000") || (vvvv == "rgb(255,0,0)")) {

document.getElementById(make_cord(schlange[0][0],schlange[0][1])).style.backgroundColor="rgb(" + (schlange[0][1] + 10) +"," + (schlange[0][1] + 10) +"," + (schlange[0][1] + 10) +")";
}
document.getElementById(make_cord(schlange[schlange.length-1][0],schlange[schlange.length-1][1])).style.backgroundColor='#ff0000';
kasten[schlange[schlange.length-1][0]][schlange[schlange.length-1][1]] = 0;
pressed=false;



if (starter > -1) {

starter--;
grow();

}


if (punkte == 4) {
grow();
punkte=0;
}


ticktimer = self.setTimeout("tick()", 120);

}else{


if (warte == 0) {

killer();
warte=2;

}else{
warte--;
ticktimer = self.setTimeout("tick()", 120);
}


}


}

}


function sternle() {


var xxx = Math.round(Math.random() * 23) ; 

var yyy = Math.round(Math.random() * 23) ; 



while (!frei(xxx,yyy)) {


var xxx = Math.round(Math.random() * 23) ; 

var yyy = Math.round(Math.random() * 23) ; 

}


var r = Math.round(Math.random() * 180) +75; 
var g= Math.round(Math.random() * 180) +75; 
var b = Math.round(Math.random() * 180) +75; 


col = 'rgb(' + r +','+ g +',' + b +')';



document.getElementById(make_cord(xxx,yyy)).style.backgroundColor=col;
document.getElementById(make_cord(xxx,yyy)).style.opacity="0.1";
try{document.getElementById(make_cord(xxx,yyy)).style.filter="alpha(opacity = '10')";}catch(bla){}
dim_stack.push(new Array(xxx,yyy));
kasten[xxx][yyy]=1;
if (!dimmer_running) make_dimm();


}




function start(x,y) {

if (uploading==0) {
if (started==0) {
starter=2;
started=1;

if ((x<14) && (y<14)) {
schlange=new Array(new Array(x+1,y),new Array(x,y));

richtung="u";

}

if ((x<14) && (y>13)) {
schlange=new Array(new Array(x,y-1),new Array(x,y));
richtung="l";
if ((y==16)||(y==17)) {

schlange=new Array(new Array(x,y+1),new Array(x,y));
richtung="o";

}

if ((y==18)) {

schlange=new Array(new Array(x+1,y),new Array(x,y));
richtung="u";

}
}

if ((x>13) && (y>13)) {
schlange=new Array(new Array(x,y-1),new Array(x,y));
richtung="r";
if ((y==17)||(y==16)) {

schlange=new Array(new Array(x,y+1),new Array(x,y));
richtung="o";

}

if ((y==18)) {

schlange=new Array(new Array(x,y+1),new Array(x,y));
richtung="r";

}
}

if ((x>13) && (y<14)) {
schlange=new Array(new Array(x,y+1),new Array(x,y));
richtung="r";
}



alt_ende = new Array(schlange[1][0],schlange[1][1]);
grow();



document.getElementById(make_cord(schlange[schlange.length-1][0],schlange[schlange.length-1][1])).style.backgroundColor='#ff0000';



ticktimer = self.setTimeout("tick()", 120);

}
}
}





function make_dimm() {

for (var i = 0; i < dim_stack.length; i++){ 

xxxx = dim_stack[i][0];
yyyy = dim_stack[i][1];


opa = Number(document.getElementById(make_cord(xxxx,yyyy)).style.opacity);

if (opa < 1) {

opa = (opa + 0.1);

document.getElementById(make_cord(xxxx,yyyy)).style.opacity = opa ;
try{document.getElementById(make_cord(xxxx,yyyy)).style.filter="alpha(opacity = '" + (opa * 100) + "')";}catch(bla){}

} else {
dim_stack = dim_stack.slice(0, i ).concat( dim_stack.slice( i + 1, dim_stack.length) );
}


}

if (dim_stack.length > 0) {
dimmer_running=true;
 self.setTimeout("make_dimm()", 40);
}else{
dimmer_running=false;
}
}




