$(document).ready(function(){
	pbRichEditSettings = {
		className: 'editor',
		buttons: {
			bold: {label: 'Wytłuszczenie', action: function (text) { return '[b]' + text + '[/b]'; }},
			underline: {label: 'Podkreślenie', action: function (text) { return '[u]' + text + '[/u]'; }},
			italic: {label: 'Kursywa', action: function (text) { return '[i]' + text + '[/i]'; }},
			center: {label: 'Akapit', action: function (text) { return '[center]' + text + '[/center]'; }},
			link: {label: 'Link', action: function() {
				var regexp = /^\s*http:\/\/(?:www\.)?klaps\.pl\/(?:(film|serial|osoba)\/(\d+)\/|([\w.]+\s*$))/;
				var url = prompt('Wklej link do klapsa:');
				var match = regexp
					.exec(url)
					;
				
				if (match != null) {	
					switch (match [1]) {
						case 'film': case 'serial':
							return '[movie=' + match [2] + ']';
							
						case 'osoba':
							return '[person=' + match [2] + ']';
							
						default:
							if (match [3]) {
								var __result = {};
								$.ajax({
									url: '/feed-me/short-url.php',
									dataType: 'json',
									type: 'POST',
									async: false,
									
									data: {
										shortUrl: match [3]
										},
										
									success: function(response){
										__result = response;
										}
								});
							
								switch(__result.type) {
									case 'movie':
										return '[movie=' + __result.id + ']';
										
									case 'person':
										return '[person=' + __result.id + ']';
										
								}
							}				
					}
				}
				
				return '';
			}},
			video: {label: 'Klip wideo', action: function (text) { return '[video=' + prompt('Wklej link do klipu') + ']'; }},
		},
		preview: {
			url: '/feed-me/bbpreview.php',
			resultContainer: document.getElementById('edit-preview')
		}
	};
});

