var app = {};
$.ajaxSetup({type:'POST', async:true});

$(function()
{
	$.ajax({url:'/application/request/load_configs',data:''
				,success:
				function(data)
				{
					if(!data) return app.configs = {};
					app.configs = $.php.json_decode(data);
					$(window).triggerHandler("CONFIG_LOADED");
				}});
	
	$(".clickclear").clickclear().trigger("blur");
});

function lang(term)
{
	if(!app.configs.lang || !app.configs.lang[term]) return '';	
	return app.configs.lang[term];
}

function config(config)
{
	if(!app) return '';
	if(!app.configs) return '';
	if(!app.configs[config]) return '';	 
	return app.configs[config];
}


$.bind = 
{
	 vars:{'load':[],'resize':[],'scroll':[],'config':[]}
	,load:function(f)
	{
		this.vars['load'].push(f);
		return this;
	}
	,resize:function(f)
	{
		this.vars['resize'].push(f);
		return this;
	}
	,scroll:function(f)
	{
		this.vars['scroll'].push(f);
		return this;
	}
	,config:function(f)
	{
		this.vars['config'].push(f);
		return this;
	}
	,handlers:function()
	{
		window.onload 	= function(){$.bind.execute("load");};	
		window.onresize = function(){$.bind.execute("resize");};	
		window.onscroll = function(){$.bind.execute("scroll");};
		$(window).bind("CONFIG_LOADED",function(){$.bind.execute("config");})
	}
	,execute:function(t)
	{
		for(var i in $.bind.vars[t])
		{
			$.bind.vars[t][i]();	
		}
	}
};

$.bind.handlers();


$.php =
{
	json_decode:function(str_json){var json=window.JSON;if(typeof json==='object'&&typeof json.parse==='function'){try{return json.parse(str_json);}catch(err){if(!(err instanceof SyntaxError)){throw new Error('Unexpected error type in json_decode()');}
this.php_js=this.php_js||{};this.php_js.last_error_json=4;return null;}}
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;var j;var text=str_json;cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
if((/^[\],:{}\s]*$/).test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return j;}
this.php_js=this.php_js||{};this.php_js.last_error_json=4;return null;}
	,nl2br:function(str, is_xhtml) {
		var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
		return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
	}
	
};



