var SocialEngineAPI = {
  version : '0.1.0alpha'
};
SocialEngineAPI.Base = new Class({
  initialize: function()
  {
    this.version = SocialEngineAPI.version;
  },
  RegisterModule: function(moduleObject)
  {
    moduleObject.Base = this;
  }

});
var ctoggle = function(idObj){
	if(typeof idObj != 'object'){
		idObj = document.getElementById(idObj);
	}
	if(idObj.style.display == 'none'){
		idObj.style.display = 'block';
	}
	else{
		idObj.style.display = 'none';
	}
}
var timeOut = function(duration, ido, bool){
	var ido = ido || '';
	var bools = bool || false;

	if(typeof ido != 'object'){
		ido = document.getElementById(ido);
	}
	setTimeout(function(){
		if(bools){
			ido.innerHTML = '';
		}
		else{
			ido.style.display = 'none';
		}
	}, duration);
}
var updateCommentCount = function(div1, div2, count){
	if(count){
		$(div2).set('html', count+' comments');
	}
	if($(div1).getStyle('display') == 'none'){
		$(div2).setStyle('display', 'block');
	}
	else{
		$(div2).setStyle('display', 'none');
	}
}
var mousePosX = function(event){
	var event = new Event(event);
	var xScroll = document.body.scrollLeft || document.documentElement.scrollLeft || window.pageXOffset || 0;
	var xWidth = event.client.x + xScroll;
	return xWidth;
}
var mousePosY = function(event){
	var event = new Event(event);
	var yScroll = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;
	var yHeight = event.client.y + yScroll;
	return yHeight;
}

function show_light(id, mode)
{
	if(mode=='none')
	{
		$(id).set('tween', {
			duration: 250,
			onComplete: function(){
				$(id).style.display=mode;
			}
		});
		$(id).tween('opacity', 1, 0);
	}
	else
	{	
		var sc_width = window.getWidth();
		var left = (sc_width - 470)/2;
		$(id).setStyle('left',left+'px');
		if(id=='invite_fr')
		{
			$(id).setStyle('top','50px');
		}
		else if(id=='add_frdns_div' || id=='add_frdns_div2' || id=='chpasswd')
		{
			$(id).setStyle('top','225px');
		}
		else if(id=='reportPopId')
		{
			$(id).setStyle('top','200px');
		}
		else 
		{
			$(id).setStyle('top','110px');
		}
		$(id).style.display=mode;
		$(id).setStyle('opacity', 1);
	}
}
function show_back_light(id, mode)
{
	if (browserName=="Microsoft Internet Explorer" && browserVer <=6)
	{
		if(mode=='block')
		{
			show();
		}
		else
		{
			hide();
		}
	}
	if(mode=='none')
	{
		$(id).set('tween', {
			duration: 400,
			onComplete: function(){
				$(id).style.display=mode;
			}
		});
		$(id).tween('opacity', 0.6, 0);
	}
	else
	{
		var sc_width = window.getWidth();
		var sc_height = window.getHeight();
		$(id).setStyle('width',sc_width+'px');
		$(id).setStyle('height',sc_height+'px');
		$(id).style.display=mode;
		$(id).setStyle('opacity', 0.6);
	}
}
var light_sc_width = window.getWidth();
var light_sc_width_after = window.getWidth();
var light_sc_height = window.getHeight();
var show = function()
{
	this.light_sc_width = window.getWidth();
	_getScroll();
	prepareIE('100%', 'hidden');
	setScroll(0,0);
	this.light_sc_width_after = window.getWidth();
}
var hide = function()
{
	this.setScroll(0,0);
    this.prepareIE("auto", "auto");
}
var prepareIE = function(height, overflow){
	bod = document.getElementsByTagName('body')[0];
	bod.style.height = height;
	bod.style.overflow = overflow;

	htm = document.getElementsByTagName('html')[0];
	htm.style.height = height;
	htm.style.overflow = overflow; 
	
	if(overflow == "auto")
	{
		bod.style.width = this.light_sc_width;
		htm.style.width = this.light_sc_width;
	}
	else
	{
		bod.style.width = this.light_sc_width_after;
		htm.style.width = this.light_sc_width_after;
	}
}
var _getScroll = function(){
	if (self.pageYOffset) {
		this.yPos = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		this.yPos = document.documentElement.scrollTop; 
	} else if (document.body) {
		this.yPos = document.body.scrollTop;
	}
}
var setScroll = function(x, y){
	window.scrollTo(x, y); 
}
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
var browserName=navigator.appName;
var browserVer1=navigator.appVersion; 
var browserVer=browserVer1.charAt(22);
function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS 								= "an unknown operating system";
	}
}
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
/* Class Core */
SocialEngineAPI.Core = new Class({
  Base: {},
  settings: {},
  plugins: {},
  options : {
    ajaxURL : 'js_api.php'
  },
  initialize: function()
  {
  },
  ImportSettings: function(settings)
  {
    this.settings = settings;
  },
  ImportPlugins: function(plugins)
  {
    this.plugins = plugins;
  }
});
/* Class Language */
if( typeof(SocialEngineAPI)=="undefined" )
  var SocialEngineAPI = {};
SocialEngineAPI.Language = new Class({
  Base: {},
  initialize: function()
  {
    this.languageVariables = new Hash();
  },
  Translate: function(id)
  {
    var rawValue = this.languageVariables.get(id) || 'Missing Language Variable #' + id;
    return rawValue;
  },
  TranslateFormatted: function(id, params)
  {
    var rawValue = this.languageVariables.get(id) || 'Missing Language Variable #' + id;
    params.unshift(rawValue);
    var formattedValue = sprintf.run(params);
    return formattedValue;
  },
  Import: function(languageVariableObject)
  {
    if( $type(languageVariableObject)=="object" )
      this.languageVariables.extend(languageVariableObject);
  }
});
var SocialEngineLanguage = SocialEngineAPI.Language;
/* Class Url */
SocialEngineAPI.URL = new Class({
  Base: {},
  url_base : null,
  url_info : {},
  initialize: function()
  {
  },
  url_create: function(name, user, id1, id2, id3)
  {
    var url_template = ( SocialEngine.Core.settings.setting_url ? this.url_info[name].url_subdirectory : this.url_info[name].url_regular );
    if( !url_template ) return false;
    url_template = url_template.replace('$user', user);
    url_template = url_template.replace('$id1', id1);
    url_template = url_template.replace('$id2', id2);
    url_template = url_template.replace('$id3', id3);
    return this.url_base + url_template;
  },
  url_userdir: function(user_id)
  {
    return 'uploads_user/' + (user_id + 999 - ((user_id - 1) % 1000)).toString() + '/' + user_id + '/';
  },
  ImportURLBase: function(url_base)
  {
    this.url_base = url_base;
  },
  ImportURLInfo: function(url_info)
  {
    this.url_info = url_info;
  }
});

function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }
function sprintf()
{
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}
function validEmail(inputvalue){
var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
 if(pattern.test(inputvalue)){ 	return true;  } else{	return false;  }}
String.prototype.trim = function() {    return this.replace(/^\s+|\s+$/g, "");}