var timeoutIN, timeoutOUT, frameDuration = 50;

function AnimateIN(id, current, max)
{
	if(current < max)
	{
		current++;
		document.getElementById(id).src = "./Images/" + id + "_" + current + ".jpg";
		timeoutIN = setTimeout("AnimateIN('" + id + "', " + current + ", " + max + ")", frameDuration);
	}
	else
	{
		clearTimeout(timeoutIN);
	}
}

function AnimateOUT(id, current, min)
{
	if(current > min)
	{
		current--;
		document.getElementById(id).src = "./Images/" + id + "_" + current + ".jpg";
		timeoutOUT = setTimeout("AnimateOUT('" + id + "', " + current + ", " + min + ")", frameDuration);
	}
	else
	{
		clearTimeout(timeoutOUT);
	}
}

function Preload(name, max)
{
	if(max == 0) document.getElementById("Preload").src = "./Images/" + name + ".jpg";
	else
	{
		for(i = 1; i <= max; i++)
		{
			document.getElementById("Preload").src = "./Images/" + name + "_" + i + ".jpg";
		}
	}
}

function checkEnter(e)
{
	var characterCode;
	if(e && e.which)
	{
		e = e
		characterCode = e.which
	}
	else
	{
		e = event
		characterCode = e.keyCode
	}
	if(characterCode == 13) return true;
	else return false;
}

function mailto(adress)
{
	location.href = 'mailto:' + adress;
}

var alphabet = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','(',')','~','!','@','#','$','%','^','&','*','-','=','+','_','.',',','`','{','}','[',']','|','\'','\\','\"','/','?',':',';','>','<',' ','\n');
var tempbin = new Array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","a");
var binary = new Array();
var encalphabet;
var decrypted;
var encrypted;

function makebinary(l, start, z)
{
	if(l < 0) return;
	if(tempbin[l] == "1")
	{
		tempbin[l] = "0";
		x = makebinary(l-1,start,z);
	}
	else if(tempbin[l] == "0")
	{
		tempbin[l] = "1";
	}
	else if(tempbin[l] == "a")
	{
		tempbin[l] = "0";
	}
	if(l == start)
	{
		binary[z] = "";
		for (i = 0; i <= l; i++) binary[z] += tempbin[i];
	}
	return;
}

for(z = 0; z < alphabet.length; z++)
{
	makebinary(tempbin.length-1,tempbin.length-1,z);
}

function in_encalphabet(x)
{
	if(x == -1) return 0;
	z = alphabet[x];
	for(i = 0; i < encalphabet.length; i++)
	{
		if(z == encalphabet.substr(i,1))
		return 0;
	}
	return 1;
}

function encrypt(decrypted)
{
	encalphabet = "";
	encrypted = "";
	for(i = 0; i < alphabet.length; i++)
	{
		x = -1;
		while(in_encalphabet(x) == 0) x = Math.floor(alphabet.length*Math.random());
		encalphabet += alphabet[x];
	}
	temp = encalphabet;
	for(i = 0; i < decrypted.length; i++)
	{
		for(z = 0; z < encalphabet.length; z++)
		{
			if(decrypted.substr(i,1) == alphabet[z])
			{
				temp += encalphabet.substr(z,1);
				break;
			}
		}
	}
	for(i = 0; i < temp.length; i++)
	{
		for(z = 0; z < alphabet.length; z++)
		{
			if(temp.substr(i,1) == alphabet[z])
			{
				encrypted += binary[z];
				break;
			}
		}
	}
	return encrypted;
}

function decrypt(encrypted)
{
	encalphabet = "";
	temp = "";
	decrypted = "";
	for(i = 0; i < encrypted.length; i+=tempbin.length)
	{
		for(z = 0; z < alphabet.length; z++)
		{
			if(encrypted.substr(i,tempbin.length) == binary[z])
			{
				temp += alphabet[z];
				break;
			}
		}
	}
	for(i = 0; i < alphabet.length; i++) encalphabet += temp.substr(i,1);
	while(i < encrypted.length)
	{
		for(z = 0; z < encalphabet.length; z++)
		{
			if(temp.substr(i,1) == encalphabet.substr(z,1))
			{
				decrypted += alphabet[z];
				break;
			}
		}
		i++;
	}
	return decrypted;
}

