/* 
    Titel: JavaScript Puzzle
    Autor: Johannes Gamperl
    email: jg@jg.seite.net

    Copyright (c) J|G Webdesign & Programmierung - Johannes Gamperl, 1997. 
    All rights reserved. Alle Rechte vorbehalten. URL: http://jg.seite.net

    Dieser Code darf für nicht-kommerzielle  sowie kommerzielle Zwecke frei
    genutzt und angepaßt werden, solange dies unentgeltlich erfolgt und
    dieser Vermerk bestehen bleibt. 
*/


var zellen = 3;
var anzahl = 8;

blank = new Image();
blank.src = "blank.gif";
var temp = new Image();


for (i = 0; i <= anzahl; i++) {
	Grafik = new Array();
	Grafik[i]  = new Image();
	Grafik[i].src  = i + ".gif"
	}


function Puzzle(nr, x) {



		// nach unten
		if (x == 'l' || x == 'm' || x == 'r' || x == 'ul' || x == 'um' || x == 'ur') {
		
		if (document.images[nr-zellen].src == blank.src) {
			document.images[9].src = document.images[nr].src
			document.images[nr].src = document.images[nr-zellen].src;
			document.images[nr-zellen].src = document.images[9].src;
			}
		}



		// nach links
		if (x == 'om' || x == 'or' || x == 'm' || x == 'r' || x == 'um' || x == 'ur') {
		
		if (document.images[nr-1].src == blank.src) {
			document.images[9].src = document.images[nr].src
			document.images[nr].src = document.images[nr-1].src;
			document.images[nr-1].src = document.images[9].src;
			}
		}
		
		

		// nach rechts
		if (x == 'ol' || x == 'om' || x == 'l' || x == 'm' || x == 'ul' || x == 'um') {
		
		if (document.images[nr+1].src == blank.src) {
			document.images[9].src = document.images[nr].src
			document.images[nr].src = document.images[nr+1].src;
			document.images[nr+1].src = document.images[9].src;
			}
		}


		// nach oben
		if (x == 'ol' || x == 'om' || x == 'or' || x == 'l' || x == 'm' || x == 'r') {

		if (document.images[nr+zellen].src == blank.src) {
			document.images[9].src = document.images[nr].src
			document.images[nr].src = document.images[nr+zellen].src;
			document.images[nr+zellen].src = document.images[9].src;
			}
		}

}



function init_shuffle(x, y) {
   temp.src = x.src;
   x.src = y.src;
   y.src = temp.src;
}

function shuffle() {
   for(i=1; i <= anzahl ;i++) {
   init_shuffle(document.images[i],document.images[Math.floor(Math.random()*anzahl+1)]);  
      
   }
}


function mogeln(){
	for(i=0; i <= anzahl ;i++) {
		document.images[i].src = i + '.gif';
		}
		document.images[anzahl].src = 'blank.gif';
}




