var currentScreenshot = new Object();

currentScreenshot['group1'] = 1;
currentScreenshot['group2'] = 1;
currentScreenshot['group3'] = 1;
currentScreenshot['group4'] = 1;

var notifyGif;

function toogleScreenshot(groupName) {
	var wasSmall = document.getElementById(groupName).getElementsByClassName('screenshot')[0].className == 'screenshot';

	decreaseScreenshot("group1");
	decreaseScreenshot("group2");
	decreaseScreenshot("group3");
	decreaseScreenshot("group4");
	
	if (wasSmall) {
		enlargeScreenshot(groupName);
	}
}

function enlargeScreenshot(groupName) {
	document.getElementById(groupName).getElementsByClassName('screenshot')[0].className = 'screenshot zoomed';
}

function decreaseScreenshot(groupName) {
	document.getElementById(groupName).getElementsByClassName('screenshot')[0].className = 'screenshot';
}

function previousScreenshot(groupName) {
	currentScreenshot[groupName] -= 1;
	
	if (currentScreenshot[groupName] < 1) currentScreenshot[groupName] = 4;
	else if (currentScreenshot[groupName] > 4) currentScreenshot[groupName] = 1;
	
	hideScreenshot(groupName, "image1");
	hideScreenshot(groupName, "image2");
	hideScreenshot(groupName, "image3");
	hideScreenshot(groupName, "image4");
	
	showScreenshot(groupName, "image" + currentScreenshot[groupName]);
}

function nextScreenshot(groupName) {
	currentScreenshot[groupName] += 1;
	
	if (currentScreenshot[groupName] < 1) currentScreenshot[groupName] = 4;
	else if (currentScreenshot[groupName] > 4) currentScreenshot[groupName] = 1;
	
	hideScreenshot(groupName, "image1");
	hideScreenshot(groupName, "image2");
	hideScreenshot(groupName, "image3");
	hideScreenshot(groupName, "image4");
	
	showScreenshot(groupName, "image" + currentScreenshot[groupName]);
}

function showScreenshot(groupName, imageName) {
	document.getElementById(groupName).getElementsByClassName(imageName)[0].className = imageName + " shown";
	document.getElementById(groupName).getElementsByClassName(imageName)[1].className = imageName + " shown";
}

function hideScreenshot(groupName, imageName) {
	document.getElementById(groupName).getElementsByClassName(imageName)[0].className = imageName;
	document.getElementById(groupName).getElementsByClassName(imageName)[1].className = imageName;
}

function populate() {
	var i = 1;
	var j = 1;
	for (i = 1; i <= 4; i++) {
		for (j = 1; j <= 4; j++) {
			document.getElementById("group" + i).getElementsByClassName("image" + j)[0].src = "/images/screenshot" + i + j + ".png";
			document.getElementById("group" + i).getElementsByClassName("image" + j)[1].src = "/images/screenshotBig" + i + j + ".png";
		}
	}
}

function notify() {
	if (document.getElementById("notifyEmail").value.length == 0 || document.getElementById("notifyEmail").value == document.getElementById("notifyEmail").getAttribute("placeholder")) {
		document.getElementById("notifyEmail").style.backgroundColor = "rgb(255, 230, 230)";
		
		return;
	}
	document.getElementById("notify").getElementsByClassName("form")[0].style.opacity = "0";
	document.getElementById("notifyName").disabled = true;
	document.getElementById("notifyEmail").disabled = true;
	document.getElementById("notifySubmit").disabled = true;
	notifyGif = new Image();
	notifyGif.onLoad = finishedNotify();
	notifyGif.src = "/sitenotify.php?name=" + escape(document.getElementById("notifyName").value) + "&email=" + escape(document.getElementById("notifyEmail").value);
}

function finishedNotify() {
	document.getElementById("notify").getElementsByClassName("check")[0].style.opacity = "1";
}

function activatePlaceholders() {
	if ('placeholder' in document.createElement('input')) return false;
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++) {
		//if (inputs[i].getAttribute("type") == "text" || inputs[i].getAttribute("type") == "email" ) {
			if (inputs[i].getAttribute("placeholder") && inputs[i].getAttribute("placeholder").length > 0) {
				if (inputs[i].value.length == 0) {
					inputs[i].value = inputs[i].getAttribute("placeholder");
				}
				inputs[i].onclick = function() {
					if (this.value == this.getAttribute("placeholder")) {
						this.value = "";
					}
					return false;
				}
				inputs[i].onblur = function() {
					if (this.value.length < 1) {
						this.value = this.getAttribute("placeholder");
					}
				}
			}
		//}
	}
}
