/*****************************************************************************
* GLOBAL INITIALIZATION
*****************************************************************************/
var yg = new Object();
// Set debugging on/off.
yg.debugging = false;
// Array of init functions.
yg.initializers = new Array();
yg.initializerDelays = new Array();
/**
* Add initializer function.
*/
yg.addInitializer = function(initializer, delay) {
yg.initializers.push(initializer);
yg.initializerDelays.push(delay);
}
/**
* Initialize services.
*/
yg.init = function() {
yg.debug("JavaScript init...");
// Loop trhough initialization functions.
for (var i = 0; i < yg.initializers.length; i++) {
yg.debug("Initializer " + i);
setTimeout(yg.initializers[i], yg.initializerDelays[i]);
}
}
/**
* This is just for debugging.
*/
yg.debug = function(message) {
if (yg.debugging) {
try {
console.log(message);
} catch(e) {
document.title = message + " " + document.title;
}
}
}
/*****************************************************************************
* TOOLTIP
*****************************************************************************/
var tip = new Object();
tip.toolTipDiv = document.createElement("div");
tip.mouseX = 0;
tip.mouseY = 0;
tip.AJAX = 1;
tip.TEXT = 2;
tip.s = function (type, value) {
if (type == tip.AJAX) {
// Ajax...
} else {
tip.toolTipDiv.innerHTML = value;
}
tip.toolTipDiv.style.visibility = "visible";
tip.toolTipDiv.style.display = "block";
}
tip.h = function () {
tip.toolTipDiv.innerHTML = "";
tip.toolTipDiv.style.visibility = "hidden";
tip.toolTipDiv.style.display = "none";
//document.onmousemove = null;
}
tip.move = function (e) {
// IE.
if (navigator.appName == "Microsoft Internet Explorer") { //document.all
tip.mouseX = event.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
tip.mouseY = event.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
} else if (navigator.appName == "Opera") {
tip.mouseX = event.clientX + document.body.scrollLeft;
tip.mouseY = event.clientY + document.body.scrollTop;
}
// Muut.
else {
tip.mouseX = e.pageX;
tip.mouseY = e.pageY;
}
tip.toolTipDiv.style.left = (tip.mouseX + 10) + "px";
tip.toolTipDiv.style.top = (tip.mouseY + 10) + "px";
if (false) {
document.title = navigator.appName + " Mouse position: " + tip.mouseX + "x" + tip.mouseY + ", tip position " + tip.toolTipDiv.style.left + "x" + tip.toolTipDiv.style.top + ".";
}
}
tip.create = function() {
yg.debug("Creating tooltip.");
var element = document.getElementById("toolTip");
tip.toolTipDiv.style.visibility = "hidden";
tip.toolTipDiv.style.display = "none";
tip.toolTipDiv.className = "toolTip";
tip.toolTipDiv.innerHTML = "";
element.appendChild(tip.toolTipDiv);
document.onmousemove = tip.move;
}
// Add initializer.
yg.addInitializer(tip.create);
/*****************************************************************************
* LEAD FLASH
*****************************************************************************/
// Browser plugin support check.
var MM_contentVersion = 8;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
var words = navigator.plugins["Shockwave Flash"].description.split(" ");
for (var i = 0; i < words.length; ++i ) {
if (isNaN(parseInt(words[i])))
continue;
MM_PluginVersion = words[i];
}
var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
&& (navigator.appVersion.indexOf("Win") != -1)) {
document.write(' \n');
}
var leadFlash = new Object();
/**
* Place flash player.
*/
leadFlash.placeLeadFlash = function () {
var leadFlashDiv = document.getElementById("leadflash");
// If doesn't exists, quit.
if (!leadFlashDiv) {
return false;
}
var src = "";
if ( MM_FlashCanPlay ) {
src += '
' ;
} else {
src += '
' ;
}
leadFlashDiv.innerHTML = src;
}
/**
* Send play command to lead flash.
*/
leadFlash.playLeadFlash = function () {
// IE.
if(window.leadFlashPlayer) {
yg.debug("Lead flash: IE");
window.document["leadFlashPlayer"].SetVariable("aloita", true);
} else if(document.leadFlashPlayer) {
yg.debug("Lead flash: FX");
document.leadFlashPlayer.SetVariable("aloita", true);
} else {
yg.debug("Couldn't find lead flash player!");
}
}
//yg.addInitializer(leadFlash.playLeadFlash, 0);
/*****************************************************************************
* GAME RATING
*****************************************************************************/
/**
* Object that handles the drawing of user ratings.
*
* @access public
* @return void
**/
function Rating(){
// Bindings.
this.getStars = getStars;
this.showRating = showRating;
this.release = release;
this.setRating = setRating;
// Game original rating list.
this.gameRatings = new Array();
// Star images.
this.stars = new Array();
// Image urls.
var shineStarUrl = "/elements/misc/game_infobox/images/star_shine.gif";
var noshineStarUrl = "/elements/misc/game_infobox/images/star_noshine.gif";
/**
* Change visible rating on mouse over.
*
* @access public
* @return void
**/
function showRating(gameid, rating){
var i = 1;
try {
for (i = 1; i < this.stars[gameid].length; i++) {
if(i <= rating) {
this.stars[gameid][i].src = shineStarUrl;
} else {
this.stars[gameid][i].src = noshineStarUrl;
}
}
} catch(e) {
yg.debug("ratings.showRating: gameid " + gameid + " rating " + rating + " " + i + " " + e.toString());
}
}
/**
* Show original rating.
*
* @access public
* @return void
**/
function release(gameid) {
try {
ratings.showRating(gameid, ratings.gameRatings[gameid]);
} catch(e) {
yg.debug("ratings.release: " + e.toString());
}
}
/**
* Submit user rating.
*
* @access public
* @return void
**/
function setRating(gameid, rating){
// Submit vote.
new Ajax.Request("/games/"+gameid+"/?rate="+rating, { method:'get' });
// Freeze current situation by deleting actions.
try {
for (var i = 1; i < this.stars[gameid].length; i++) {
this.stars[gameid][i].onmouseover = function(){tip.s(2, "You have already voted.");};
this.stars[gameid][i].onmouseout = function(){tip.h();};
this.stars[gameid][i].onclick = null;
}
} catch(e) {
yg.debug("ratings.setRating: " + e.toString());
}
}
/**
* Print stars.
*
* @access public
* @return void
**/
function getStars(elementId, gameid, rating, enableRating){
// Set game rating.
this.gameRatings[gameid] = rating;
this.stars[gameid] = new Array();
// Get element.
var ratingParent = document.getElementById(elementId);
if (!ratingParent) {
return false;
}
// Append stars.
for (var i = 1; i <= 5; i++) {
// Create image.
var img = document.createElement("img");
// Set parameters
img.gameid = gameid;
img.i = i;
if (enableRating) {
img.onmouseover = function () { ratings.showRating(this.gameid, this.i); };
img.onmouseout = function () { ratings.release(this.gameid); };
img.onclick = function () { ratings.setRating(this.gameid, this.i); };
} else {
img.onmouseover = function(){tip.s(2, "You have already voted or you are not logged in.");};
img.onmouseout = function(){tip.h();};
}
// Add to list.
this.stars[gameid][i] = img;
// Set image src.
if(i <= rating) {
img.src = "/elements/misc/game_infobox/images/star_shine.gif";
} else {
img.src = "/elements/misc/game_infobox/images/star_noshine.gif";
}
ratingParent.appendChild(img);
}
}
}
var ratings = new Rating();
/*****************************************************************************
* SHOUTBOX
*****************************************************************************/
var chat = new Object();
chat.limit = 6;
chat.updateInterval = 5000;
chat.style = "frontpage";
chat.messageAreaId = "shoutBox";
chat.updateUrl = "/forum/fmext/infernoshout.php";
// Enable long line splitting and javascript message limiting.
chat.processLines = true;
/**
* Update message field.
*/
chat.update = function() {
// Start loading animation or whatever...
chat.onLoadStart();
// Request new messages.
$.ajax({
type: "get",
url: this.updateUrl + "?style="+this.style+"&limit="+this.limit+"&hash=" + Math.random(),
dataType: "xml",
success: chat.updateMessageField
});
/*
new Ajax.Request(this.updateUrl + "?style="+this.style+"&limit="+this.limit+"&hash=" + Math.random(), {
method: "get",
parameters: {},
onSuccess: chat.updateMessageField
});
*/
// Recall.
setTimeout("chat.update()", this.updateInterval);
}
chat.updateMessageField = function(content, status) {
// Get response xml.
var xmlObject = content;
var output = "";
try {
var elements = xmlObject.getElementsByTagName('shout');
for (var i = 0; i < elements.length; i++) {
var userid = elements.item(i).attributes.getNamedItem("userid").value;
var username = elements.item(i).attributes.getNamedItem("username").value;
var time = elements.item(i).attributes.getNamedItem("timestamp").value;
var groupid = elements.item(i).attributes.getNamedItem("usergroupid").value;
var message = elements.item(i).firstChild.data;
// Split long message lines.
message = chat.breakLongLines(message);
// Color username, if admin.
if (groupid == 6) {
username = "" + username + "";
} else if (groupid == 5 || groupid == 7) {
username = "" + username + "";
} else if (groupid == 18 || groupid == 19) {
username = "" + username + "";
} else if (groupid == 39) {
username = "" + username + "";
}
// Convert from from unix-time to human readable time.
var d = new Date(time * 1000);
time = "" + chat.addLeadingZero(d.getHours()) + ":" + chat.addLeadingZero(d.getMinutes());
output += chat.drawRow(userid, username, time, message);
}
} catch(e) {
//document.title += "Error: " + e.toString();
}
// Add output.
document.getElementById(chat.messageAreaId).innerHTML = output;
chat.onLoadComplete();
return;
}
chat.addLeadingZero = function(n) {
n = n.toString();
if (n.length == 1) {
n = "0" + n;
}
return n;
}
/**
* Draws single message row. If you want to create your own template,
* just override this method.
*/
chat.drawRow = function(userid, username, time, message) {
return "
| " + " ["+time+"] " + " | " + "" + "" + "" + "<"+username+">" + "" + "" + " | " + "" + ""+message+"" + " | " + "