var wrapImageValue = "rbw";
var satunnaisluku;
var vertailutaulukko = new Array();


var rb = new Array();
rb[0] = "RIGHT-BACKSIDE";
rb[1] = "right-backside";
rb[2] = "right backside";
rb[3] = "Right-backside";
rb[4] = "Right backside";
rb[5] = "Right Backside";
rb[6] = "right Backside";
rb[7] = "right back side";
rb[9] = "Right back side";
rb[10] = "Right Back side";
rb[11] = "Right Back Side";
rb[12] = "RIGHT BACKSIDE";
rb[13] = "RIGHT BACK SIDE";
rb[14] = "Right-backside";
rb[15] = "Right-Backside";
rb[16] = "LEFT FRONTSIDE";
rb[17] = "LEFT-FRONTSIDE";
rb[18] = "LEFT FRONT SIDE";
rb[19] = "left frontside";
rb[20] = "left-frontside";
rb[21] = "Left frontside";
rb[22] = "Left Frontside";
rb[23] = "left front side";
rb[24] = "Left front side";
rb[25] = "Left Front Side";
rb[26] = "Left Front side";
rb[27] = "Left-Frontside";
rb[28] = "Left-frontside";
rb[29] = "left Frontside";
rb[30] = "rightbackside";

var lb = new Array();
lb[0] = "leftbackside";
lb[1] = "left-backside";
lb[2] = "left backside";
lb[3] = "Left-backside";
lb[4] = "Left backside";
lb[5] = "Left Backside";
lb[6] = "left Backside";
lb[7] = "left back side";
lb[9] = "Left back side";
lb[10] = "Left Back side";
lb[11] = "Left Back Side";
lb[12] = "LEFT BACKSIDE";
lb[13] = "LEFT BACK SIDE";
lb[14] = "Left-backside";
lb[15] = "Left-Backside";
lb[16] = "RIGHT FRONTSIDE";
lb[17] = "RIGHT-FRONTSIDE";
lb[18] = "RIGHT FRONT SIDE";
lb[19] = "right frontside";
lb[20] = "right-frontside";
lb[21] = "Right frontside";
lb[22] = "Right Frontside";
lb[23] = "right front side";
lb[24] = "Right front side";
lb[25] = "Right Front Side";
lb[26] = "Right Front side";
lb[27] = "Right-Frontside";
lb[28] = "Right-frontside";
lb[29] = "right Frontside";
lb[30] = "LEFT-BACKSIDE";

var rbw = new Array();
rbw[0] = "rightbackwrap";
rbw[1] = "right backwrap";
rbw[2] = "rightback wrap";
rbw[3] = "Rightbackwrap";
rbw[4] = "Right backwrap";
rbw[5] = "Right Backwrap";
rbw[6] = "Right back wrap";
rbw[7] = "Right Back Wrap";
rbw[8] = "right-backwrap";
rbw[9] = "Right-backwrap";
rbw[10] = "Right-Backwrap";
rbw[11] = "RIGHTBACKWRAP";
rbw[12] = "RIGHT BACKWRAP";
rbw[13] = "RIGHT BACK WRAP";
rbw[14] = "RIGHT-BACKWRAP";
rbw[15] = "rightbackwrap";
rbw[16] = "leftfrontwrap";
rbw[17] = "left frontwrap";
rbw[18] = "left front wrap";
rbw[19] = "Leftfrontwrap";
rbw[20] = "Left frontwrap";
rbw[21] = "Left Frontwrap";
rbw[22] = "Left Front wrap";
rbw[23] = "Left Front Wrap";
rbw[24] = "left-frontwrap";
rbw[25] = "Left-frontwrap";
rbw[26] = "Left-Frontwrap";
rbw[27] = "LEFTFRONTWRAP";
rbw[28] = "LEFT FRONTWRAP";
rbw[29] = "LEFT FRONT WRAP";
rbw[30] = "LEFT-FRONTWRAP";
rbw[31] = "LEFT-FRONT WRAP";

var lbw = new Array();
lbw[0] = "leftbackwrap";
lbw[1] = "left backwrap";
lbw[2] = "leftback wrap";
lbw[3] = "Leftbackwrap";
lbw[4] = "Left backwrap";
lbw[5] = "Left Backwrap";
lbw[6] = "Left back wrap";
lbw[7] = "Left Back Wrap";
lbw[8] = "left-backwrap";
lbw[9] = "Left-backwrap";
lbw[10] = "Left-Backwrap";
lbw[11] = "LEFTBACKWRAP";
lbw[12] = "LEFT BACKWRAP";
lbw[13] = "LEFT BACK WRAP";
lbw[14] = "LEFT-BACKWRAP";
lbw[15] = "leftback wrap";
lbw[16] = "rightfrontwrap";
lbw[17] = "right frontwrap";
lbw[18] = "right front wrap";
lbw[19] = "Rightfrontwrap";
lbw[20] = "Right frontwrap";
lbw[21] = "Right Frontwrap";
lbw[22] = "Right Front wrap";
lbw[23] = "Right Front Wrap";
lbw[24] = "right-frontwrap";
lbw[25] = "Right-frontwrap";
lbw[26] = "Right-Frontwrap";
lbw[27] = "RIGHTFRONTWRAP";
lbw[28] = "RIGHT FRONTWRAP";
lbw[29] = "RIGHT FRONT WRAP";
lbw[30] = "RIGHT-FRONTWRAP";
lbw[31] = "RIGHT-FRONT WRAP";

vertailutaulukko = rbw;
var wrapPisteet = 0;

function tarkistasprinkit()  {
  if(document.getElementById("sprink1").value == "LeftBackwrap"){
    document.getElementById("sprinkcheck1").src = "ok.jpg";
  }
  else {
    document.getElementById("sprinkcheck1").src = "nok.jpg";
  }

  if(document.getElementById("sprink2").value == "RightBackwrap"){
    document.getElementById("sprinkcheck2").src = "ok.jpg";
  }
  else {
    document.getElementById("sprinkcheck2").src = "nok.jpg";
  }

  if(document.getElementById("sprink3").value == "LeftFrontwrap"){
    document.getElementById("sprinkcheck3").src = "ok.jpg";
  }
  else {
    document.getElementById("sprinkcheck3").src = "nok.jpg";
  }

  if(document.getElementById("sprink4").value == "RightFrontwrap"){
    document.getElementById("sprinkcheck4").src = "ok.jpg";
  }
  else {
    document.getElementById("sprinkcheck4").src = "nok.jpg";
  }

}



function tarkistawrap()  {
var tarkistuspisteet = wrapPisteet;

  // Silmukka jossa tarkastetaan onko annettu vastaus jokin mŠŠritellyistŠ
  for (i = 0; i <= rb.length; i++)
  {
    if(document.getElementById("wrapinput").value==vertailutaulukko[i]) {
       wrapPisteet++;
       
    }

  }

if(tarkistuspisteet == wrapPisteet){
  alert("You got it wrong. The correct answer would have been the " +vertailutaulukko[5]+".");
}

document.getElementById("scoreboard").value = wrapPisteet;

if(wrapPisteet == 20) {
  alert("I think you have learned the lesson here. You can now continue to the other tutorials.");
}

if(wrapPisteet == 40) {
  alert("Awesome. Now we can call you King of Wraps. It's time to move to the other tutorials, my majesty.");
}

if(wrapPisteet == 100) {
  alert("Seriously, I can't possibly imagine why you still continue.");
}

if(wrapPisteet == 130) {
  alert("Aye Captain. You sire are mad.");                       
}

if(wrapPisteet == 150) {
  alert("Seriously, I can't possibly imagine why you still continue.");                       
}

if(wrapPisteet == 200) {
  alert("This is the last message you'll get. No point for doing this.");                       
}

if(wrapPisteet == 1000) {
  alert("Instead of naming thousand wraps correctly, well... i bet you could have learned 3D Low  *wink*");                       
}




arvonta();

}

function arvonta() {

var alkuperainen = vertailutaulukko;

while(alkuperainen == vertailutaulukko) {

// Arvotaan luku
satunnaisluku = Math.random();

// Asetetaan kuva ja annetaan sitŠ vastaavat oikeat vastaukset
if(satunnaisluku < 0.25) {
   document.getElementById("wrappic").src ="right-backside.jpg";
   vertailutaulukko = rb;
}
else if(satunnaisluku < 0.5) {
   document.getElementById("wrappic").src = "left-backside.jpg";
   vertailutaulukko = lb;
}
else if(satunnaisluku < 0.75) {
   document.getElementById("wrappic").src = "rightbackwrap.jpg";
   vertailutaulukko = rbw;
}
else {
   document.getElementById("wrappic").src = "leftbackwrap.jpg";
   vertailutaulukko = lbw;
}

}

}

// *********************** Drag & Drop testi ***************************

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};




// ******************** Domia toteuttava koodi ********************

	var reportBox, iReportCount = 0;

	window.onload = function() {
		if (document.all || document.getElementById)
		{
			var oRFTrap = document.all ? document.all["RFTrap"] : document.getElementById("RFTrap")
			var oLFTrap = document.all ? document.all["LFTrap"] : document.getElementById("LFTrap")
			var oLTrap = document.all ? document.all["LTrap"] : document.getElementById("LTrap")
			var oRTrap = document.all ? document.all["RTrap"] : document.getElementById("RTrap")
			
		
			reportBox  = document.all ? document.all["oReport"] : document.getElementById("oReport")
			reportBox2 = document.all ? document.all["oReport2"] : document.getElementById("oReport2")

			Drag.init(oRFTrap, null, -105, 352, -123, 107);
			
			Drag.init(oLFTrap, null, -7, 450, -123, 107);
			
			Drag.init(oLTrap, null, -7, 450, -196, 34);
			Drag.init(oRTrap, null, -105, 352, -196, 34);

            oLFTrap.onDragEnd = function(x, y) { reportDragEnd("LFTrap", x, y); }
            oRFTrap.onDragEnd = function(x, y) { reportDragEnd("RFTrap", x, y); }
            oLTrap.onDragEnd = function(x, y) { reportDragEnd("LTrap", x, y); }
            oRTrap.onDragEnd = function(x, y) { reportDragEnd("RTrap", x, y); }

			// report stuff hu
			//oB.onDragStart = function(x, y) { reportDragStart("black", x, y); }
			//oG.onDragStart = function(x, y) { reportDragStart("green", x, y); }
			//oP.onDragStart = function(x, y) { reportDragStart("purple", x, y); }

			//oB.onDragEnd = function(x, y) { reportDragEnd("black", x, y); }
			//oG.onDragEnd = function(x, y) { reportDragEnd("green", x, y); }
			//oP.onDragEnd = function(x, y) { reportDragEnd("purple", x, y); }

			//oB.onDrag = function(x, y) { reportDrag("black", x, y); }
			//oG.onDrag = function(x, y) { reportDrag("green", x, y); }
			//oP.onDrag = function(x, y) { reportDrag("purple", x, y); }
			//alert(document.getElementById("dragYlaRaja").offsetTop);
            //alert(document.getElementById("dragVasenRaja").offsetLeft);
		}

		function reportDragStart(who, x, y) {
			reportBox.value += who + " | onDragStart " + " (" + x + "," + y + ")\n"
		}

		function reportDragEnd(who, x, y) {
			//reportBox.value += who + " | onDragEnd " + " (" + x + "," + y + ")\n"
			
			// Alerttaa x&y sijainnin
			//alert("X:" + x + " Y:" + y);
			
			// Kuvan RFTrap tarkistukset sijainnista
			if(who == "RFTrap" && x > 220 && y < -40) {
			   document.getElementById("RFTrap").src = "vanish.png";
                           document.getElementById("indicate4").src = "ok.jpg";   
                           //alert("RFTrap ok");
			}
			else {
			   //trapetsi ei ole ok.
			}
			
			// Kuvan LTrap tarkistukset sijainnista
			if(who == "LTrap" &&  x > 320 && y < -115) {
		           document.getElementById("LTrap").src = "vanish.png";
                           document.getElementById("indicate1").src = "ok.jpg";	   
                           //alert("LTrap ok");
			}
			else {
			   // trapetsi ei ole ok
			}
			
			// Kuvan LFTrap tarkistukset sijainnista
		    if(who == "LFTrap" && x > 320 && y > 30) {
                           document.getElementById("LFTrap").src = "vanish.png";
                           document.getElementById("indicate3").src = "ok.jpg";
			   //alert("LFTrap ok");
			}
			else {
			   //trapetsi ei ole ok.
			}
						
			// Kuvan RTrap tarkistukset sijainnista
		    if(who == "RTrap" && x > 220 && y > -43) {
                           document.getElementById("RTrap").src = "vanish.png";
                           document.getElementById("indicate2").src = "ok.jpg";
			   //alert("RTrap ok");
			}
			else {
			   //trapetsi ei ole ok.
			}
			
			
			
		}

		function reportDrag(who, x, y) {
			reportBox2.value = who + " | onDrag " + " (" + x + "," + y + ")"
		}
	}
