function init() {
	var e;
	e = document.getElementById("languageEn");
	e.onclick = function() {
		//document.getElementById("languageSwitch").value = "en";
		//document.getElementById("languageForm").submit();
		document.location.href = "index.php?site=ChangeLanguage-en";
	}
	e = document.getElementById("languagePl");
	e.onclick = function() {
		//document.getElementById("languageSwitch").value = "pl";
		//document.getElementById("languageForm").submit();
		document.location.href = "index.php?site=ChangeLanguage-pl";
	}

	e = document.getElementById("email");
	if (e != null) {
		getMail(e, 0);
	}

	externalLinks();
	
	// This is only temporary solution. We have to force resize too big images.
	var allImages = document.getElementsByTagName("img");
	var i, iWidth, iHeight;
	//var MaxWidth = 580;
	var MaxWidth = 560;
	var debug = "";
	for (i = 0; i < allImages.length; i++) {
		iWidth = allImages[i].width;
		iHeight = allImages[i].height;
		if (iWidth > MaxWidth) {
			allImages[i].width = MaxWidth;
			allImages[i].height = MaxWidth / iWidth * iHeight;
		}
		debug += allImages[i].name +","+ allImages[i].width +","+ allImages[i].width + "\n";
	}
}

function externalLinks() {
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external")) {
			anchor.target = "_blank";
		}
	}
}

/**
 * Function encrypts email (modified tool from:
 * http://www.dynamicdrive.com/emailriddler/)
 * @param {Object} object This is DOM object (usually "this" DIV) that will be
 * displayed on web page as an email link.
 * @param {int} emailNumber This is parameter that tells which email to display,
 * list is closed. At the moment only value is 0, which means marti address.
 * @return object
 */
function getMail(object, emailNumber) {
	var emailData;
	switch (emailNumber) {
		default:
			emailData = [109,97,114,116,105,64,112,114,101,115,101,110,116,115,46,112,108];
	}
	var encryptedEmail = ""; //variable to contain encrypted email
	for (var i = 0; i < emailData.length; i++)
		encryptedEmail += String.fromCharCode(emailData[i]);
	object.onclick = function() {
		document.location.href = "mailto:" + encryptedEmail;
	}
}

function contactSend(e) {
	// form validation
	//var form = e.parentNode.parentNode;
	var canBeSubmitted = true;
	var temp = document.forms[0]["contactName"].value;
	if (temp == null || temp == "") {
		alert("Please, enter your name.");
		return;
	}
	temp = document.forms[0]["contactEmail"].value;
	if (temp == null || temp == "") {
		alert("Please, enter your email address. It is very important in case I need to contact you.");
		return;
	}
	temp = document.forms[0]["contactBody"].value;
	if (temp == null || temp == "") {
		alert("Please, enter a message. What is the point of contacting me if you have nothing to say? :)");
		return;
	}
	// disable button and send
	if (canBeSubmitted) {
		e.disabled = true;
		e.parentNode.parentNode.submit();
	}
}

function submitForm(button) {
	var form = button.form;
	if (form.elements["apple"].value == "" || form.elements["apple"].value == null) {
		alert("If you want to comment you should write something into comment field, isn't it? :)");
		return;
	}
	button.disabled = true;
	form.submit();
}

function commentForm() {
	var hiddenForm = document.getElementById("hiddenForm");
	if (hiddenForm.style.display == "block") {
		hiddenForm.style.display = "none";
	} else {
		hiddenForm.style.display = "block";
	}
}

