﻿function gameinfo(game)
{
	var gamelist = [];
		gamelist[1] = [];
			gamelist[1][0] = '1';
			gamelist[1][1] = 'Konkursy';
			gamelist[1][2] = 'Konkursy z nagrodami';
			gamelist[1][3] = "img/misc/games01.png";
		gamelist[2] = [];
			gamelist[2][0] = '2';
			gamelist[2][1] = 'Zielony Kamyk';
			gamelist[2][2] = 'Historia pewnego komputerowca, pewnego miasteczka i niepozornego, zielonego kamienia';
			gamelist[2][3] = "img/misc/greenstone_icon.png";
		gamelist[0] = [];
			gamelist[0][0] = '0';
			gamelist[0][1] = 'Ciekawe miejsca';
			gamelist[0][2] = 'Gdzie znajduje się skarb, a gdzie należy w ciemnościach oczekiwać białej postaci wędrującej po murach zamku.';
			gamelist[2][3] = "img/misc/games_2.png";
	
	document.getElementById("desc").innerHTML = "<b><center>"+gamelist[game][1]+"</b><br><br><img style=\"width: 300px; \" src="+gamelist[game][3]+"><br>"+gamelist[game][2]+"<br><a  href=\""+gamelist[game][0]+".php\"><img src=\"img/buttons/proceed.png\"></a>";
}

function show_chapter(chapter)
{
 for(var i=0; i<4; i++)
 {
	if(document.getElementById(i))
	{
	document.getElementById(i).style.display="none";
	}
 }
	document.getElementById(chapter).style.display="block";
 
}

function show_gamepart(selected)
{
 for(var i=0; i<7; i++)
 {
  if(document.getElementById(i))
  {
   document.getElementById(i).style.display="none";
  }
 }
 document.getElementById(selected).style.display="block";
}

function b01_show_gallery(curpos)
{
	var gal_img = new Image();
	gal_img.src = gallery[curpos];
	gal_img.style.visibility = "hidden";
	if(navigator.appName!="Microsoft Internet Explorer")
	{
		gal_img.onload=function()
		{
		if(gal_img.width>800 && gal_img.width>gal_img.height )
			{
				var ratio = Math.round((800/gal_img.width)*1000)/1000;
				gal_img.style.width = 800+"px";
			}
		else if(gal_img.height>600)
			{
				var ratio = Math.round((600/gal_img.height)*1000)/1000;
				gal_img.style.height = 600+"px";
			}

		gal_img.style.marginTop = (600-gal_img.height)/2+"px";
		gal_img.style.marginLeft = (800-gal_img.width)/2+"px";
		gal_img.style.visibility = "visible";
		
	}
	}else //--re-run the func if IE. Reason? IE treats them as already loaded.
	{
		if(gal_img.width>800 && gal_img.width>gal_img.height)
			{
				var ratio = Math.round((800/gal_img.width)*1000)/1000;
				gal_img.style.width = 800+"px";
				gal_img.style.height = Math.round(gal_img.height*ratio)+"px";
			}
			else if(gal_img.height>600)
			{
				var ratio = Math.round((600/gal_img.height)*1000)/1000;
				gal_img.style.height = 600+"px";
				gal_img.style.width = Math.round(gal_img.width*ratio)+"px";
			}
			
			if(document.getElementById("galleryimage"))
		{
		 document.getElementById("gal_img").removeChild(document.getElementById("galleryimage"));
		}

			document.getElementById("gal_img").appendChild(gal_img);

			var h = gal_img.height;
			var w = gal_img.width;

			gal_img.style.marginLeft = (800-w)/2+"px";
			gal_img.style.marginTop = (600-h)/2+"px";
			gal_img.style.visibility = "visible";
	}
	gal_img.id = "galleryimage";
	if(document.getElementById("nextbutton"))
	{
	 document.getElementById("button_right").removeChild(document.getElementById("nextbutton"));
	}
	if(document.getElementById("previousbutton"))
	{
	 document.getElementById("button_left").removeChild(document.getElementById("previousbutton"));
	}
	
	var bprev = new Image();
	
	bprev.id="previousbutton";
	bprev.className="gallery_arr";
	if(curpos>0)
	{
		var prevpos=curpos-1;
				bprev.name=prevpos;
		bprev.src = 'img/buttons/arrleft.png';
		bprev.onclick = function(){b01_show_gallery(parseInt(this.name))};
	}
	else
	{
		bprev.src = 'img/buttons/arrleft_red.png';
	}
	document.getElementById("button_left").appendChild(bprev);
	
	
	var bnext = new Image();

		bnext.id="nextbutton";
		bnext.className = "gallery_arr";
	if(curpos<gallery.length-1)
	{
		var nextpos=curpos+1;
				bnext.name=nextpos;
		bnext.src = 'img/buttons/arrright.png';
		bnext.onclick = function(){b01_show_gallery(parseInt(this.name))};
	}
	else
	{
		bnext.src = 'img/buttons/arrright_red.png';
	}
	document.getElementById("button_right").appendChild(bnext);
	
	if(document.getElementById("galleryimage"))
		{
		 document.getElementById("gal_img").removeChild(document.getElementById("galleryimage"));
		}
	
	document.getElementById("gal_img").appendChild(gal_img);
}

