var debug_mode = debug_mode || false;
var base_url = base_url || null;
var css_url = css_url || null;
var actual_skin = actual_skin || 'default';
var __loadedmodules = __loadedmodules || [];
// this code using $ as alias to jQuery
(function($) {
	jQuery.tools.version = jQuery.tools.version || '1.0.5';
	if (!base_url) {
		var mysrc = $('script[src*=jquery.digi.js]').attr('src');
		base_url = mysrc.substr(0, mysrc.lastIndexOf('js/jquery.digi.js'));
	}
	if (!css_url) {
		css_url = base_url+'tpl/'+actual_skin+'/css';
	}
	var __loadedmodules = [];
	var json_regexp = new RegExp('^[\[\{]', 'g');
	//--------------------8<-------------- $ Extending ----------------------8<---------------------
	$.extend({
		set_cookie: function(c_name, value, expiredays) {
			var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+
			((expiredays==null) ? "; path=/" : "; expires="+exdate.toGMTString()+"; path=/");
		},
		get_cookie: function(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 "";
		},
		b64: {
			'ct':['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'],
			'enc':function(d){
				var r = "";
				if (this.utf8) { var d = d.replace(/./g, function(x) {
					var c = x.charCodeAt(0);
					return (String.fromCharCode(c>>8)+String.fromCharCode(c&255)); });
				}
				for (var p=0; p < d.length; p+=3) {
					r += this.ct[d.charCodeAt(p)>>2];
					r += this.ct[((d.charCodeAt(p)&3)<<4)|(!d[p+1]?0:(d.charCodeAt(p+1)>>4))];
					r += (!d[p+1]?"=":this.ct[((d.charCodeAt(p+1)&15)<<2)|(!d[p+2]?0:d.charCodeAt(p+2)>>6)]);
					r += (!d[p+2]?"=":this.ct[d.charCodeAt(p+2)&63]);
				}
				return r;
			},
			'dec':function(d){
				if (!this.dt) { this.dt = {};
					for (var c=0; c < 64; c++) { this.dt[this.ct[c]] = c; } }
				var r = '';
				for (var p=0; p < d.length; p+=4) {
					r += String.fromCharCode(this.dt[d[p]]<<2|this.dt[d[p+1]]>>4);
					r += (!d[p+2]||d[p+2]=='=')?'':String.fromCharCode(this.dt[d[p+1]]<<4&255|(this.dt[d[p+2]]||0)>>2);
					r += (!d[p+3]||d[p+3]=='=')?'':String.fromCharCode((this.dt[d[p+2]]||0)<<6&255|(this.dt[d[p+3]]||0));
				}
				if (this.utf8) {
					var r = r.replace(/../g, function(x) {
						return String.fromCharCode(x.charCodeAt(0)<<8|x.charCodeAt(1)); });
				}
				return r;
			}
		},
		load_module: function(module, callback, isasync) {
			if(typeof(isasync) == 'undefined') isasync = false;
			//if(!__loadedmodules.length) $.calc_used_modules();
			//determinate source by module type (js or module)
			var src = '';
			if (module.indexOf('.js') > 0) src = module; else src = base_url+"js/jquery."+module+".js";
			//do not load twice
			if (!$.grep(__loadedmodules, function(module) { return (module.indexOf(src) >= 0); }).length) {
				__loadedmodules[__loadedmodules.length] = src;
				src = src.replace(RegExp(location.protocol+'//'+location.hostname), '');
				var cache = (typeof(debug_mode) != 'undefined' && debug_mode*1) ? false : true;
			if(callback != 'loaded') {
					jQuery.ajax({type: "GET", url: src, dataType: "script", async: isasync, ifModified: cache, cache: cache, global: false, success: function(data) {
						if (typeof(callback) == 'function') callback(data);
					}});
				}
			}
		},
		load_foreign_module: function(module, callback) {
			$.calc_used_modules();
			//determinate source by extension (js or module)
			if (module.indexOf('.js') > 0) var src = module; else var src = base_url+"js/jquery."+module+".js";
			//do not load twice
			if (!$.grep(__loadedmodules, function(module) { return (module.indexOf(src) >= 0); }).length) {
				__loadedmodules[__loadedmodules.length] = src;
				jQuery('<scr'+'ipt></scr'+'ipt>').attr({src: src, language: "JavaScript", id: "js-"+module}).appendTo('head'); var tim = setTimeout(function() { if (jQuery('#js-'+module)) { clearTimeout(tim); if (typeof(callback) == 'function') callback(); } },1);
			}
		},
		load_css: function(css, id) {
			var css_exp = new RegExp('^[^\{\@]*$');
			var use_default_css = false;
			var css_mode = 'append';

			//try to find module css in default template (when append mode is on)
			if (actual_skin != "default" && css_mode == 'append') {
				use_default_css = true;
			}

			if (css_exp.test(css)) {
				css = css_url+'/'+css+'.css';
				//css is an external file
				if (typeof(id) == 'undefined') {
					//alert('no css id?');
					id = css.replace(new RegExp('([\/\.:])', 'g'), '_');
					if (use_default_css) {
						id_default = css.replace(actual_skin, 'default').replace(new RegExp('([\/\.:])', 'g'), '_');
					}
				}
				if ($('#style_'+id).length == 0 && $('head link[href*='+css+']').length == 0) {
					if ($.browser.msie) {
						var css_elem = $('<link rel="stylesheet" href="'+css+'" type="text/css" media="screen" title="style_'+id+'" id="style_'+id+'">').appendTo('head');
						if (use_default_css) {
							$('<link rel="stylesheet" href="'+(css.replace(actual_skin, 'default'))+'" type="text/css" media="screen" title="style_'+id+'" id="style_'+id+'">').appendTo('head');
						}
					} else {
						var css_elem = $('<style type="text/css" id="style_'+id+'">@import "'+css+'";</style>').appendTo('head');
						if (use_default_css) {
							$('<style type="text/css" id="style_'+id+'">@import "'+(css.replace(actual_skin, 'default'))+'";</style>').appendTo('head');
						}
					}
				}
			} else {
				if (typeof(id) == 'undefined') {
					//alert('no css id?');
					id = new Date().getTime();
				}
				//inline style
				if (!$('#style_'+id).length) {
					var css_elem = $('<style type="text/css" id="style_'+id+'">'+css+'</style>').appendTo('head');
				}
			}
			return css_elem;
		},
		calc_used_modules: function() {
			$.each($('script'), function(id, scr) {
				if (!$(scr).attr('_js_used') && scr.src && (!$.grep(__loadedmodules, function(module) { return (module.indexOf(scr.src) >= 0); }).length)) {
					$(scr).attr('_js_used', true);
					__loadedmodules[__loadedmodules.length] = scr.src;
				}});
			return __loadedmodules;
		},
		get_by_frame: function(url, callback) {
			frame = jQuery('<iframe src="'+url+'">').hide().ready(function() { callback(this.clone()); }).appendTo('body');
		},
		get_path: function() {
			var path_regexp = new RegExp('req=([a-zA-Z0-9\/]+)');
			var path;
			if (path_regexp.test(location.search)) path = path_regexp.exec(location.search)[0];
			if (!path) path = location.pathname.substr(1);
			return path;
		},
		add_hook: function(hook, func) {
			//add functions to js autoloader onload event
			if (typeof(hook_funcs) != 'object') hook_funcs = {};
			if (typeof(hook_funcs[hook]) == 'undefined') hook_funcs[hook] = [];
			hook_funcs[hook][hook_funcs[hook].length] = func;
			hook_funcs[hook] = $.unique(hook_funcs[hook]);
			return hook_funcs;
		},
		exec_hook: function(hook, params) {
			if (typeof(hook_funcs) == 'object') {
				if (typeof(hook_funcs[hook]) == 'object') {
					//do onload event functions
					$.each(hook_funcs[hook], function(id, func) {
						if (typeof(func) == 'function') {
							try {
								func(params, hook);
							} catch(e) {
								$.debug(e);
							}
						} else {
							delete(hook_funcs[hook][id]);
						}
					});
				}
			}
		},
		doc_size: function(param) {
			var sizes = {};
			//clientSizes
			if (self.innerHeight) {
				sizes.ih = self.innerHeight;	sizes.iw = self.innerWidth;	sizes.oh = self.offsetHeight;	sizes.ow = self.offsetWidth;
				sizes.st = self.pageYOffset;	sizes.sl = self.pageXOffset;	sizes.sw = self.scrollWidth;
			}	else if (document.documentElement && document.documentElement.clientHeight) {
				//in frames + ie strict
				sizes.ih = document.documentElement.clientHeight;	sizes.iw = document.documentElement.clientWidth;	sizes.oh = document.documentElement.offsetHeight;	sizes.ow = document.documentElement.offsetWidth;
				sizes.st = document.documentElement.scrollTop;	sizes.sl = document.documentElement.scrollLeft;	sizes.sw = document.documentElement.scroll;
			} else {
				sizes.ih = document.body.clientHeight;	sizes.iw = document.body.clientWidth;	sizes.oh = document.body.offsetHeight;	sizes.ow = document.body.offsetWidth;	sizes.iw = document.body.clientWidth;
				sizes.st = document.body.scrollTop;	sizes.sl = document.body.scrollLeft; sizes.sw = document.body.scrollWidth;
			}
			if (typeof(param) == 'undefined') {
				return sizes;
			} else {
				return sizes[param];
			}
		},
		is_array: function(arr) {
			return Array.prototype.isPrototypeOf(arr);
		},
		is_null: function(val) {
			return ((typeof(val) == 'object') && ((val+'') == 'null'));
		},
		object_length: function(obj)  {
			var length = 0;
			if (typeof(obj) == 'object') {
				for (var i in obj) {
					length++;
				}
			}
			return length;
		},
		object_element_is_empty: function(obj) {
			if (typeof(obj) == 'object') {
				for (var i in obj) {
					if (typeof(obj[i]) == "object" && $.object_length(obj[i]) > 0)
						return false;
				}
			}
			return true;
		},
		debug: function(what) {
			if (debug_mode) {
				$.add_message(what, 'debug');
			}
		},
		add_message: function(what, theme) {
			if (!theme) theme = 'info';
			$.load_css('jquery.jgrowl');
			$.load_module('jgrowl');
			//convert to string
			what = what+'';
			$.jGrowl('<div class="cell">'+what.replace(/\+/g, ' ')+'</div>', {header: '', theme: theme, life: 4000,	sticky: true});
		},
		/** Growl Message Boxes from Cookie **/
		check_messages: function() {
			$.startupURL = $.startupURL || location.href;
			var msgs;
			//alert(unescape($.get_cookie('messages')));
			if ((location.href == $.startupURL) && (msgs = $.get_cookie('messages')) && (msgs = eval(unescape(msgs)))) {
				if (msgs.length) {
					$.load_css('jquery.jgrowl');
					$.load_module('jgrowl');
					var txt = '';
					$.each(msgs, function(i, val) {
						txt = val.txt ? val.txt.replace(/\+/g, ' ') : (val.txt == null ? '[null]' : '[empty string]');
						$.jGrowl('<div class="cell">'+txt+'</div>', {header: '', theme: val.type, life: 4000,	sticky: val.sticky});
					});
					$.set_cookie('messages', '[]');
				}
			}
		}
	});
	//--------------------8<-------------- $.FN Extending (utils) ----------------------8<---------------------
	$.fn.extend({
		url_param: function(strParamName) {
			strParamName = escape(unescape(strParamName));
			var returnVal = new Array();
			var qString = null;
			if ($(this).attr("nodeName")=="#document") {
				//document-handler
				if (window.location.search.search(strParamName) > -1 ){
					qString = window.location.search.substr(1,window.location.search.length).split("&");
				}
			} else if ($(this).attr("src")!="undefined") {
				var strHref = $(this).attr("src");
				if ( strHref.indexOf("?") > -1 ){
					var strQueryString = strHref.substr(strHref.indexOf("?")+1);
					qString = strQueryString.split("&");
				}
			} else if ($(this).attr("href")!="undefined") {
				var strHref = $(this).attr("href");
				if ( strHref.indexOf("?") > -1 ){
					var strQueryString = strHref.substr(strHref.indexOf("?")+1);
					qString = strQueryString.split("&");
				}
			} else {
				return null;
			}
			if (qString==null) return null;
			for (var i=0;i<qString.length; i++){
				if (escape(unescape(qString[i].split("=")[0])) == strParamName){
					returnVal.push(qString[i].split("=")[1]);
				}
			}
			if (returnVal.length==0) return null;
			else if (returnVal.length==1) return returnVal[0];
			else return returnVal;
		},
		/**
		 * Retrieves the absolute position of an element on the screen
		 */
		absolute_position: function () {
			var el = $(this)[0];
			var sLeft = 0, sTop = 0;
			var isDiv = /^div$/i.test(el.tagName);
			if (isDiv && el.scrollLeft) {
				sLeft = el.scrollLeft;
			}
			if (isDiv && el.scrollTop) {
				sTop = el.scrollTop;
			}
			var r = { x: el.offsetLeft - sLeft, y: el.offsetTop - sTop };
			if (el.offsetParent) {
				var tmp = $(el.offsetParent).absolute_position();
				r.x += tmp.x;
				r.y += tmp.y;
			}
			return r;
		},
		/**
		 *  Page Loader function
		 **/
		page_load: function() {
			$(this).each(function() {
				try {
					/** Form Module Loader **/
					if ($('form', this).length) {
						$.load_module('form');
					}
					/** Static Grid Loader **/
					if ($('.grid-static', this).length) {
						$.load_module('flexigrid');
						$.load_css('jquery.flexigrid');
						if (!$('.grid-static', this)[0].grid) {

							$('.grid-static', this).addClass('grid').flexigrid({width: $(this).width()+'px'});
						}
					}
					/** Reach Text Editor aka WYSIWYG **/
					if ($('.rte, .wysiwyg', this).length) {
						$.load_module('rte/jquery.rte');
						$.load_module('rte/jquery.rte.tb');
						$.load_module('rte/jquery.ocupload-1.1.4');
						$.load_css('jquery.rte');
						$('.rte, .wysiwyg', this).rte({
									css: [base_url+'tpl/default/css/jquery.rte.inside.css'],
									controls_rte: rte_toolbar,
									controls_html: html_toolbar,
									width: '100%',
									height: '100%'
						});
					}
					/** Accordion **/
					if ($('ul.accordion', this).length) {
						$.load_module('accordion');
						$('ul.accordion', this).accordion();
					}
					/** Tagger **/
					if ($('.tagger', this).length) {
						$.load_module('tagger');
						$.load_css('jquery.tagger');
						$('.tagger', this).tagger();
					}
					/** Tabs **/
					if ($('div.tab-panes', this).length) {
						var i, missing = $('.tabs ul li', this).length - $('div.tab-panes > div', this).length;
						for (i = 0; i <= missing; i++) {
							$('<div></div>').appendTo('div.tab-panes');
						}
						$('.tabs ul', this).tabs('div.tab-panes > div', {effect: 'fade', onBeforeClick: function(event, i) {
							// get the pane to be opened
							var pane = this.getPanes().eq(i);
							// if it is empty ..
							if (pane.is(":empty")) {
								// load it with a page specified in the tab's href attribute
								pane.load(this.getTabs().eq(i).attr("href"), {}, function() { $(pane).page_load(); });
							}
						}}).history();
					}
					/** Tooltip **/
					//if (typeof($.fn.tooltip) == 'function') $('#tooltip-trigger', this).tooltip({tip: '.tooltip'});

					/** Modal windows on  links **/
					$('.modal[href]', this).click(function() {
						$.load_module('jmodal');
						var elem = this;
						$.jmodal({title: elem.title ? elem.title : $(elem).html(), content: function(e) {
							e.html('<img src="'+base_url+'/tpl/'+actual_skin+'/img/gif-loading.gif" title="loading..." alt="loading..." />');
							$.ajax({url: $(elem).attr('href'), type: 'get', dataType: 'html', async: false, success: function(data) {
								e.html(data);
								$(e).page_load();
							}});
						}});
						return false;
					});
					/** Confirm windows **/
					$('a.confirm', this).click(function() {
						return confirm($(this).attr('title'));
					});
					/** AJAX Links **/
					$('a.ajax', this).click(function() {
						$elem = $(this);
						$.ajax({url: $elem.attr('href'), type: 'get'});
						return false;
					});
					/** Date Picker **/
					if ($('.date-pick', this).length) {
						$.load_module('datepicker');
						$.load_css('jquery.datepicker');
						Date.firstDayOfWeek = 1;
						Date.format = 'yyyy.mm.dd.';
						$.each($('.date-pick'), function() {
							var input = this;
							if (!this.value*1) $(this).val(Date().asString());
							d = new Date(this.value*1000);
							$.dpText.TEXT_CHOOSE_DATE = '&nbsp;&nbsp;&nbsp;&nbsp;';
							var nam = this.name;
							$(this).attr('name', this.name+'_time');
							var $hinput = $('<input type="hidden" name="'+nam+'" value="'+this.value+'" />').insertBefore(this);
							if ($(this).hasClass('time-pick')) {
								var clickfunc, i;
								var $min_sel = $('<select name="'+this.name+'_minutes"></select>');
								for (i=0; i<=59; i++) {
									$min_sel.append('<option'+(d.getMinutes() == i ? ' selected' : '')+'>'+i+'</option>');
								}
								$min_sel.insertAfter(this);
								var $hour_sel = $('<select name="'+this.name+'_hour"></select>');
								for (i=0; i<=23; i++) {
									$hour_sel.append('<option'+(d.getHours() == i ? ' selected' : '')+'>'+i+'</option>');
								}
								$hour_sel.insertAfter(this).change(clickfunc = function() {
									var curtime = Date.fromString($(input).val()).addHours($hour_sel.val()).addMinutes($min_sel.val()).getTime()/1000;
									if (curtime && curtime > -2208988800) $hinput.val(curtime);
								}).after(':&nbsp;');
								$min_sel.change(clickfunc);
								$(this).keyup(clickfunc);
							}
							$(this).val(d.asString());
							$(this).datePicker({clickInput:false, createButton: true, startDate: new Date(0).asString()}).bind(
								'dpClosed',
								function(e, selectedDates)
								{
									var d = selectedDates[0];
									if (d) {
										d = new Date(d);
										$($hinput).val(d.getTime()/1000);
									}
								}
							);
						});
					}
					/* Collapsible */
					$('fieldset.collapsible:not(.collapsible_active) > legend', this).each(function() {
						var fieldset = $(this.parentNode);
						fieldset.addClass('collapsible_active');
						// Expand if there are errors inside
						if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
							fieldset.removeClass('collapsed');
						}

						// Turn the legend into a clickable link and wrap the contents of the fieldset
						// in a div for easier animation
						var text = this.innerHTML;
						$(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
							var fieldset = $(this).parents('fieldset:first')[0];
							// Don't animate multiple times
							if (!fieldset.animating) {
								fieldset.animating = true;
								if ($(fieldset).is('.collapsed')) {
									var content = $('> div', fieldset).hide();
									$(fieldset).removeClass('collapsed');
									content.slideDown(300, function() {
										// Make sure we open to height auto
										$(this).css('height', 'auto');
										var h = self.innerHeight || document.documentElement.clientHeight || $('body')[0].clientHeight || 0;
										var offset = self.pageYOffset || document.documentElement.scrollTop || $('body')[0].scrollTop || 0;
										var pos = $(this.parentNode).absolute_position();
										var fudge = 55;
										if (pos.y + this.parentNode.offsetHeight + fudge > h + offset) {
											if (this.parentNode.offsetHeight > h) {
												window.scrollTo(0, pos.y);
											} else {
												window.scrollTo(0, pos.y + this.parentNode.offsetHeight - h + fudge);
											}
										}
										this.parentNode.animating = false;
										$(this.parentNode).addClass('expanded');
									});
								}	else {
									var content = $('> div', fieldset).slideUp('medium', function() {
										$(this.parentNode).addClass('collapsed').removeClass('expanded');
										this.parentNode.animating = false;
									});
								}
							}
							return false;
						})).after($('<div class="fieldset-wrapper"></div>').append(fieldset.children(':not(legend)')));
					});
					$.exec_hook('page_load', {elem: this});
				} catch(e) {
					if (typeof(console) == 'undefined') {
						//alert(e);
					} else {
						console.log(e);
						console.log(data);
					}
				}
			});
			return this;
		}
	});
	$.browser.msie6 = (navigator.appVersion.toLowerCase().indexOf("msie 6") > 0) ? true : false;
	$.browser.msie7 = (navigator.appVersion.toLowerCase().indexOf("msie 7") > 0) ? true : false;

	$(function() {
		//console.profile('main');
		$.calc_used_modules();
		if ($.browser.msie && typeof(CFInstall) !== 'undefined') {
			$.load_foreign_module('http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js');
			$('body').empty(); //.append('<div id="chrome" style="position: absolute; top: 0; left: 0; background: #FFF;"></div>').width($('body').width()).height($('body').height());
			CFInstall.check(); //{node: 'chrome'}
		}
		/*
		if (!$('#overlay').length) {
			$('<div class="overlay" id="overlay"><div class="wrap"></div></div>').appendTo('body');
		}
		*/
		if ($('#overlay').length) $.overlay = $('#overlay').overlay({api: true, closeOnClick: false});

		$(document).page_load();
		$.check_messages();

		/** Hooks : Grid double click **/
		$.add_hook('grid_row_dblclick', function(param) {
			var row = param.row, grid = param.grid;
			var id = row.id.substr(3);
			if (grid.dblClick) {
				if (typeof(grid.dblClick) != 'object') grid.dblClick = {url: grid.dblClick};
				var url = grid.dblClick.url.replace('%id%', id);
				if (grid.dblClick.type == 'modal') {

						$.load_module('jmodal');
						$.jmodal({title: grid.dblClick.title, content: function(e) {
							e.html('loading...');
							$.ajax({url: url, type: 'get', dataType: 'html', async: false, success: function(data) {
								e.html(data);
								$(e).page_load();
							}});
						}});

					/*
					var wrap = $.overlay.getContent().find("div.wrap");
					$.ajax({url: url, type: 'get', dataType: 'html', async: false, success: function(data) {
						wrap.html(data);
						wrap.page_load();
						$('img[overlay]:eq(0)').width(wrap.width());
						$.overlay.load();
					}});
					*/
				} else {
					location.href = url;
				}
			}
		});
		/** AJAX Watcher **/
		$.fw_process = function(data) {
			setTimeout(function() { $.check_messages(); }, 800);
			if (!$.trim(data).length) return '?';

			var last_char = $.trim(data).substr($.trim(data).length - 1, 1);
			if (last_char == ';' || last_char == ')' || data.indexOf('eval(') == 0) {
				eval(data);
			} else {
				var temp = false;
				try { temp = eval('('+data+')'); } catch(e) { }
				if (temp) var data = temp;
			}
			//try {
				var stop = 0;
				if (typeof(data) == 'object') {
					$.each(data, function(key, val) {
						if (typeof(key) == 'string' && !stop) {
							//commands to preprocessor starting with _
							if (key.substr(0,1) == '_') {
								//bug? -> string comparsions starting with _ not working in compressed mode!!
								key = key.substr(1);
								//redirect command
								if (key == 'redirect' && typeof(val) == 'string') {
									stop = 1;
									var url;
									if (val.indexOf('http://') >= 0 || val.substr(0,1) == '/') url = val; else url = base_url+val;
									location.href = url;
								} else if (key == 'popup') {
									var url;
									if (val.indexOf('http://') >= 0 || val.substr(0,1) == '/') url = val; else url = base_url+val;
									window.open(url);
								//debug command
								} else if (key == 'debug') {
									$.debug(val);
								//alert command
								} else if (key == 'alert') {
									alert(val);
								} else if (key == 'reload') {
									stop = 1;
									location.reload();
								//debug_info command
								} else if (key == 'debug_info') {
									$('<div>'+val+'</div>').page_load().prependTo('#debug');
								//command to script loader
								} else if (key == 'scripts' && typeof(val) == 'object') {
									//got a module
									$.each(val, function(id, script) {
										$.load_module(script,	function(script_data) {
											$.exec_hook('js_onload', { 'script_path' : script, 'script_data' : script_data });
										});
									});
								//command to script eval
								} else if (key == 'eval' && typeof(val) == 'object') {
									//eval a script
									$.each(val, function(id, script) {
										eval(script);
									});
								//html replacer
								} else if (key == 'replace' && typeof(val) == 'object') {
									$.each(val, function(key, html) {
										$(key).replaceWith(html).page_load();
									});
								//html content changer
								} else if (key == 'content' && typeof(val) == 'object') {
									$.each(val, function(key, html) {
										$(key).html(html).page_load();
									});
								//html replacer (1)
								} else if (key == 'replace1' && typeof(val) == 'object') {
									$.each(val, function(key, html) {
										$(key).eq(0).replaceWith(html).page_load();
									});
								//html content changer (1)
								} else if (key == 'content1' && typeof(val) == 'object') {
									$.each(val, function(key, html) {
										$(key).eq(0).html(html).page_load();
									});
								}
							}
						}
					});
					if (!stop) {

					}
					if ((debug_mode * 1) && (typeof(console) == 'object')) { console.groupCollapsed('Processed data'); console.dir(data); console.groupEnd(); }
				} else {
					//$.debug(data);
					//if (typeof(data) != 'undefined' && data+'' && (debug_mode * 1) && (typeof(console) == 'object')) { console.groupCollapsed('Non-processed data'); /*console.dirxml($(data)[0]);*/ console.log(data); console.groupEnd(); }
				}
			/*} catch(e) {
				if (typeof(console) == 'undefined') {
					//alert(e);
				} else {
					console.log(e);
					console.log(data);
				}*/
			//}
			return data ? data : false;
		};
		$.ajaxSetup({dataType: 'json', ifModified: false, cache: true});
		$("#footer").ajaxComplete(function(ajax_event, request, settings) {
			//got 403 message
			if (typeof(request) == 'object' && request.status == 403) {
				$.debug('403', function() {
					location.reload(true);
					return false;
				});
			}
			var data = $.fw_process(request.responseText);

			setTimeout(function() {
				$.exec_hook('ajax_request', { 'data' : data, 'ajax_event' : ajax_event, 'request' : request });
			}, 500);

			return true;
		});
		//** Resizer **//
		var resizer;
		$(window).resize(resizer = function() {
			var minheight = 180;
			if ($('#content').outerHeight() > minheight) minheight = $('#content').outerHeight();
			if ($('#sidenav').outerHeight() > minheight) minheight = $('#sidenav').outerHeight();
			if ($(document).height() <= $(window).height() || ($('#content').outerHeight() > minheight)) {
				var newheight = $(window).height() - $('#header').outerHeight() - $('#debug').outerHeight() * 1 - $('#footer').outerHeight() - 70;
				$('#content').css('min-height', ((newheight > minheight) ? newheight : minheight)+'px');
			}
		});
		resizer();
		setTimeout(resizer, 500);
		//console.profileEnd();
	});
})(jQuery);

// In case you don't have firebug...

if (!window.console || !console.firebug) {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupCollapsed", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	window.console = {};
	for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
}
