if (IN_FBOOK && approot) {
	if (this == this.parent) {
		this.parent.location.href=approot+'home';
	}
}

// Fetch a single line of text from the language file
function __(key, params) {
	if (typeof(langDict)!='undefined' && langDict[key]) {
		var translation = langDict[key];
		if(typeof params =="object"){//array
			for(var i=0;i<params.length;i++){
				translation = translation.replace(/%s/,params[i]);
			}
		}else if(typeof params =="string"){//string
			translation =  translation.replace(/%s/,params);
		}
		return translation;
	} else {
		return key;
	}
}

//TODO: We may like to convert all those arrays to objects and check if the key exists, instead of using indexOf?
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

//number to currency format
Number.prototype.format = function( ){
		var number = this + '';
		x = number.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
		   x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
}

//WHY IS IT HERE??
// make "Recruit Racers" button clickable
jQuery(document).ready(function($){
	/*
	$(':button[@value="'+__('recruit_racers')+'"]').click(function() {
		document.location.href = webroot+'friends/find_friends';
	});
	*/

	if (0 && IN_FBOOK && approot) {
		$('a').each(function() {
			if ($(this).attr('href') && $(this).attr('href').substring(0,1) != '#') {
				$(this).attr('href', $(this).attr('href').replace(webroot, approot));
				if ($(this).attr('target') != '_blank') {
					$(this).attr('target', '_top');
				}
			}
		});
		$('form').each(function() {
			if ($(this).attr('action')) {
				$(this).attr('action', $(this).attr('action').replace(webroot, approot));
				$(this).attr('target', '_top').attr('method', 'get');
			}
		});
	}
});

function preloadImages()
{
	var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
	for(var i = 0; i < a.length; i++) {
		document.createElement('img').src = webroot+'img/'+a[i];
	}
}

function getCookie(c_name)
{
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

if (!getCookie("mytzo")) {
	var tzo=new Date().getTimezoneOffset();
	setCookie("mytzo", tzo, 365);
}

preloadImages('mobracer_logo_indicator.png');
