
function json(url) {
			var newUrl = '';
	;
	if(location.search && !newUrl) {
		url = url + location.search; 
		var tmp = location.search.substr(1);
		var paramset = false;
		var eins = tmp.split('&');

		for(var i = 0; i < eins.length; i++) {
			var params = eins[i].split('=');
			var result = /params\[(.*)\]/.exec(params[0]);
			if(result) {
				
				if(!paramset) {
					paramset = true;
					newUrl += '/params';
				}
				
				newUrl += '/' + RegExp.$1 + '/' + params[1];
			} else {
				newUrl += '/' + params[0] + '/' + params[1];
			}
		}
		//location.search = '';

		url = newUrl;
	}
	
	$.ajax({
		dataType: 'json',
	    error: 
	    	function(XHR, status, errorThrown) {
	    		$('body').html(status + ' - ' + errorThrown);  
	    	},
	    success:
            function(data, status, xhr) {
    			update(data);    
				if((url.indexOf('doc_id/22') > -1) || (url.indexOf('doc_id/23') > -1) || (url.indexOf('doc_id/24') > -1) || (url.indexOf('doc_id/25') > -1)) {
					$.get('/fw/app/abc/stuff/css/screen1.css', function(css) {
		    			$('style#style').text(css);
		  			});
				} else {
					$.get('/fw/app/abc/stuff/css/screen.css', function(css) {
		    			$('style#style').text(css);
		  			});
				}        
            },
        url: url + (url.indexOf('params') < 0 ? '/params/json/1' : '/json/1')
	});
}

function update(data) {
	var h1 = $('h1');
	var content = $('#content');
	if(typeof(data.title) != 'undefined' && data.title !== null) {
		h1.html(decodeURIComponent(data.title));
	} else {
		h1.html('');
	}
	if(typeof(data.content) != 'undefined' && data.content !== null) {
		content.html(decodeURIComponent(data.content));
	} else {
		content.html('');
	}
	$.getScript('/fw/app/abc/stuff/js/script.js');
}

$(function() {
	$('.menu').find('a:not(.json)').each(function(idx, el) {
		if($(el).attr('href').indexOf('javascript') < 0 &&
			$(el).attr('href').indexOf('http') < 0 &&  
			$(el).attr('href') !== '#') {
			$(el).attr('href', 'javascript:json("' + $(el).attr('href') + '");').addClass('json');
		}
	});
	$('#ajax-load').ajaxStart(function() {
		$(this).css('visibility', 'visible');
	});
	$('#ajax-load').ajaxSuccess(function() {
		$(this).css('visibility', 'hidden');
	});
});
