var gallerypageprogress;
var gamescreenshotprogress;

function fade(opacity, id) {
	if (navigator.userAgent.indexOf('MSIE') > '-1') {
		document.getElementById(id).style.zoom = '1';
		document.getElementById(id).style.filter = 'alpha(opacity=' + opacity * 10 + ')';
	} else {
		document.getElementById(id).style.opacity = opacity / 100;
	}
	opacity = opacity + 1;
	if (opacity < '100') {
		window.setTimeout(function () { fade(opacity, id); }, 1);
	}
}

function autogallerypage(id) {
	var pages = document.getElementById('pages').getElementsByTagName('a').length;
	if (document.getElementById('gamebox_page_' + id).className != 'active') {
		for (var i = '1'; i <= pages; i ++) {
			if (i == id) {
				document.getElementById('gamebox_page_' + i).className = 'active';
				document.getElementById('gamebox_picture_' + i).style.display = 'block';
				if (navigator.userAgent.indexOf('MSIE') > '-1') {
					document.getElementById('gamebox_details_' + i).style.zoom = '1';
					document.getElementById('gamebox_details_' + i).style.filter = 'alpha(opacity=0)';
				} else {
					document.getElementById('gamebox_details_' + i).style.opacity = '0';
				}
				document.getElementById('gamebox_details_' + i).style.display = 'block';
				fade(0, 'gamebox_details_' + i);
			} else {
				document.getElementById('gamebox_page_' + i).className = '';
				document.getElementById('gamebox_picture_' + i).style.display = 'none';
				document.getElementById('gamebox_details_' + i).style.display = 'none';
			}
		}
	}
	if (pages > '1') {
		id ++;
		if (id > pages) {
			id = '1';
		}
		gallerypageprogress = window.setTimeout(function () { autogallerypage(id); }, 5000);
	}
}

function gallerypage(id) {
	clearInterval(gallerypageprogress);
	if (document.getElementById('gamebox_page_' + id).className != 'active') {
		for (var i = '1'; i <= document.getElementById('pages').getElementsByTagName('a').length; i ++) {
			if (i == id) {
				document.getElementById('gamebox_page_' + i).className = 'active';
				document.getElementById('gamebox_picture_' + i).style.display = 'block';
				if (navigator.userAgent.indexOf('MSIE') > '-1') {
					document.getElementById('gamebox_details_' + i).style.zoom = '1';
					document.getElementById('gamebox_details_' + i).style.filter = 'alpha(opacity=0)';
				} else {
					document.getElementById('gamebox_details_' + i).style.opacity = '0';
				}
				document.getElementById('gamebox_details_' + i).style.display = 'block';
				fade(0, 'gamebox_details_' + i);
			} else {
				document.getElementById('gamebox_page_' + i).className = '';
				document.getElementById('gamebox_picture_' + i).style.display = 'none';
				document.getElementById('gamebox_details_' + i).style.display = 'none';
			}
		}
	}
}

function populargames(page) {
	if (document.getElementById('button_' + page).className != 'active') {
		for (var i = '1'; i <= '3'; i ++) {
			if (i == page) {
				document.getElementById('button_' + i).className = 'active';
			} else {
				document.getElementById('button_' + i).className = '';
			}
		}
		if (page == '1') {
			var start = '1';
			var stop = '5';
		} else if (page == '2') {
			var start = '6';
			var stop = '10';
		} else if (page == '3') {
			var start = '11';
			var stop = '15';
		}
		for (var i = '1'; i <= '15'; i ++) {
			if (document.getElementById('populargame_' + i)) {
				if ((i >= start) && (i <= stop)) {
					if (navigator.userAgent.indexOf('MSIE') > '-1') {
						document.getElementById('populargame_' + i).style.zoom = '1';
						document.getElementById('populargame_' + i).style.filter = 'alpha(opacity=0)';
					} else {
						document.getElementById('populargame_' + i).style.opacity = '0';
					}
					document.getElementById('populargame_' + i).style.display = 'block';
					fade(0, 'populargame_' + i);
				} else {
					document.getElementById('populargame_' + i).style.display = 'none';
				}
			}
		}
	}
}

function autogamescreenshot(id) {
	var screenshots = document.getElementById('gamescreenshots').getElementsByTagName('a').length;
	if (document.getElementById('screenshot_' + id).className != 'active') {
		for (var i = '1'; i <= screenshots; i ++) {
			if (i == id) {
				document.getElementById('screenshot_' + i).className = 'active';
				if (navigator.userAgent.indexOf('MSIE') > '-1') {
					document.getElementById('screenshot').style.zoom = '1';
					document.getElementById('screenshot').style.filter = 'alpha(opacity=0)';
				} else {
					document.getElementById('screenshot').style.opacity = '0';
				}
				document.getElementById('screenshot').src = document.getElementById('screenshot_' + i).src;
				fade(0, 'screenshot');
			} else {
				document.getElementById('screenshot_' + i).className = '';
			}
		}
	}
	if (screenshots > '1') {
		id ++;
		if (id > screenshots) {
			id = '1';
		}
		gamescreenshotprogress = window.setTimeout(function () { autogamescreenshot(id); }, 5000);
	}
}

function gamescreenshot(id) {
	clearInterval(gamescreenshotprogress);
	if (document.getElementById('screenshot_' + id).className != 'active') {
		for (var i = '1'; i <= document.getElementById('gamescreenshots').getElementsByTagName('a').length; i ++) {
			if (i == id) {
				document.getElementById('screenshot_' + i).className = 'active';
				if (navigator.userAgent.indexOf('MSIE') > '-1') {
					document.getElementById('screenshot').style.zoom = '1';
					document.getElementById('screenshot').style.filter = 'alpha(opacity=0)';
				} else {
					document.getElementById('screenshot').style.opacity = '0';
				}
				document.getElementById('screenshot').src = document.getElementById('screenshot_' + i).src;
				fade(0, 'screenshot');
			} else {
				document.getElementById('screenshot_' + i).className = '';
			}
		}
	}
}

function review() {
	if (document.getElementById('review').style.display == 'none') {
		document.getElementById('review').style.display = 'block';
	} else {
		document.getElementById('review').style.display = 'none';
	}
}

function markrate(points) {
	for (var i = '1'; i <= '5'; i ++) {
		if (i <= points) {
			document.getElementById('points_' + i).src = 'images/star_gold.png';
		} else {
			document.getElementById('points_' + i).src = 'images/star_grey.png';
		}
	}
}

function unmarkrate() {
	var points = document.getElementById('points').value;
	for (var i = '1'; i <= '5'; i ++) {
		if (i <= points) {
			document.getElementById('points_' + i).src = 'images/star_gold.png';
		} else {
			document.getElementById('points_' + i).src = 'images/star_grey.png';
		}
	}
}

function rate(points) {
	document.getElementById('points').value = points;
}
