7 THEMES = ['Alkohol', 'Ambicja', 'Anioł', 'Antysemityzm', 'Arkadia', 'Artysta', 'Bezdomność',
 
   8 'Bezpieczeństwo', 'Bieda', 'Bijatyka', 'Błazen', 'Błądzenie', 'Błoto', 'Bogactwo', 'Bóg', 'Brat',
 
   9 'Bunt', 'Buntownik', 'Burza', 'Car', 'Carpe diem', 'Ciemność', 'Cień', 'Cisza', 'Chciwość', 'Chleb',
 
  10 'Chłop', 'Choroba', 'Chrystus', 'Chrzest', 'Ciało', 'Cierpienie', 'Cmentarz', 'Cnota', 'Córka', 'Cud',
 
  11 'Czarownika', 'Czary', 'Czas', 'Czyn', 'Czyściec', 'Dama', 'Danse macabre', 'Deszcz', 'Diabeł',
 
  12 'Dobro', 'Dom', 'Dorosłość', 'Drzewo', 'Duch', 'Dusza', 'Duma', 'Dworek', 'Dworzanin', 'Dwór',
 
  13 'Dzieciństwo', 'Dziecko', 'Dziedzictwo', 'Dziewictwo', 'Dźwięk', 'Egzorcyzm', 'Elita', 'Emigrant',
 
  14 'Fałsz', 'Filozof', 'Fircyk', 'Flirt', 'Głupiec', 'Głupota', 'Głód', 'Gospodarz', 'Gospodyni', 'Gość',
 
  15 'Gotycyzm', 'Góra', 'Gra', 'Grób', 'Grzech', 'Grzeczność', 'Gwiazda', 'Handel', 'Hańba', 'Historia',
 
  16 'Honor', 'Idealista', 'Imię', 'Interes', 'Jabłka', 'Jedzenie', 'Jesień', 'Kaleka', 'Kara', 'Karczma',
 
  17 'Klęska', 'Kłamstwo', 'Kłótnia', 'Kobieta', 'Kobieta demoniczna', 'Kobieta "upadła"', 'Kochanek',
 
  18 'Kochanek romantyczny', 'Kolonializm', 'Kondycja ludzka', 'Konflikt', 'Konflikt wewnętrzny', 'Koniec świata',
 
  19 'Koń', 'Korzyść', 'Kot', 'Kradzież', 'Krew', 'Król', 'Krzywda', 'Ksiądz', 'Książka',
 
  20 'Księżyc', 'Kuchnia', 'Kuszenie', 'Kwiaty', 'Labirynt', 'Las', 'Lato', 'Lekarz', 'Lenistwo', 'List',
 
  21 'Liberat', 'Los', 'Lud', 'Lustro', 'Łzy', 'Małżeństwo', 'Marzenie', 'Maska', 'Maszyna', 'Matka',
 
  22 'Matka Boska', 'Mądrość', 'Mąż', 'Melancholia', 'Mędrzec', 'Mężczyzna', 'Miasto', 'Mieszczanin',
 
  23 'Miłosierdzie', 'Miłość', 'Miłość niespełniona', 'Miłość platoniczna', 'Miłość romantyczna', 
 
  24 'Miłość silniejsza niż śmierć', 'Miłość spełniona', 'Miłość tragiczna', 'Mizoginia', 'Młodość', 'Moda',
 
  25 'Modlitwa', 'Morderstwo', 'Morze', 'Motyl', 'Mucha', 'Muzyka', 'Narodziny', 'Naród', 'Natura',
 
  26 'Nauczyciel', 'Nauczycielka', 'Nauka', 'Niebezpieczeństwo', 'Niedziela', 'Niemiec', 'Nienawiść',
 
  27 'Nieśmiertelność', 'Niewola', 'Noc', 'Nuda', 'Obcy', 'Obłok', 'Obowiązek', 'Obraz świata', 'Obrzędy',
 
  28 'Obyczaje', 'Obywatel', 'Odrodzenie przez grób', 'Odwaga', 'Ofiara', 'Ogień', 'Ogród', 'Ojciec',
 
  29 'Ojczyzna', 'Oko', 'Okręt', 'Okrucieństwo', 'Omen', 'Opieka', 'Organizm', 'Otchłań', 'Pająk', 'Pamięć',
 
  30 'Pan', 'Panna młoda', 'Państwo', 'Patriota', 'Piekło', 'Pielgrzym', 'Pieniądz', 'Pies', 'Piętno',
 
  31 'Pijaństwo', 'Piwnica', 'Plotka', 'Pobożność', 'Pocałunek', 'Pochlebstwo', 'Poeta', 'Poetka', 'Poezja',
 
  32 'Podróż', 'Podstęp', 'Pogrzeb', 'Pojedynek', 'Pokora', 'Pokusa', 'Polak', 'Polityka', 'Polowanie',
 
  33 'Polska', 'Portret', 'Porwanie', 'Poświęcenie', 'Potwór', 'Powstanie', 'Powstaniec', 'Pozory',
 
  34 'Pozycja społeczna', 'Pożar', 'Pożądanie', 'Praca', 'Praca u podstaw', 'Praca organiczna', 'Prawda', 'Prawnik',
 
  35 'Prometeusz', 'Proroctwo', 'Prorok', 'Próżność', 'Przebranie', 'Przeczucie', 'Przedmurze chrześcijaństwa',
 
  36 'Przekleństwo', 'Przekupstwo', 'Przemiana', 'Przemijanie', 'Przemoc', 'Przestrzeń',
 
  37 'Przyjaźń', 'Przyroda nieożywiona', 'Przysięga', 'Przywódca', 'Ptak', 'Pustynia', 'Pycha', 'Raj',
 
  38 'Realista', 'Religia', 'Rewolucja', 'Robak', 'Robotnik', 'Rodzina', 'Rosja', 'Rosjanin', 'Rośliny',
 
  39 'Rozczarowanie', 'Rozpacz', 'Rozstanie', 'Rozum', 'Ruiny', 'Rycerz', 'Rzeka', 'Salon', 'Samobójstwo',
 
  40 'Samolubstwo', 'Samotnik', 'Samotność', 'Sarmata', 'Sąsiad', 'Sąd', 'Sąd Ostateczny', 'Sen', 'Serce',
 
  41 'Sędzia', 'Sielanka', 'Sierota', 'Siła', 'Siostra', 'Sława', 'Słońce', 'Słowo', 'Sługa', 'Służalczość',
 
  42 'Skąpiec', 'Sobowtór', 'Społecznik', 'Spowiedź', 'Sprawiedliwość', 'Starość', 'Strach', 'Strój',
 
  43 'Stworzenie', 'Sumienie', 'Swaty', 'Syberia', 'Syn', 'Syn marnotrawny', 'Syzyf', 'Szaleniec',
 
  44 'Szaleństwo', 'Szantaż', 'Szatan', 'Szczęście', 'Szkoła', 'Szlachcic', 'Szpieg', 'Sztuka', 'Ślub',
 
  45 'Śmiech', 'Śmierć', 'Śmierć bohaterska', 'Śpiew', 'Światło', 'Świętoszek', 'Święty', 'Świt',
 
  46 'Tajemnica', 'Taniec', 'Tchórzostwo', 'Teatr', 'Testament', 'Tęsknota', 'Theatrum mundi', 'Tłum',
 
  47 'Trucizna', 'Trup', 'Twórczość', 'Uczeń', 'Uczta', 'Uroda', 'Umiarkowanie', 'Upadek', 'Upiór',
 
  48 'Urzędnik', 'Vanitas', 'Walka', 'Walka klas', 'Wampir', 'Warszawa', 'Wąż', 'Wdowa', 'Wdowiec',
 
  49 'Wesele', 'Wiatr', 'Wierność', 'Wierzenia', 'Wieś', 'Wiedza', 'Wieża Babel', 'Więzienie', 'Więzień',
 
  50 'Wina', 'Wino', 'Wiosna', 'Wizja', 'Władza', 'Własność', 'Woda', 'Wojna', 'Wojna pokoleń', 'Wolność',
 
  51 'Wróg', 'Wspomnienia', 'Współpraca', 'Wygnanie', 'Wyrzuty sumienia', 'Wyspa', 'Wzrok', 'Zabawa',
 
  52 'Zabobony', 'Zamek', 'Zaręczyny', 'Zaświaty', 'Zazdrość', 'Zbawienie', 'Zbrodnia', 'Zbrodniarz',
 
  53 'Zdrada', 'Zdrowie', 'Zemsta', 'Zesłaniec', 'Ziarno', 'Ziemia', 'Zima', 'Zło', 'Złodziej', 'Złoty wiek',
 
  54 'Zmartwychwstanie', 'Zwątpienie', 'Zwierzęta', 'Zwycięstwo', 'Żałoba', 'Żebrak', 'Żołnierz',
 
  55 'Żona', 'Życie jako wędrówka', 'Życie snem', 'Żyd', 'Żywioły', 'Oświadczyny']
 
  59 function highlight(colour) {
 
  61     if (window.getSelection) {
 
  63         sel = window.getSelection();
 
  65             range = sel.getRangeAt(0);
 
  67         document.designMode = "on";
 
  69             sel.removeAllRanges();
 
  72         // Use HiliteColor since some browsers apply BackColor to the whole block
 
  73         if ( !document.execCommand("HiliteColor", false, colour) ) {
 
  74             document.execCommand("BackColor", false, colour);
 
  76         document.designMode = "off";
 
  77     } else if (document.selection && document.selection.createRange) {
 
  79         range = document.selection.createRange();
 
  80         range.execCommand("BackColor", false, colour);
 
  84 // function unselectThemes(themeId) {
 
  85 //     $('.Apple-style-span').each(function() {
 
  86 //         $(this).after($(this).html());
 
  91 function gallery(element, url) {    
 
  92     var element = $(element);
 
  93     var imageDimensions = {};
 
  94     element.data('images', []);
 
  96     function changePage(pageNumber) {        
 
  97         $('.gallery-image img', element).attr('src', element.data('images')[pageNumber - 1]);
 
 100     function normalizeNumber(pageNumber) {
 
 101         // Numer strony musi być pomiędzy 1 a najwyższym numerem
 
 102         var pageCount = element.data('images').length;
 
 103         pageNumber = parseInt(pageNumber, 10);
 
 105         if (!pageNumber || pageNumber == NaN || pageNumber == Infinity || pageNumber == -Infinity) {
 
 107         } else if (pageNumber < 1) {
 
 109         } else if (pageNumber > pageCount) {
 
 116     var pn = $('.page-number', element);
 
 117     pn.change(function(event) {
 
 118         event.preventDefault();
 
 119         var n = normalizeNumber(pn.val());
 
 123     $('.previous-page', element).click(function() {
 
 124         pn.val(normalizeNumber(pn.val()) - 1);
 
 127     $('.next-page', element).click(function() {
 
 128         pn.val(normalizeNumber(pn.val()) + 1);
 
 133     var image = $('.gallery-image img', element).attr('unselectable', 'on');
 
 135     var imageOrigin = {};
 
 138     $('.zoom-in', element).click(function() {
 
 139         zoomFactor = Math.min(2, zoomFactor + 0.2);
 
 142     $('.zoom-out', element).click(function() {
 
 143         zoomFactor = Math.max(0.2, zoomFactor - 0.2);
 
 146     $('.change-gallery', element).click(function() {
 
 147         $('.chosen-gallery').val($('#document-meta .gallery').html() || '/platforma/gallery/');
 
 148         $('.gallery-image').animate({top: 60}, 200);
 
 149         $('.chosen-gallery').focus();
 
 151     $('.change-gallery-ok', element).click(function() {
 
 152         if ($('#document-meta .gallery').length == 0) {
 
 153             $('<div class="gallery"></div>').appendTo('#document-meta');
 
 155         $('#document-meta .gallery').html($('.chosen-gallery').val());
 
 156         updateGallery($('.chosen-gallery').val());
 
 157         $('.gallery-image').animate({top: 30}, 200);
 
 159     $('.change-gallery-cancel', element).click(function() {
 
 160         $('.gallery-image').animate({top: 30}, 200);
 
 163     $('.gallery-image img', element).load(function() {
 
 164         image.css({width: null, height: null});
 
 166             width: $(this).width() * zoomFactor,
 
 167             height: $(this).height() * zoomFactor,
 
 168             originWidth: $(this).width(),
 
 169             originHeight: $(this).height(),
 
 170             galleryWidth: $(this).parent().width(),
 
 171             galleryHeight: $(this).parent().height()
 
 174         if (!(imageDimensions.width && imageDimensions.height)) {
 
 175             setTimeout(function() { $('.gallery-image img', element).load(); }, 100);
 
 177         var position = normalizePosition(
 
 178             image.position().left,
 
 179             image.position().top, 
 
 180             imageDimensions.galleryWidth,
 
 181             imageDimensions.galleryHeight,
 
 182             imageDimensions.width,
 
 183             imageDimensions.height
 
 185         image.css({left: position.x, top: position.y, width: $(this).width() * zoomFactor, height: $(this).height() * zoomFactor});
 
 188     $(window).resize(function() {
 
 189         imageDimensions.galleryWidth = image.parent().width();
 
 190         imageDimensions.galleryHeight = image.parent().height();
 
 193     function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight) {
 
 197             minX: galleryWidth - imageWidth,
 
 198             minY: galleryHeight - imageHeight
 
 202     function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight) {
 
 203         var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
 
 205             x: Math.min(b.maxX, Math.max(b.minX, x)),
 
 206             y: Math.min(b.maxY, Math.max(b.minY, y))
 
 210     function onMouseMove(event) {
 
 211         var position = normalizePosition(
 
 212             event.clientX - origin.x + imageOrigin.left,
 
 213             event.clientY - origin.y + imageOrigin.top, 
 
 214             imageDimensions.galleryWidth,
 
 215             imageDimensions.galleryHeight,
 
 216             imageDimensions.width,
 
 217             imageDimensions.height
 
 219         image.css({position: 'absolute', top: position.y, left: position.x});
 
 223     function setZoom(factor) {
 
 228         imageDimensions.width = imageDimensions.originWidth * zoomFactor;
 
 229         imageDimensions.height = imageDimensions.originHeight * zoomFactor;
 
 230         var position = normalizePosition(
 
 231             image.position().left,
 
 232             image.position().top, 
 
 233             imageDimensions.galleryWidth,
 
 234             imageDimensions.galleryHeight,
 
 235             imageDimensions.width,
 
 236             imageDimensions.height
 
 238         image.css({width: imageDimensions.width, height: imageDimensions.height,
 
 239             left: position.x, top: position.y});
 
 243     function onMouseUp(event) {
 
 245             .unbind('mousemove.gallery')
 
 246             .unbind('mouseup.gallery');
 
 250     image.bind('mousedown', function(event) {
 
 255         imageOrigin = image.position();
 
 257             .bind('mousemove.gallery', onMouseMove)
 
 258             .bind('mouseup.gallery', onMouseUp);
 
 262     function updateGallery(url) {
 
 268             success: function(data) {
 
 269                 element.data('images', data);
 
 272                 $('.gallery-image img', element).show();
 
 275             error: function(data) {
 
 276                 element.data('images', []);
 
 279                 $('.gallery-image img', element).hide();
 
 290 function transform(editor, callback) {
 
 292         $.blockUI({message: 'Ładowanie...'});
 
 294     setTimeout(function() {
 
 296             xml: editor.getCode(),
 
 297             success: function(element) {
 
 298                 $('#html-view').html(element);
 
 303             }, error: function(text) {
 
 304                                 var message = $('<pre></pre>');
 
 306                 $('#html-view').html('<p class="error">Wystąpił błąd:</p><pre>' + 
 
 307                                     message.html() + '</pre>');
 
 319 function reverseTransform(editor, cont, errorCont, dontBlock) {
 
 320     var serializer = new XMLSerializer();
 
 321     if ($('#html-view .error').length > 0) {
 
 328         $.blockUI({message: 'Ładowanie...'});
 
 330     setTimeout(function() {
 
 332                         element: $('#html-view div').get(0),            
 
 333             success: function(text) {
 
 334                 editor.setCode(text);
 
 341             }, error: function(text) {
 
 342                 $('#source-editor').html('<p>Wystąpił błąd:</p><pre>' + text + '</pre>');
 
 358 function html(element) {
 
 359     var element = $(element);
 
 361     function selectTheme(themeId)
 
 363         var selection = window.getSelection();
 
 364         selection.removeAllRanges();
 
 366         var range = document.createRange();
 
 367         var s = $(".motyw[theme-class='"+themeId+"']")[0];
 
 368         var e = $(".end[theme-class='"+themeId+"']")[0];
 
 371             range.setStartAfter(s);
 
 372             range.setEndBefore(e);
 
 373             selection.addRange(range);
 
 377     function verifyTagInsertPoint(node) {
 
 378         if(node.nodeType == 3) { // Text Node
 
 379             node = node.parentNode;
 
 382         if (node.nodeType != 1) { 
 
 387         var xtype = node.attr('x-node');
 
 389         if (!xtype || (xtype.search(':') >= 0) ||
 
 390             xtype == 'motyw' || xtype == 'begin' || xtype == 'end') {
 
 394         // don't allow themes inside annotations
 
 395         if( node.is('*[x-annotation-box] *') )
 
 401         var ANNOT_ALLOWED = ['wyroznienie'];
 
 403         function html2plainText(fragment) {
 
 406                 $(fragment.childNodes).each(function() {
 
 407                         if(this.nodeType == 3) // textNode
 
 408                             text += this.nodeValue;
 
 409                         else if (this.nodeType == 1 
 
 410                             && $.inArray($(this).attr('x-node'), ANNOT_ALLOWED) != -1 ){
 
 411                                 text += html2plainText(this);                           
 
 418     function addAnnotation()
 
 420         var selection = window.getSelection();
 
 421         var n = selection.rangeCount;
 
 424             window.alert("Nie zaznaczono żadnego obszaru");
 
 428         // for now allow only 1 range
 
 430             window.alert("Zaznacz jeden obszar");
 
 434         // remember the selected range
 
 435         var range = selection.getRangeAt(0);
 
 437         if (!verifyTagInsertPoint(range.endContainer)) {
 
 438             window.alert("Nie można wstawić w to miejsce przypisu.");
 
 442                 // BUG #273 - selected text can contain themes, which should be omited from
 
 444         var text = html2plainText( range.cloneContents() ); 
 
 446         var tag = $('<span></span>');
 
 447         range.collapse(false);
 
 448         range.insertNode(tag[0]);
 
 451             xml: '<pr><slowo_obce>'+text+'</slowo_obce> --- </pr>',
 
 452             success: function(text) {
 
 459                 alert('Błąd przy dodawaniu przypisu:' + errors);                
 
 466         var selection = window.getSelection();
 
 467         var n = selection.rangeCount;
 
 470             window.alert("Nie zaznaczono żadnego obszaru");
 
 474         // for now allow only 1 range
 
 476             window.alert("Zaznacz jeden obszar.");
 
 481         // remember the selected range
 
 482         var range = selection.getRangeAt(0);
 
 485                 if( $(range.startContainer).is('.html-editarea') 
 
 486                  || $(range.endContainer).is('.html-editarea') ) {
 
 487                         window.alert("Motywy można oznaczać tylko na tekście nie otwartym do edycji. \n Zamknij edytowany fragment i spróbuj ponownie.");
 
 491         // verify if the start/end points make even sense -
 
 492         // they must be inside a x-node (otherwise they will be discarded)
 
 493         // and the x-node must be a main text
 
 494         if (!verifyTagInsertPoint(range.startContainer)) {
 
 495             window.alert("Motyw nie może się zaczynać w tym miejscu.");
 
 499         if (!verifyTagInsertPoint(range.endContainer)) {
 
 500             window.alert("Motyw nie może się kończyć w tym miejscu.");
 
 504         var date = (new Date()).getTime();
 
 505         var random = Math.floor(4000000000*Math.random());
 
 506         var id = (''+date) + '-' + (''+random);
 
 508         var spoint = document.createRange();
 
 509         var epoint = document.createRange();
 
 511         spoint.setStart(range.startContainer, range.startOffset);
 
 512         epoint.setStart(range.endContainer, range.endOffset);
 
 514         var mtag, btag, etag, errors;
 
 519             xml: '<end id="e'+id+'" />',
 
 520             success: function(text) {
 
 521                 etag = $('<span></span>');
 
 522                 epoint.insertNode(etag[0]);
 
 523                 etag.replaceWith(text);
 
 525                     xml: '<motyw id="m'+id+'"></motyw>',
 
 526                     success: function(text) {                                           
 
 527                         mtag = $('<span></span>');
 
 528                         spoint.insertNode(mtag[0]);
 
 529                         mtag.replaceWith(text);
 
 531                             xml: '<begin id="b'+id+'" />',
 
 532                             success: function(text) {
 
 533                                 btag = $('<span></span>');
 
 534                                 spoint.insertNode(btag[0])
 
 535                                 btag.replaceWith(text);
 
 536                                 selection.removeAllRanges();
 
 537                                 openForEdit($('.motyw[theme-class=' + id + ']'));
 
 546     function openForEdit($origin)
 
 550         // annotations overlay their sub box - not their own box //
 
 551         if($origin.is(".annotation-inline-box")) {
 
 552             $box = $("*[x-annotation-box]", $origin);
 
 557         var x = $box[0].offsetLeft;
 
 558         var y = $box[0].offsetTop;
 
 559         var w = $box.outerWidth();
 
 560         var h = $box.innerHeight();
 
 562         if ($origin.is(".annotation-inline-box")) {
 
 563             w = Math.max(w, 400);
 
 567         // start edition on this node
 
 568         var $overlay = $('<div class="html-editarea"><button class="accept-button">Zapisz</button><button class="delete-button">Usuń</button><textarea></textarea></div>').css({
 
 569             position: 'absolute',
 
 574         }).appendTo($box[0].offsetParent || $box.parent()).show();
 
 576         if ($origin.is('.motyw')) {
 
 577             $('textarea', $overlay).autocomplete(THEMES, {
 
 584         $('.delete-button', $overlay).click(function() {
 
 585             if ($origin.is('.motyw')) {
 
 586                 $('[theme-class=' + $origin.attr('theme-class') + ']').remove();
 
 591             $(document).unbind('click.blur-overlay');
 
 596         var serializer = new XMLSerializer();
 
 601             success: function(text) {
 
 602                 $('textarea', $overlay).val($.trim(text));
 
 604                 setTimeout(function() {
 
 605                     $('textarea', $overlay).elastic().focus();
 
 608                 function save(argument) {
 
 609                     var nodeName = $box.attr('x-node') || 'pe';
 
 610                                         var insertedText = $('textarea', $overlay).val();
 
 612                                         if ($origin.is('.motyw')) {
 
 613                                                 insertedText = insertedText.replace(/,\s*$/, '');
 
 617                         xml: '<' + nodeName + '>' + insertedText + '</' + nodeName + '>',
 
 618                         success: function(element) {
 
 619                             $origin.html($(element).html());
 
 622                         error: function(text) {
 
 624                             alert('Błąd! ' + text);
 
 629                 $('.accept-button', $overlay).click(function() {
 
 633                 $(document).bind('click.blur-overlay', function(event) {
 
 634                     if ($(event.target).parents('.html-editarea').length > 0) {
 
 639                     $(document).unbind('click.blur-overlay');
 
 642             }, error: function(text) {
 
 643                 alert('Błąd! ' + text);
 
 648     $('.edit-button').live('click', function(event) {
 
 649         event.preventDefault();
 
 650         openForEdit($(this).parent());
 
 655     var button = $('<button class="edit-button">Edytuj</button>');
 
 656     $(element).bind('mousemove', function(event) {
 
 657         var editable = $(event.target).closest('*[x-editable]');
 
 658         $('.active[x-editable]', element).not(editable).removeClass('active').children('.edit-button').remove();
 
 659         if (!editable.hasClass('active')) {
 
 660             editable.addClass('active').append(button);
 
 662         if (editable.is('.annotation-inline-box')) {
 
 663             $('*[x-annotation-box]', editable)
 
 664                 .css({position: 'absolute', left: event.clientX - editable.offset().left + 5, top: event.clientY - editable.offset().top + 5})
 
 667             $('*[x-annotation-box]').hide();
 
 671     $('.motyw').live('click', function() {
 
 672         selectTheme($(this).attr('theme-class'));
 
 675     $('#insert-annotation-button').click(function() {
 
 680     $('#insert-theme-button').click(function() {
 
 690 function refreshHistory(callback){
 
 692                 message: 'Odświeżanie historii...'
 
 696                 url: document.location.href + '/history',
 
 699                         $('#history-view .message-box').html('Nie udało się odświeżyć historii').show();
 
 702                 success: function(data) {
 
 703                         $('#history-view .message-box').hide();
 
 704                         var changes_list = $('#changes-list');
 
 705                         changes_list.html('');
 
 707                         $.each(data, function() {
 
 709                                 changes_list.append('<tr>'
 
 710                                         +'<td><input type="radio" name="rev_from" value="'+val+'">'
 
 711                                                 + '<input type="radio" name="rev_to" value="'+val+'">'
 
 712                                         +'<td>'+ this[0]+'</td>'
 
 713                                         +'<td>'+ this[3]+'</td>'
 
 714                                         +'<td>'+ this[2]+'</td>'
 
 715                                         +'<td>'+ this[1]+'</td></tr>')                  
 
 718                         if(callback) callback();
 
 723 function historyDiff(callback) {
 
 724         var changelist = $('#changes-list');
 
 725         var rev_a = $("input[name='rev_from']:checked", changelist);
 
 726         var rev_b = $("input[name='rev_to']:checked", changelist);
 
 728         if (rev_a.length != 1 || rev_b.length != 1) {
 
 729                 window.alert("Musisz zaznaczyć dwie wersje do porównania.");
 
 733         if (rev_a.val() == rev_b.val()) {
 
 734                 window.alert("Musisz zaznaczyć dwie różne wersje do porównania.");
 
 739                 message: 'Wczytywanie porównania...'
 
 743                 url: document.location.href + '/diff/'+rev_a.val() + '/'+ rev_b.val(),
 
 747                         window.alert('Nie udało się wykonać porównania :(.')                                        
 
 749                 success: function(data) {
 
 751                         var diffview = $('#diff-view');                 
 
 760     gallery('#sidebar', $('#document-meta .gallery').html());
 
 763     CodeMirror.fromTextArea('id_text', {
 
 764         parserfile: 'parsexml.js',
 
 765         path: STATIC_URL + "js/lib/codemirror/",
 
 766         stylesheet: STATIC_URL + "css/xmlcolors.css",
 
 768             useHTMLKludges: false
 
 770         iframeClass: 'xml-iframe',              
 
 776         initCallback: function(editor) {
 
 777             $('#save-button').click(function(event) {
 
 778                 event.preventDefault();
 
 779                 $.blockUI({message: $('#save-dialog')});
 
 782             $('#save-ok').click(function() {
 
 783                 $.blockUI({message: 'Zapisywanie...'});
 
 785                 function doSave (argument) {
 
 786                     var metaComment = '<!--';
 
 787                     $('#document-meta div').each(function() {
 
 788                         metaComment += '\n\t' + $(this).attr('class') + ': ' + $(this).html();
 
 790                     metaComment += '\n-->'
 
 793                         name: $('#document-name').html(),
 
 794                         text: metaComment + editor.getCode(),
 
 795                         revision: $('#document-revision').html(),
 
 796                         author: $('#username').html() || 'annonymous',
 
 797                         comment: $('#komentarz').val()
 
 801                         url: document.location.href,
 
 805                         success: function(data) {
 
 807                                 editor.setCode(data.text);
 
 808                                 $('#document-revision').html(data.revision);
 
 814                         error: function(xhr, textStatus, errorThrown) {
 
 815                             alert('error: ' + textStatus + ' ' + errorThrown);
 
 820                 if ($('#simple-view-tab').hasClass('active')) {
 
 821                     reverseTransform(editor, doSave);
 
 827             $('#save-cancel').click(function() {
 
 831             var tabs = $('ol#tabs li');
 
 833                         tabs.click(function(event, callback) {
 
 834                                 tabs.removeClass('active');
 
 836                                 $(this).addClass('active');
 
 837                                 $('#' + $(this).attr('ui:related')).show();                             
 
 838                                 $(this).trigger('wl:tabload', callback);                                                                
 
 842             $('#simple-view-tab').bind('wl:tabload', function(event, callback) {
 
 843                 transform(editor, callback);
 
 846                         $('#source-view-tab').bind('wl:tabload', function(event, callback) {
 
 847                 reverseTransform(editor, callback);
 
 850                         $('#history-view-tab').bind('wl:tabload', function(event, callback) {
 
 851                                 refreshHistory(callback);                                                               
 
 854                         $('#make-diff-button').click(historyDiff);
 
 856             $('#source-editor .toolbar button').click(function(event) {
 
 857                 event.preventDefault();
 
 858                 var params = eval("(" + $(this).attr('ui:action-params') + ")");
 
 859                 scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
 
 862             $('.toolbar select').change(function(event) {
 
 863                 var slug = $(this).val();
 
 865                 $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
 
 869             $('.toolbar-buttons-container').hide();
 
 870             $('.toolbar select').change();
 
 873                         $('#simple-view-tab').trigger('click', 
 
 875                                         $('#loading-overlay').fadeOut();
 
 881     $(window).resize(function() {
 
 882         $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());
 
 887     $('.vsplitbar').click(function() {
 
 888         if ($('#sidebar').width() == 0) {
 
 889             $('#sidebar').width(480).css({right: 0}).show();
 
 890             $('#editor .editor').css({right: 495});
 
 891             $('.vsplitbar').css({right: 480}).addClass('active');
 
 893             $('#sidebar').width(0).hide();
 
 894             $('#editor .editor').css({right: 15});
 
 895             $('.vsplitbar').css({right: 0}).removeClass('active');
 
 900         $(window).bind('beforeunload', function(event) {
 
 901                 return "Na stronie mogą być niezapisane zmiany.";