PageSourceSearch

https://photocentra.com/js/default606.js

js photocentra.com collected 2026-09-26 10:40:05 UTC 213,398 bytes, 5,591 lines download raw bytes

1/* utils functions */
2var cookie = {
3    setCookie: function(a, b) {
4        document.cookie = a + "=" + b + ";expires=" + expireDate.toUTCString() + ";path=/;domain=." + SiteDom + "." + domainEnd
5    },
6    setMinutesCookie: function(a, b, c) {
7        var d = new Date,
8            e = d.getTime();
9        d.setTime(e + 6E4 * c);
10        document.cookie = a + "=" + b + ";expires=" + d.toUTCString() + ";path=/;domain=." + SiteDom + "." + domainEnd
11    },
12    getCookie: function(a) {
13        a = new RegExp(a + "=[^;]+", "i");
14        return document.cookie.match(a) ? document.cookie.match(a)[0].split("=")[1] : null
15    }
16};
17
18var utils = {
19    isMobile: function() {
20        return 768 >= Math.min(window.innerWidth, screen.width);
21    },
22    isTouch: function() {
23        return 'ontouchstart' in window || navigator.maxTouchPoints;
24    },
25    endsWith: function(str, suffix) {
26        return str.indexOf(suffix, str.length - suffix.length) !== -1;
27    }
28};
29
30function getRecsComm(id_photo, id_auth, auth_name, comm_num) {
31    $("#recWithCTbl").hide();
32    var $addRecAjax = $("#addRecAjax"+comm_num);
33    //$addRecAjax.html(ploc.already_rec_note_loc);
34    //$("#previewRec").html(ploc.already_rec_note_loc);
35    var $oldRate = $addRecAjax.attr('data-ph-rating');
36    var isUp = false;
37    setTimeout(function() {
38        if (!isUp)
39            $addRecAjax.html(loaderGray);
40    }, 500);
41    $.get(ajaxFld + "get_recs.php", {
42        id_photo: id_photo
43    }, function(data) {
44        NProgress.done();
45        isUp = true;
46        $addRecAjax.html('<span class="commShowRating"><svg id="icon-check" viewBox="0 0 225 225" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><g transform="matrix(1,0,0,1,-178.667,-170.667)"><g class="check" transform="matrix(1,0,0,1,176,113)"><path d="M65,166L101,202L165,138" style="fill:none;stroke:#ea3970;stroke-width:16.67px;"></path></g><circle class="circle" cx="291" cy="283" r="104" style="fill:none;stroke:#2a2a31;stroke-width:16.67px;"></circle></g></svg>' + ploc.rating_loc + ': ' + roundExt((parseFloat($oldRate) + parseFloat(data)), 2) + '</span>');
47        var $recCnt = $("#recCnt");
48        $recCnt.text(parseInt($recCnt.text()) + 1);
49        var $recsAjax = $("#recsAjax");
50        var $old = $recsAjax.html();
51        if ($old) {
52            $old = $old.substr(0, $old.length - 1);
53            $recsAjax.html($old + " <a href=\"/author.php?id_auth=" + id_auth + "\">" + auth_name + "</a>");
54        }
55    });
56}
57
58/* functions */
59function startNProgress() {
60    if (NProgress.status === null) {
61        NProgress.start();
62        setTimeout(function() {
63            NProgress.done();
64        }, 20000);
65    }
66}
67
68function getIEVer() {
69    var rv = -1;
70    if (navigator.appName == 'Microsoft Internet Explorer') {
71        var ua = navigator.userAgent;
72        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
73        if (re.exec(ua) != null)
74            rv = parseFloat(RegExp.$1);
75    } else if (navigator.appName == 'Netscape') {
76        var ua = navigator.userAgent;
77        var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
78        if (re.exec(ua) != null)
79            rv = parseFloat(RegExp.$1);
80    }
81    return rv;
82}
83
84function getBrowserLang() {
85    return lang = "undefined" != typeof navigator.language ? navigator.language : "undefined" != typeof navigator.browserLanguage ? navigator.browserLanguage : "undefined" != typeof navigator.systemLanguage ? navigator.systemLanguage : "undefined" != typeof navigator.userLanguage ? navigator.userLanguage : "ru"
86}
87
88function preloadImg(a) {
89    (new Image).src = a
90}
91
92function getEl(a) {
93    return document.getElementById ? document.getElementById(a) : document.all ? document.all[a] : document.layers ? document.layers[a] : NULL
94}
95
96function info(a) {
97    "undefined" != typeof console && console.info(a)
98}
99
100function dir(a) {
101    "undefined" != typeof console && console.dir(a)
102}
103
104function log() {
105    console.log.apply(console, arguments);
106}
107
108function setDeceleratingTimeout(a, b, c) {
109    var d = function(c, f) {
110        return function() {
111            0 < --c && (window.setTimeout(d, ++f * b),
112                a())
113        }
114    }(c, 0);
115    window.setTimeout(d, b)
116}
117
118function scrollTopMenu(pos) {
119
120    setTimeout(function() {
121        if (window.scroll)
122            window.scroll(0, pos);
123    }, 100);
124
125    scrollDirection = 'up';
126
127}
128
129function roundExt(a, b) {
130    return Math.round(a * Math.pow(10, b)) / Math.pow(10, b)
131}
132
133// function updateTextareaHeight(el) {
134//     var lht = parseInt(el.css('line-height'), 10);
135//     var lines = Math.floor(el.prop('scrollHeight') / lht);
136//     var elH = lines * lht;
137//     if (elH > 276)
138//         el.css({
139//             'height': elH + 'px'
140//         });
141//     else
142//         el.css({
143//             'height': '276px'
144//         });
145// }
146
147/* init vars */
148var isMobVer = utils.isMobile(),
149    minCommLen = 5,
150    maxCommLen = 3E4,
151    homeUrl = window.location.host,
152    domainEnd = homeUrl.substr(homeUrl.lastIndexOf(".") + 1),
153    homeUrl = "by" == domainEnd ? "photoclub." + domainEnd : "photocentra." + domainEnd;
154
155var globalIsMulti = false;    
156
157//var screenW = Math.min(window.innerWidth, screen.width);
158//var screenH = Math.min(window.innerHeight, screen.height);
159var screenW = document.documentElement.clientWidth || document.body.clientWidth;
160var screenH = document.documentElement.clientHeight || document.body.clientHeight;
161
162log('isMobVer:', isMobVer, 'screenW:', screenW, 'screenH:', screenH);
163cookie.setCookie('isMobVer', isMobVer);
164
165var scrollTopPos = 0,
166    errColor = "#E90000",
167    okColor = "#009900",
168    $ccode = cookie.getCookie("ccode");
169var at_pub = "@",
170    isIE = !1;
171$.browser.msie && (isIE = !0);
172isIE && cookie.setCookie("isIE", 1);
173var id_auth_answer = 0,
174    id_comm_parent = 0,
175    screenWidth = screenW,
176    screenHeight = screenH,
177    theme = cookie.getCookie("theme");
178"def" != theme && "black" != theme && (theme = "def");
179if ("black" == theme)
180    var actMenuBg = "#1F1F1F",
181        actMenuColor = "#ffffff",
182        inactMenuColor = "#627ba0";
183else
184    actMenuBg = "#8dbfd6",
185    actMenuColor = "#ffffff",
186    inactMenuColor = "#2678af";
187var portInstallLoader = '<img src="/css/' + theme + '/port_install_loader.gif">',
188    loaderGray = '<img src="/css/' + theme + '/loader_gray.new.gif">',
189    loaderComm = '<img src="/css/' + theme + '/loader_comm.new.gif">',
190    loaderGall = '<img src="/css/' + theme + '/loader_gall.new.gif">';
191if (typeof isShareToView === "undefined")
192    isShareToView = true;
193var bgColor = '#999';
194if (theme == 'black')
195    bgColor = '#303030';
196
197/* ----------------- Localizer ----------------- */
198var ploc = {
199    by: {
200        ed_license_label_loc: 'Лицензия editorial',
201        comm_license_label_loc: 'Лицензия commercial',
202        fee_loc: '%',
203        stock_photo_loc: 'M',
204        art_photo_loc: 'G',
205        all_photos_loc: 'Все фото',
206        l_for_sale_loc: 'Продается',
207        art_photos_loc: 'Галерея',
208        stock_photos_loc: 'Маркетплейс',
209        images_loc: '',
210        get_follow: 'Подписаться',
211        already_rec_note_loc: 'Спасибо, ваша<br>рекомендация принята',
212        edit_comm_loc: 'Редактировать сообщение',
213        cancel_loc: 'Отменить',
214        upload_failed_loc: 'Ошибка, файл должен быть меньше 12Мб',
215        save_comm_loc: 'Сохранить сообщение',
216        edit_loc: 'Редактировать',
217        serie_loc: 'Серия',
218        place_loc: 'место',
219        photo_contest_loc: 'Фотоконкурс',
220        oncomp_let_loc: 'К',
221        work_of_day_loc: 'Работа дня',
222        workofday_let_loc: 'РД',
223        for_critique_loc: 'Работа для критики',
224        for_critique_let_loc: 'Критика',
225        till_loc: 'до',
226        rating_loc: 'Рейтинг',
227        aver_mark_loc: 'Средняя оценка',
228        rec_loc: 'Рекомендации',
229        add_rec_loc: 'Рекомендовать',
230        comments_loc: 'Обсуждение',
231        to_first_page_loc: 'К первой странице обсуждения',
232        do_want_del_comm_loc: 'Вы действительно хотите удалить это сообщение?',
233        del_loc: 'Удалить',
234        sel_citation_loc: 'Цитата выделенного',
235        from_loc: 'от',
236        click_to_paste_name_loc: 'Нажмите, для того, чтобы вставить имя автора в сообщение',
237        best_work_loc: 'Лучшие работы',
238        last_works_loc: 'Последние работы',
239        auth_profile_loc: 'Профиль автора',
240        thankyou_mark_loc: 'Спасибо, ваша оценка принята',
241        be_constructive_loc: 'Текст сообщения должен содержать хотя бы ' + minCommLen + ' букв',
242        max_comm_len_loc: 'Сообщение должно содержать не более ' + maxCommLen + ' символов',
243        vote_accept_loc: 'Спасибо, ваш голос принят',
244        no_works_loc: 'Извините, но тут не найдено никаких работ',
245        no_auth_works_loc: 'Автор пока не добавил ни одной работы',
246        no_followers_loc: 'У автора пока нет ни одного подписчика',
247        hide_block_loc: 'Свернуть блок',
248        show_block_loc: 'Развернуть блок',
249        res_contest_loc: 'Результаты конкурса',
250        sort_rating_loc: 'Сортировать по рейтингу',
251        all_works_contest_loc: 'Все работы конкурса',
252        vote_accept_short_loc: 'Ваш голос<br>принят',
253        answer_loc: 'Ответить',
254        informative_loc: 'Содержательно',
255        in_portfolio_loc: 'в портфолио',
256        in_portfolio_note_loc: 'в портфолио',
257        add_work1_loc: 'Добавить работу',
258        add_work2_loc: '',
259        drop_upload_loc: 'Перетащите сюда файл<br>для загрузки в потфолио',
260        in_gall_loc: 'в галерею',
261        in_gall_note_loc: 'Загрузка в публичную галерею для оценки другими пользователями',
262        crop_var_loc: 'Вариант кадрирования',
263        mobile_ver_loc: 'Мобильная версия',
264        click_choose_city_loc: 'Кликните, чтобы выбрать город',
265        choose_city_loc: 'Выберите город',
266        select_region_loc: 'Выберите регион',
267        voter_for_meaning_loc: 'Голоса за содержательность',
268        appeal_loc: 'Пожаловаться',
269        why_appeal_loc: 'Укажите причину жалобы на сообщение: #',
270        appeal_ok_loc: 'Спасибо, ваша жалоба была успешно отправлена',
271        show_all_comm_loc: 'Показать все сообщения',
272        goto_photo_page_loc: 'Перейти на страницу фото',
273        add_comm_loc: 'Добавить сообщение',
274        comm_added_loc: 'Сообщение добавлено',
275        all_views_loc: 'Все просмотры',
276        all_recs_loc: 'Все рекомендации',
277        ban_author_loc: 'Заблокировать автора',
278        unban_author_loc: 'Разблокировать автора'
279    },
280    com: {
281        ed_license_label_loc: 'Editorial license',
282        comm_license_label_loc: 'Commercial license',
283        fee_loc: 'fee',
284        stock_photo_loc: 'M',
285        art_photo_loc: 'G',
286        l_for_sale_loc: 'Listed for sale',
287        all_photos_loc: 'All photos',
288        art_photos_loc: 'Gallery',
289        stock_photos_loc: 'Marketplace',
290        images_loc: 'images',
291        get_follow: 'Follow',
292        already_rec_note_loc: 'Your recommendation<br>has been received',
293        edit_comm_loc: 'Edit message',
294        cancel_loc: 'Cancel',
295        upload_failed_loc: 'Failed, max file size is 12Mb',
296        save_comm_loc: 'Save message',
297        edit_loc: 'Edit',
298        serie_loc: 'Serie',
299        place_loc: 'place',
300        photo_contest_loc: 'Contest',
301        oncomp_let_loc: 'C',
302        work_of_day_loc: 'Photo of the day',
303        workofday_let_loc: 'D',
304        for_critique_loc: 'For criticism',
305        for_critique_let_loc: 'Criticism',
306        till_loc: 'till',
307        rating_loc: 'Rating',
308        aver_mark_loc: 'Average mark',
309        rec_loc: 'Recommendations',
310        add_rec_loc: 'Recommend',
311        comments_loc: 'Discussion',
312        to_first_page_loc: 'First page',
313        do_want_del_comm_loc: 'Are you really want to delete this message?',
314        del_loc: 'Delete',
315        sel_citation_loc: 'Quote selected text',
316        from_loc: 'from',
317        click_to_paste_name_loc: 'Click to put author’s name into your message',
318        best_work_loc: 'Most rated photos',
319        last_works_loc: 'Latest photos',
320        auth_profile_loc: 'Profile',
321        thankyou_mark_loc: 'Your mark has been received',
322        be_constructive_loc: 'Comment should contain at least ' + minCommLen + ' characters',
323        max_comm_len_loc: 'Comment should contain up to ' + maxCommLen + ' characters',
324        vote_accept_loc: 'Your vote has been received',
325        no_works_loc: 'Sorry, but there are no photos here',
326        no_auth_works_loc: 'Author hasn’t added any photo yet',
327        no_followers_loc: 'Author has no followers',
328        hide_block_loc: 'Hide block',
329        show_block_loc: 'Show block',
330        res_contest_loc: 'Contest results',
331        sort_rating_loc: 'Sort by rating',
332        all_works_contest_loc: 'Contest all photos',
333        vote_accept_short_loc: 'Your vote<br>
333has been received',
334        answer_loc: 'Answer',
335        informative_loc: 'Informative',
336        in_portfolio_loc: 'to the portfolio',
337        in_portfolio_note_loc: 'to the portfolio',
338        add_work1_loc: 'Upload photo',
339        add_work2_loc: '',
340        drop_upload_loc: 'Drop files here to upload',
341        in_gall_loc: 'to the gallery',
342        in_gall_note_loc: 'Upload to the gallery for rating and comments',
343        crop_var_loc: 'Crop',
344        mobile_ver_loc: 'Mobile version',
345        click_choose_city_loc: 'Click to choose city',
346        choose_city_loc: 'Choose city',
347        select_region_loc: 'Choose region',
348        voter_for_meaning_loc: 'Votes for informative comments',
349        appeal_loc: 'Complain',
350        why_appeal_loc: 'Please tell us complaint reason for message: #',
351        appeal_ok_loc: 'Thank you, your complaint was successfully sent',
352        show_all_comm_loc: 'Show all comments',
353        goto_photo_page_loc: 'Open photo’s full page',
354        add_comm_loc: 'Add message',
355        comm_added_loc: 'Message posted',
356        all_views_loc: 'All views',
357        all_recs_loc: 'All recommendations',
358        ban_author_loc: 'Block author',
359        unban_author_loc: 'Unblock author'
360    },
361    de: {
362        ed_license_label_loc: 'Editorial license',
363        comm_license_label_loc: 'Commercial license',
364        fee_loc: 'fee',
365        stock_photo_loc: 'Marketplace',
366        art_photo_loc: 'Gallery',
367        all_photos_loc: 'All photo',
368        stock_photo_loc: 'M',
369        art_photo_loc: 'G',
370        l_for_sale_loc: 'Listed for sale',
371        images_loc: '',
372        get_follow: 'Folgen',
373        already_rec_note_loc: 'Danke, Ihre Empfehlung<br>wurde gezählt',
374        edit_comm_loc: 'Anmerkung editieren',
375        cancel_loc: 'Abbrechen',
376        upload_failed_loc: 'Fehler, max Dateigröße ist 12Mb',
377        save_comm_loc: 'Anmerkung speichern',
378        edit_loc: 'Editieren',
379        serie_loc: 'Serie',
380        place_loc: 'Platz',
381        photo_contest_loc: 'Fotowettbewerb',
382        oncomp_let_loc: 'WB',
383        work_of_day_loc: 'Bild des Tages',
384        workofday_let_loc: 'BT',
385        for_critique_loc: 'Bild mit Kritikanfrage',
386        for_critique_let_loc: 'Kritikanfrage',
387        till_loc: 'bis',
388        rating_loc: 'Rating',
389        aver_mark_loc: 'Durchschnittsbewertung',
390        rec_loc: 'Empfehlungen',
391        add_rec_loc: 'Empfehlen',
392        comments_loc: 'Diskussion',
393        to_first_page_loc: 'Zu den ersten Anmerkungen',
394        do_want_del_comm_loc: 'Möchten Sie diese Anmerkung wirklich löschen?',
395        del_loc: 'Löschen',
396        sel_citation_loc: 'Markierten Text zitieren',
397        from_loc: 'von',
398        click_to_paste_name_loc: 'Klicken Sie bitte hier, um den Namen des Benutzers zu Ihrer Anmerkung hinzufügen',
399        best_work_loc: 'Die besten Bilder',
400        last_works_loc: 'Die letzten Bilder',
401        auth_profile_loc: 'Benutzerprofil',
402        thankyou_mark_loc: 'Danke, Ihre Bewertung wurde gezählt',
403        be_constructive_loc: 'Ihre Anmerkung soll mindestens ' + minCommLen + ' Buchstaben enthalten',
404        max_comm_len_loc: 'Eine Anmerkung darf bis zu ' + maxCommLen + ' Zeichen enthalten',
405        vote_accept_loc: 'Danke, Ihre Stimme wurde gezählt',
406        no_works_loc: 'Sorry, es gibt keine Bilder here',
407        no_auth_works_loc: 'Der Benutzer hat noch kein Bild hochgeladen',
408        no_followers_loc: 'Keine Followers',
409        hide_block_loc: 'Block ausblenden',
410        show_block_loc: 'Block anzeigen',
411        res_contest_loc: 'Fotowettbewerb Gewinner',
412        sort_rating_loc: 'Nach Rating sortieren',
413        all_works_contest_loc: 'Alle Wettbewerbsbilder',
414        vote_accept_short_loc: 'Ihre Stimme<br>wurde gezählt',
415        answer_loc: 'Antworten',
416        informative_loc: 'Aussagekräftig',
417        in_portfolio_loc: 'ins Portfolio',
418        in_portfolio_note_loc: 'ins Portfolio',
419        add_work1_loc: 'Bild',
420        add_work2_loc: 'hochladen',
421        drop_upload_loc: 'Dateien per "Drag & Drop" hochladen',
422        in_gall_loc: 'in die Galerie',
423        in_gall_note_loc: 'Hochladen in die öffentliche Galerie für Bewertungen von anderen Autoren',
424        crop_var_loc: 'Crop',
425        mobile_ver_loc: 'Mobile Version',
426        click_choose_city_loc: 'Klicken Sie hier, um Ihren Wohnsitz auszuwählen',
427        choose_city_loc: 'Bitte wählen Sie Ihre Stadt',
428        select_region_loc: 'Wählen Sie bitte Ihre Region aus',
429        voter_for_meaning_loc: 'Stimmen für diese Anmerkung',
430        appeal_loc: 'Beschweren',
431        why_appeal_loc: 'Sagen Sie bitte uns Ihre Beschwerde zur Anmerkung: #',
432        appeal_ok_loc: 'Danke, Ihre Beschwerde wurde erfolgreich gesendet',
433        show_all_comm_loc: 'Alle Anmerkungen anzeigen',
434        goto_photo_page_loc: 'Zur Bildseite',
435        add_comm_loc: 'Anmerkung hinzufügen',
436        comm_added_loc: 'Anmerkung wurde hinzugefügt',
437        all_views_loc: 'Alle Aufrufe',
438        all_recs_loc: 'Alle Empfehlungen',
439        ban_author_loc: 'Sperren Autor',
440        unban_author_loc: 'Entsperren Autor'
441    },
442    ru: {
443        ed_license_label_loc: 'Лицензия editorial',
444        comm_license_label_loc: 'Лицензия commercial',
445        fee_loc: '%',
446        stock_photo_loc: 'M',
447        art_photo_loc: 'G',
448        l_for_sale_loc: 'Продается',
449        all_photos_loc: 'Все фото',
450        art_photos_loc: 'Галерея',
451        stock_photos_loc: 'Маркетплейс',
452        images_loc: '',
453        get_follow: 'Подписаться',
454        already_rec_note_loc: 'Спасибо, ваша<br>рекомендация принята',
455        edit_comm_loc: 'Редактировать сообщение',
456        cancel_loc: 'Отменить',
457        upload_failed_loc: 'Ошибка, файл должен быть меньше 12Мб',
458        save_comm_loc: 'Сохранить сообщение',
459        edit_loc: 'Редактировать',
460        serie_loc: 'Серия',
461        place_loc: 'место',
462        photo_contest_loc: 'Фотоконкурс',
463        oncomp_let_loc: 'К',
464        work_of_day_loc: 'Работа дня',
465        workofday_let_loc: 'РД',
466        for_critique_loc: 'Работа для критики',
467        for_critique_let_loc: 'Критика',
468        till_loc: 'до',
469        rating_loc: 'Рейтинг',
470        aver_mark_loc: 'Средняя оценка',
471        rec_loc: 'Рекомендации',
472        add_rec_loc: 'Рекомендовать',
473        comments_loc: 'Обсуждение',
474        to_first_page_loc: 'К первой странице обсуждения',
475        do_want_del_comm_loc: 'Вы действительно хотите удалить это сообщение?',
476        del_loc: 'Удалить',
477        sel_citation_loc: 'Цитата выделенного',
478        from_loc: 'от',
479        click_to_paste_name_loc: 'Нажмите, для того, чтобы вставить имя автора в сообщение',
480        best_work_loc: 'Лучшие работы',
481        last_works_loc: 'Последние работы',
482        auth_profile_loc: 'Профиль автора',
483        thankyou_mark_loc: 'Спасибо, ваша оценка принята',
484        be_constructive_loc: 'Текст сообщения должен содержать хотя бы ' + minCommLen + ' букв',
485        max_comm_len_loc: 'Сообщение должно содержать не более ' + maxCommLen + ' символов',
486        vote_accept_loc: 'Спасибо, ваш голос принят',
487        no_works_loc: 'Извините, но тут не найдено никаких работ',
488        no_auth_works_loc: 'Автор пока не добавил ни одной работы',
489        no_followers_loc: 'У автора пока нет ни одного подписчика',
490        hide_block_loc: 'Свернуть блок',
491        show_block_loc: 'Развернуть блок',
492        res_contest_loc: 'Результаты конкурса',
493        sort_rating_loc: 'Сортировать по рейтингу',
494        all_works_contest_loc: 'Все работы конкурса',
495        vote_accept_short_loc: 'Ваш голос<br>принят',
496        answer_loc: 'Ответить',
497        informative_loc: 'Содержательно',
498        in_portfolio_loc: 'в портфолио',
499        in_portfolio_note_loc: 'в портфолио',
500        add_work1_loc: 'Добавить работу',
501        add_work2_loc: '',
502        drop_upload_loc: 'Перетащите сюда файл<br>для загрузки в потфолио',
503        in_gall_loc: 'в галерею',
504        in_gall_note_loc: 'Загрузка в публичную галерею для оценки другими пользователями',
505        crop_var_loc: 'Вариант кадрирования',
506        mobile_ver_loc: 'Мобильная версия',
507        click_choose_city_loc: 'Кликните, чтобы выбрать город',
508        choose_city_loc: 'Выберите город',
509        select_region_loc: 'Выберите регион',
510        voter_for_meaning_loc: 'Голоса за содержательность',
511        appeal_loc: 'Пожаловаться',
512        why_appeal_loc: 'Укажите причину жалобы на сообщение: #',
513        appeal_ok_loc: 'Спасибо, ваша жалоба была успешно отправлена',
514        show_all_comm_loc: 'Показать все сообщения',
515        goto_photo_page_loc: 'Перейти на страницу фото',
516        add_comm_loc: 'Добавить сообщение',
517        comm_added_loc: 'Сообщение добавлено',
518        all_views_loc: 'Все просмотры',
519        all_recs_loc: 'Все рекомендации',
520        ban_author_loc: 'Заблокировать автора',
521        unban_author_loc: 'Разблокировать автора'
522    }
523};
524var $lang = cookie.getCookie("lang");
525if ("" == $lang || "undefined" == $lang)
526    $lang = getBrowserLang();
527ploc = "by" == $lang ? ploc.by : "com" == $lang ? ploc.com : "de" == $lang ? ploc.de : ploc.ru;
528
529/* --------------------------------------------------------------------------- */
530/* Default JS, PhotoCentra */
531
532/* --------------------------------------------------------------------------- */
533function getMood(auth_mood) {
534    $.get(ajaxFld + "get_mood.php", {
535        auth_mood: auth_mood
536    }, function() {
537        NProgress.done();
538        var moodTxt = $("#moodTxt");
539        moodTxt.html(auth_mood + ' <i class="editIconMy">&#xe906;</i>');
540        moodTxt.show();
541    });
542}
543
544function setGallWidth($wrapDiv) {
545    var $gallWidth = parseInt($wrapDiv.innerWidth());
546    var $divCnt = Math.floor($gallWidth / $divWidthDef);
547    var $divWidth = Math.ceil($gallWidth / $divCnt) - 3;
548    $(".imgBoxDiv", $wrapDiv).css("width", $divWidth + "px");
549    if ($wrapDiv.selector == '#wrapCouncilRec')
550        for (var $i = $divCnt + 1; $i <= 7; $i++)
551            $($("#councilRec" + $i), $wrapCouncilRec).hide();
552}
553
554function getBookmark(id, id_parent, bookmark, comm_cnt, type) {
555    var addBookmarkAjax = $("#addBookmarkAjax");
556    var previewBookmark = $("#previewBookmark");
557    addBookmarkAjax.html(loaderGall);
558    previewBookmark.html(loaderGall);
559    $.get(ajaxFld + "get_bookmark.php", {
560        id: id,
561        id_parent: id_parent,
562        bookmark: bookmark,
563        comm_cnt: comm_cnt,
564        type: type
565    }, function(data) {
566        NProgress.done();
567        addBookmarkAjax.html(data);
568        previewBookmark.html(data);
569    });
570}
571
572
573function addToGallery(el) {
574
575    let idphoto = $(el).data('idphoto');
576    let galid = $(el).data('galid');
577
578    $.get(ajaxFld + "add_to_gallery.php", {
579        idphoto: idphoto,
580        galid: galid
581
582    }, function(success) {
583        if(success == 1) { 
584
585            let remGallWork = $("#remGallWork"+galid);
586            let remGall = $("#remGall"+galid);
587
588            if(remGall) remGall.show();
589
590            if(remGallWork) remGallWork.show();
591        }
592    });
593}
594
595
596function remFromGallery(el) {
597
598    let idphoto = $(el).data('idphoto');
599    let galid = $(el).data('galid');
600
601    $.get(ajaxFld + "add_to_gallery.php", {
602        idphoto: idphoto,
603        galid: galid,
604        remove: 1
605
606    }, function(success) {
607        if(success == 1) $(el).hide();
608    });
609}
610
611
612
613
614function getFavor(id, id_parent, favor, comm_cnt, type) {
615    var addFavorAjax = $("#addFavorAjax");
616    var previewFavor = $("#previewFavor");
617    addFavorAjax.html(loaderGall);
618    previewFavor.html(loaderGall);
619    $.get(ajaxFld + "get_favor.php", {
620        id: id,
621        id_parent: id_parent,
622        favor: favor,
623        comm_cnt: comm_cnt,
624        type: type
625    }, function(data) {
626        NProgress.done();
627        addFavorAjax.html(data);
628        previewFavor.html(data);
629    });
630}
631
632function getFineart(id, fineart, type) {
633    var $fineart = $("#previewFineart");
634    if (type == "full")
635        $fineart = $("#addFineartAjax");
636    $fineart.html('&nbsp;');
637    $.get(ajaxFld + "get_fineart.php", {
638        id: id,
639        fineart: fineart,
640        type: type
641    }, function(data) {
642        NProgress.done();
643        $fineart.html(data);
644    });
645}
646
647function getHowDone(id, id_parent) {
648    var howDone = $("#howDone");
649    var isUp = false;
650    setTimeout(function() {
651        if (!isUp)
652            howDone.html(loaderGall);
653    }, 500);
654    $.get(ajaxFld + "get_how_done.php", {
655        id: id,
656        id_parent: id_parent
657    }, function(data) {
658        NProgress.done();
659        isUp = false;
660        howDone.html(data);
661    });
662}
663
664function getWaiter(id) {
665    var waiter = $("#waiter");
666    var isUp = false;
667    setTimeout(function() {
668        if (!isUp)
669            waiter.html(loaderGall);
670    }, 500);
671    $.get(ajaxFld + "get_waiter.php", {
672        id: id
673    }, function(data) {
674        NProgress.done();
675        isUp = true;
676        waiter.html(data);
677    });
678}
679
680function getFriend(id, friend) {
681    var addFriend = $("#addFriend");
682    addFriend.html('&nbsp;');
683    $.get(ajaxFld + "get_friend.php", {
684        id: id,
685        friend: friend
686    }, function(data) {
687        NProgress.done();
688        addFriend.html(data);
689    });
690}
691
692function getBannedFromComm(id, banned, comm_nr) {
693    var banAuthor = $("#aBan" + comm_nr);
694    banAuthor.css({
695        visibility: "hidden"
696    });
697    $.get(ajaxFld + "get_banned.php", {
698        id: id,
699        banned: banned
700    }, function(data) {
701        NProgress.done();
702        var html = '<a href="#" onclick="getBannedFromComm(' + id + ', 1, ' + comm_nr + '); return false;" class="delCommA"><i class="about_icon about_icon_popup">&#xe826;</i>' + ploc.ban_author_loc + '</a>';
703        if (banned)
704            html = '<a href="#" onclick="getBannedFromComm(' + id + ', 0, ' + comm_nr + '); return false;" class="delCommA"><i class="about_icon about_icon_popup">&#xe826;</i>' + ploc.unban_author_loc + '</a>';
705        banAuthor.html(html).css({
706            visibility: "visible"
707        });
708    });
709}
710
711function getBanned(id, banned) {
712    var banAuthor = $("#banAuthor");
713    banAuthor.html('&nbsp;');
714    $.get(ajaxFld + "get_banned.php", {
715        id: id,
716        banned: banned
717    }, function(data) {
718        NProgress.done();
719        banAuthor.html(data);
720    });
721}
722
723function getPageStatus(page, la, status) {
724    $.get(ajaxFld + "get_page_status.php", {
725        page: page,
726        la: la,
727        status: status
728    }, function(data) {
729        NProgress.done();
730    });
731}
732
733function getViews(id, cnt, id_auth_photo) {
734    $.get(ajaxFld + "get_views.php", {
735        id: id,
736        cnt: cnt,
737        id_auth_photo: id_auth_photo
738    }, function(data) {
739        NProgress.done();
740        $("#viewsAjax").html(data);
741        if (isMobVer) {
742            $("#viewsAjax").html('<b>' + $("#viewCnt").text() + '</b> <a href="/views.php?id_photo=' + id + '" target="_blank"><b>' + ploc.all_views_loc + '</b></a>');
743            $("#recsAjax").html('<b>' + $("#recCnt").text() + '</b> <a href="/recs.php?id_photo=' + id + '" target="_blank"><b>' + ploc.all_recs_loc + '</b></a>');
744        }
745    });
746}
747
748function getHomeAlbum(id_photo, is_vote) {
749    var $addRecAjax = $("#addRecAjax");
750    var isUp = false;
751    if (is_vote == 1) {
752        setTimeout(function() {
753            if (!isUp)
754                $addRecAjax.html(loaderGall);
755        }, 500);
756    }
757    $.get(ajaxFld + "get_home_album.php", {
758        id_photo: id_photo,
759        is_vote: is_vote
760    }, function(data) {
761        NProgress.done();
762        isUp = true;
763        if (data != '') {
764            $addRecAjax.html(data);
765            $("#homeAlbum").hide();
766        }
767    });
768}
769
770function recFromPreviewFunction(element) {
771
772    var $idPhotoData = $(element).find('#recFromPreview').data('id-photo');
773    var $imgAuthor = $(element).find('#recFromPreview').data('id-author');
774
775    if (document.getElementById('loginAvatar') !== null) {
776        var $idAuthor = $('#loginAvatar').data('id-auth');
777    } else {
778        var $idAuthor = $('#loginAvatarMin').data('id-auth');
779    }
780
781    if ($imgAuthor != $idAuthor) {
782
783        //storeRecsArray($idPhotoData);
784
785        //log('idphoto='+$idPhotoData,'authId='+$idAuthor);
786
787        $.get(ajaxFld + "get_recs.php", {
788            id_photo: $idPhotoData
789        }, function(data) {
790            NProgress.done();
791
792            var $ratingNum = $('#ratingNum' + $idPhotoData);
793            var $oldRate = $ratingNum.attr('data-ph-rating');
794
795            //log('data=', data);
796            if (data != 0) {
797                $ratingNum.text(roundExt((parseFloat($oldRate) + parseFloat(data)), 2));
798
799                var $ratingIcon = $("#ratingIcon" + $idPhotoData);
800                $ratingIcon.html('&#xe934;');
801            }
802
803        });
804    }
805}
806
807function getRecs(id_photo, id_auth, auth_name) {
808    $("#recWithCTbl").hide();
809    var $addRecAjax = $("#addRecAjax");
810    var $previewRec = $("#previewRec");
811
812    //storeRecsArray(id_photo);
813
814    if ($previewRec.has('a').length > 0) {
815
816        $previewRec.html('<div style="padding-top: 6px;"><span class="iconRating" style="top: 0px;margin-left: 40px;">&#xe908;</span><div style="display:inline-block">' + ploc.already_rec_note_loc + '</div></div>');
817        var isUp = false;
818
819        var $oldRate = $previewRec.attr('data-ph-rating');
820
821        setTimeout(function() {
822            if (!isUp)
823                $previewRec.html('<div class="skeletSmall skAnimation"><div class="smallBlock"></div></div><div class="skeletBig skAnimation" style="margin-top: 4px;"></div>');
824        }, 1000);
825
826        $.get(ajaxFld + "get_recs.php", {
827            id_photo: id_photo
828        }, function(data) {
829            NProgress.done();
830            isUp = true;
831
832            $previewRec.html('<div style="font-size: 15px; font-weight: 700; padding-top: 5px;"><span class="iconRating">&#xe908;</span>' + ploc.rating_loc + ':&nbsp;&nbsp;' + roundExt((parseFloat($oldRate) + parseFloat(data)), 2) + '</div>').addClass("animated bounceIn");
833
834            setTimeout(function() {
835                $previewRec.removeClass("animated bounceIn");
836            }, 1000);
837
838            /*
839            var $recsAjax = $("#recsAjax");
840            var $old = $recsAjax.html();
841            if ($old) {
842                $old = $old.substr(0, $old.length - 1);
843                $recsAjax.html($old + " <a href=\"/author.php?id_auth=" + id_auth + "\">" + auth_name + "</a>");
844            }
845            */
846        });
847
848    } else {
849
850        $addRecAjax.html('<div style="padding-top: 6px;"><span class="iconRating" style="top: 0px;margin-left: 40px;">&#xe908;</span><div style="display:inline-block">' + ploc.already_rec_note_loc + '</div></div>');
851
852        var $oldRate = $addRecAjax.attr('data-ph-rating');
853        var isUp = false;
854
855        setTimeout(function() {
856            if (!isUp)
857                $addRecAjax.html('<div class="skeletSmall skAnimation"><div class="smallBlock"></div></div><div class="skeletBig skAnimation" style="margin-top: 4px;"></div>');
858        }, 1000);
859
860        $.get(ajaxFld + "get_recs.php", {
861            id_photo: id_photo
862        }, function(data) {
863            NProgress.done();
864            isUp = true;
865
866            $addRecAjax.html('<span class="recDone">' + ploc.rating_loc + ': ' + roundExt((parseFloat($oldRate) + parseFloat(data)), 2) + '</span>').addClass("animated bounceIn");
867
868            var $recCnt = $("#recCnt");
869            $recCnt.text(parseInt($recCnt.text()) + 1);
870            var $recsAjax = $("#recsAjax");
871            var $old = $recsAjax.html();
872            if ($old) {
873                $old = $old.substr(0, $old.length - 1);
874                $recsAjax.html($old + " <a href=\"/author.php?id_auth=" + id_auth + "\">" + auth_name + "</a>");
875            }
876        });
877
878    }
879
880}
881
882function getAuthWorks(id_auth, comm_nr, order, lim) {
883    var authWorksTd = $("#authWorks" + comm_nr);
884
885    if (lim !== undefined) {
886        var limit = lim;
887    } else {
888        var limit = 3; //Math.floor((authWorksTd.innerWidth()) / $divWidthDef);
889    }
890
891    if (!authWorksTd.hasClass('authWorksPadding'))
892        authWorksTd.addClass('authWorksPadding').html(loaderGall);
893
894    $.get(ajaxFld + "get_auth_works.php", {
895        id_auth: id_auth,
896        order: order,
897        limit: limit
898    }, function(data) {
899        NProgress.done();
900        authWorksTd.html(data);
901        updateIeNudeThumbs(authWorksTd);
902    });
903}
904
905function editComm(id, comm_nr, type) {
906    var $cT = $("#commText" + comm_nr);
907    var comm_text = $cT.html().replace(/[\n]/g, '[BR]');
908    comm_text = comm_text.replace(/[\r\t]/g, '');
909    comm_text = comm_text.replace(/\'/g, '[SQ]');
910    comm_text = comm_text.replace(/\"/g, '[DQ]');
911    //$("#aEdit" + comm_nr).html('<a href="#" onclick="cancelComm(' + id + ',' + comm_nr + ',\'' + comm_text + '\',\'' + type + '\'); return false;" title="' + ploc.edit_comm_loc + '" class="editCommA">' + ploc.cancel_loc + ' <i class="about_icon about_icon_popup">&#xe813;</i></a>');
912    $.get(ajaxFld + "get_comm.php", {
913        id: id,
914        type: type
915    }, function(data) {
916        NProgress.done();
917        html = '<textarea class="txtArea" onfocus="isCommentFocus=true;" onblur="isCommentFocus=false;" id="commTextA' + comm_nr + '" name="comm_text" style="width: 852px; height: 140px;">' + data + '</textarea>';
918        html += '<div class="addCommBtn">';
919        html += '<a class="saveBtn cancelBtn" onclick="cancelComm(' + id + ',' + comm_nr + ',\'' + comm_text + '\',\'' + type + '\'); return false;" style="margin-right: 6px;">' + ploc.cancel_loc + '</a>';
920        html += '<a class="saveBtn" onclick="updateComm(' + id + ',' + comm_nr + ',\'' + type + '\'); return false;">' + ploc.save_comm_loc + '</a>';
921        html += '</div>';
922        $cT.html(html);
923    });
924}
925
926function editCommPopup(id, comm_nr, type) {
927    var $cT = $("#spanCommText" + comm_nr);
928    var comm_text = $cT.html().replace(/[\n]/g, '[BR]');
929    comm_text = comm_text.replace(/[\r\t]/g, '');
930    comm_text = comm_text.replace(/\'/g, '[SQ]');
931    comm_text = comm_text.replace(/\"/g, '[DQ]');
932    //$("#aEdit" + comm_nr).html('<a href="#" onclick="cancelCommPopup(' + id + ',' + comm_nr + ',\'' + comm_text + '\',\'' + type + '\'); return false;" title="' + ploc.edit_comm_loc + '" class="editCommA"><i class="about_icon about_icon_popup">&#xe813;</i>' + ploc.cancel_loc + '</a>');
933    $.get(ajaxFld + "get_comm.php", {
934        id: id,
935        type: type
936    }, function(data) {
937        NProgress.done();
938        var html = '<textarea class="txtArea" onfocus="isCommentFocus=true;" onblur="isCommentFocus=false;" id="commTextA' + comm_nr + '" name="comm_text" style="width: 535px; height:140px;">' + data + '</textarea>';
939        html += '<div class="addCommBtn">';
940        html += '<a class="saveBtn cancelBtn" onclick="cancelCommPopup(' + id + ',' + comm_nr + ',\'' + comm_text + '\',\'' + type + '\'); return false;" style="margin-right: 6px;">' + ploc.cancel_loc + '</a>';
941        html += '<a class="saveBtn" onclick="updateCommPopup(' + id + ',' + comm_nr + ',\'' + type + '\'); return false;">' + ploc.save_comm_loc + '</a>';
942        html += '</div>';
943        $cT.html(html);
944    });
945}
946
947function cancelComm(id, comm_nr, comm_text, type) {
948    comm_text = comm_text.replace(/\[BR\]/g, '\n');
949    comm_text = comm_text.replace(/\[SQ\]/g, '\'');
950    comm_text = comm_text.replace(/\[DQ\]/g, '\"');
951    if (comm_text != '')
952        $("#commText" + comm_nr).html(comm_text);
953    //$("#aEdit" + comm_nr).html('<a href="#" onclick="editCommPopup(' + id + ',' + comm_nr + ',\'' + type + '\'); return false;" title="' + ploc.edit_comm_loc + '" class="editCommA">' + ploc.edit_comm_loc + ' <i class="about_icon">&#xe813;</i></a></a>');
954}
955
956function cancelCommPopup(id, comm_nr, comm_text, type) {
957    comm_text = comm_text.replace(/\[BR\]/g, '\n');
958    comm_text = comm_text.replace(/\[SQ\]/g, '\'');
959    comm_text = comm_text.replace(/\[DQ\]/g, '\"');
960    if (comm_text != '')
961        $("#spanCommText" + comm_nr).html(comm_text);
962    //$("#aEdit" + comm_nr).html('<a href="#" onclick="editCommPopup(' + id + ',' + comm_nr + ',\'' + type + '\'); return false;" title="' + ploc.edit_comm_loc + '" class="editCommA">' + ploc.edit_comm_loc + ' <i class="about_icon">&#xe813;</i></a></a>');
963}
964
965function updateComm(id, comm_nr, type) {
966    var comm_text = $("#commTextA" + comm_nr).val();
967    var trimmed_comm = trimComm(comm_text);
968    if (trimmed_comm.length < minCommLen) {
969        alert(ploc.be_constructive_loc);
970        getEl('comment').focus();
971        return false;
972    }
973    cancelComm(id, comm_nr, '', type);
974    $.post(ajaxFld + "post_update_comm.php", {
975        id: id,
976        comm_text: comm_text,
977        type: type
978    }, function(data) {
979        NProgress.done();
980        if (type == 'blog')
981            $("#commText" + comm_nr).html('<div id="tdCommText' + comm_nr + '" itemprop="commentText">' + data.replace(/\#(\d{1,2})/g, '<a onclick="crop_nr=' + comm_nr + '; window.location.hash=\'#i$1\'; \$(\'#crop_down\').show(); return false;" href="#">#$1</a>') + '</div>');
982        else
983            $("#commText" + comm_nr).html('<div id="tdCommText' + comm_nr + '" itemprop="commentText">' + data.replace(/\#(\d{1,2})/g, '<a onclick="crop_nr=' + comm_nr + '; window.location.hash=\'#i$1\'; \$(\'#crop_down\').show(); return false;" href="#">#$1</a>') + '</div>');
984        $("#commText" + comm_nr).find('.commQuotePopup').removeClass('commQuotePopup').addClass('commQuote');
985
986        if (typeof twemoji !== 'undefined')
987            twemoji.parse(document.body, { folder: 'svg', ext: '.svg' });
988    });
989}
990
991function updateCommPopup(id, comm_nr, type) {
992    var comm_text = $("#commTextA" + comm_nr).val();
993
994    var trimmed_comm = trimComm(comm_text);
995    if (trimmed_comm.length < minCommLen) {
996        alert(ploc.be_constructive_loc);
997        getEl('comment').focus();
998        return false;
999    }
1000    cancelCommPopup(id, comm_nr, comm_text, type);
1001    $.post(ajaxFld + "post_update_comm.php", {
1002        id: id,
1003        comm_text: comm_text,
1004        type: type
1005    }, function(data) {
1006        NProgress.done();
1007        if (type == 'blog')
1008            $("#spanCommText" + comm_nr).html('<div id="tdCommText' + comm_nr + '" itemprop="commentText">' + data.replace(/\#(\d{1,2})/g, '<a onclick="crop_nr=' + comm_nr + '; window.location.hash=\'#i$1\'; \$(\'#crop_down\').show(); return false;" href="#">#$1</a>') + '</div>');
1009        else
1010            $("#spanCommText" + comm_nr).html('<div id="tdCommText' + comm_nr + '" itemprop="commentText">' + data.replace(/\#(\d{1,2})/g, '<a onclick="crop_nr=' + comm_nr + '; window.location.hash=\'#i$1\'; \$(\'#crop_down\').show(); return false;" href="#">#$1</a>') + '</div>');
1011        $("#spanCommText" + comm_nr).find('.commQuote').removeClass('commQuote').addClass('commQuotePopup');
1012
1013        if (typeof twemoji !== 'undefined')
1014            twemoji.parse(document.body, { folder: 'svg', ext: '.svg' });
1015    });
1016}
1017
1018function deleteComm(id, id_parent, comm_nr, type) {
1019    $.get(ajaxFld + "get_delete_comm.php", {
1020        id: id,
1021        id_parent: id_parent,
1022        type: type
1023    }, function(data) {
1024        NProgress.done();
1025
1026        if (isOverlay)
1027            $("#spanCommText" + comm_nr).html(data);
1028        else
1029            $("#commText" + comm_nr).html(data);
1030    });
1031}
1032
1033function appealComm(id, id_parent, comm_nr, type) {
1034    var appeal = prompt(ploc.why_appeal_loc + comm_nr);
1035    if (appeal) {
1036        $.get(ajaxFld + "get_delete_comm.php", {
1037            id: id,
1038            id_parent: id_parent,
1039            comm_nr: comm_nr,
1040            type: type,
1041            appeal: appeal
1042        }, function(data) {
1043            NProgress.done();
1044            alert(ploc.appeal_ok_loc);
1045        });
1046    }
1047}
1048
1049function getFollow(id, act, type, page, idphoto) {
1050    if (type === 'work')
1051        var getFollow = $("#getFollowWork");
1052    else {
1053        var getFollow = $("#getFollow");
1054        var getFollow2 = $("#getFollow2");
1055        var getFollowFromPreview = $("#getFollow" + id + idphoto);
1056    }
1057    var isUp = false;
1058    setTimeout(function() {
1059        if (!isUp) {
1060            getFollow.html(loaderGall);
1061            getFollow2.html(loaderGall);
1062        }
1063    }, 500);
1064    $.get(ajaxFld + "get_follow.php", {
1065        id: id,
1066        act: act,
1067        type: type,
1068        page: page,
1069        idphoto: idphoto
1070    }, function(data) {
1071        NProgress.done();
1072        isUp = true;
1073        getFollow.html(data);
1074        getFollow2.html(data);
1075        getFollowFromPreview.html(data);
1076    });
1077}
1078
1079function getBlogStatus(id_blog, blog_title, blog_status) {
1080    $.get(ajaxFld + "get_blog_status.php", {
1081        id_blog: id_blog,
1082        blog_title: blog_title,
1083        blog_status: blog_status
1084    }, function(data) {
1085        NProgress.done();
1086        if (blog_status == 1) {
1087            $("#blogTitle" + id_blog).attr('class', '');
1088            $("#blogStatus" + id_blog).html(data).attr('class', 'hideBtn');
1089        } else {
1090            $("#blogTitle" + id_blog).attr('class', 'blogUnpublishA');
1091            $("#blogStatus" + id_blog).html(data).attr('class', 'plusBtn');
1092        }
1093    });
1094}
1095
1096// function updateQuoteHover(el) {
1097//     var qMaxHeight = '54px';
1098//     if (isOverlay)
1099//         qMaxHeight = '46px';
1100//     el.find(".commQuote").each(function() {
1101//         if ($(this)[0].scrollHeight > $(this).innerHeight()) {
1102//             $(this).click(function() {
1103//                 $(this).css({
1104//                     'max-height': 'none'
1105//                 });
1106
1107//             }, function() {
1108//                 $(this).css({
1109//                     'max-height': ''
1110//                 });
1111//             });
1112//         }
1113//     });
1114//     el.find(".commQuotePopup").each(function() {
1115//         if ($(this)[0].scrollHeight > $(this).innerHeight()) {
1116//             $(this).hover(function() {
1117//                 $(this).css({
1118//                     'max-height': 'none'
1119//                 });
1120//             }, function() {
1121//                 $(this).css({
1122//                     'max-height': ''
1123//                 });
1124//             });
1125//         }
1126//     });
1127// }
1128
1129function updateQuoteHover(el) {
1130    var qMaxHeight = '54px';
1131    if (isOverlay)
1132        qMaxHeight = '46px';
1133
1134    el.find(".commQuote, .commQuotePopup").each(function() {
1135
1136        $(this).on('click', function() {
1137
1138            if (!$(this).hasClass('quoteOpen2')) {
1139                $(this).addClass('quoteOpen2');
1140
1141            } else {
1142
1143                $(this).removeClass('quoteOpen2');
1144
1145            }
1146
1147        });
1148
1149    });
1150
1151}
1152
1153var isLoadingGall = false;
1154var isLoadingPopup = false;
1155var isScrollPopup = true;
1156var imgPos = 0;
1157var imgCurId = 0;
1158var imgArr = {};
1159
1160//var resizedElements = [];
1161
1162function getAuthMaxRowHeight() {
1163    var t;
1164    if (window.innerWidth >= 1850)
1165        t = 5.4;
1166    else
1167        t = 4.4;
1168
1169    var maxRH = Math.round(window.innerWidth / t);
1170
1171    // return maxRH;
1172}
1173
1174function getRowHeight(rowHeight) {
1175
1176    //var heightRatio = 2.53;
1177    //if (isSquareGall)
1178    //heightRatio = 3.93;
1179    //rowHeight = Math.round(window.innerHeight / heightRatio);
1180
1181    var widthRatio = 6.2;
1182    if (isSquareGall)
1183        widthRatio = 3.93;
1184
1185    var maxRowHeight = getAuthMaxRowHeight();
1186    var minRowHeight = 250;
1187
1188    if (window.innerWidth >= 1850) widthRatio = 7;
1189
1190    rowHeight = Math.round(window.innerWidth / widthRatio);
1191
1192    if (isSquareGall)
1193        maxRowHeight = 290;
1194
1195    if (window.innerWidth <= $ipadWndW && window.innerWidth <= window.innerHeight)
1196        maxRowHeight = minRowHeight;
1197
1198    if (rowHeight > maxRowHeight)
1199        rowHeight = maxRowHeight;
1200    else if (rowHeight < minRowHeight)
1201        rowHeight = minRowHeight;
1202
1203    //return rowHeight;
1204
1205}
1206
1207function resizeToEqualHeight($gallery, isOneRow, rowHeight, maxRowHeightInput, marginsInput, authorProfile) {
1208
1209    fdSwitch();
1210
1211    var lastRow = 'hide';
1212    if (isOneRow || authorProfile)
1213        lastRow = 'nojustify';
1214    else if (typeof isLastPage !== 'undefined' && parseInt(isLastPage) === 1)
1215        lastRow = 'nojustify';
1216
1217    var maxRowHeight = 360;
1218    if (!isSquareGall) {
1219        maxRowHeight = getAuthMaxRowHeight(); //maxRowHeight = 360;
1220        if (isOneRow)
1221            maxRowHeight = '100%';
1222    }
1223
1224    //log('rowHeight', rowHeight); 
1225    //if (typeof rowHeight === 'undefined' || rowHeight === 'undefined')
1226    //rowHeight = getRowHeight(rowHeight);
1227    //log('rowHeight', rowHeight);
1228
1229    if (typeof maxRowHeightInput != 'undefined')
1230        maxRowHeight = maxRowHeightInput;
1231
1232    if (typeof authorProfile != 'undefined')
1233        var aProfile = authorProfile;
1234
1235    var Borders = 5,
1236        Margins = 11;
1237    if (typeof marginsInput != 'undefined')
1238        Margins = marginsInput;
1239    //if (window.innerWidth >= 1850) { Borders = 5; Margins = 8; } else { Borders = 4; Margins = 8; }
1240
1241    $gallery.justifiedGallery({
1242        isSquareGall: isSquareGall,
1243        isOneRow: isOneRow,
1244        rowHeight: rowHeight,
1245        maxRowHeight: maxRowHeight,
1246        lastRow: lastRow,
1247        border: Borders,
1248        margins: Margins,
1249        captions: false,
1250        waitThumbnailsLoad: false,
1251        cssAnimation: false,
1252        imagesAnimationDuration: 0,
1253        refreshSensitivity: 50,
1254        refreshTime: 0,
1255        aProfile: aProfile
1256    });
1257
1258    if (!isOneRow) {
1259        var wantedLastRowValue = 'nojustify';
1260        var controller = $gallery.data('jmessageDotsg.controller');
1261
1262        function checkIfSingleRowIsJustified() {
1263            if (typeof controller !== 'undefined' && controller.rows === 0 && controller.settings.lastRow !== wantedLastRowValue)
1264                $gallery.justifiedGallery({
1265                    lastRow: wantedLastRowValue
1266                });
1267
1268        }
1269
1270        setTimeout(function() {
1271            $gallery.justifiedGallery().on('jg.complete jg.resize', checkIfSingleRowIsJustified);
1272        }, 10);
1273    } else {
1274        //log(isOneRow, rowHeight);
1275    }
1276}
1277
1278if (typeof isInfinite === "undefined")
1279    isInfinite = false;
1280
1281function buildGall(hash, j, isInfinite) {
1282    if (typeof isInfinite === "undefined")
1283        isInfinite = false;
1284
1285    var params = '';
1286
1287    var $gall_photos = '';
1288    if (!isInfinite) {
1289        $gall_photos += '<div class="imgBoxWrap" style="overflow: hidden; white-space: nowrap;">'
1290    }
1291
1292    var jLen = j.length;
1293
1294    //log('isInfinite', isInfinite, 'Object.keys(imgArr).length', Object.keys(imgArr).length);
1295
1296    var pos = Object.keys(imgArr).length - 1;
1297
1298    for (var i = 0; i < jLen; i++) {
1299        pos++;         
1300
1301        var isCacheImage = false;
1302        if (i == 0)
1303            isCacheImage = true;
1304
1305        initImgArr(j[i].ip, pos, j[i].iu, j[i].pmw, j[i].pmh, j[i].pn, j[i].ian, isCacheImage);
1306
1307        var blurClass = '';
1308        var thumbBg = 'background-image: url(' + j[i].iu + ');';
1309
1310        if (j[i].ib == 0) {
1311            blurClass = ' blurThumb';
1312            if (isIE && getIEVer() >= 10)
1313                thumbBg = 'background: ' + bgColor + ' url(css/' + theme + '/nu.png) no-repeat 50% 50%/cover;';
1314        }
1315
1316        var noBgStyle = "";
1317        var maxW = "calc(100% - 105px)";
1318        if (j[i].cc < 1) {
1319            noBgStyle = ' style="background: none;"';
1320            maxW = "calc(100% - 55px)";
1321        }
1322
1323        if (j[i].ia == -1) {
1324            var auth_name_photo = '<div class="small_portrait" style="background-image: url(/css/black/male_cover.png);"></div><span class="tickCatNew workAnon">' + j[i].an + ' (' + ploc.till_loc + ' ';
1325            auth_name_photo += j[i].pda;
1326            auth_name_photo += ')</span>';
1327        } else {
1328            if (j[i].ap != '') {
1329                var tmp = j[i].ap;
1330                var tmp2 = j[i].ap2;
1331            } else {
1332                var tmp = '';
1333                var tmp2 = '';
1334            }
1335
1336            var auth_name_photo = '<div id="idAuth' + j[i].ip + '" class="aTtip beforeLeft"><div id="authWorks' + j[i].ip + '"></div><div class="aTtipPos"><a class="aTtipLink" href="/author.php?id_auth=' + j[i].ia + '"><div class="ttPortrait" style="background-image: url(' + j[i].av + ');"></div><div class="ttName">' + j[i].an + tmp2 + '</div></a><div class="ttMood">' + j[i].am + '</div><span id="getFollow' + j[i].ia + j[i].ip + '" class="previewFollow"><a class="saveBtn followBtn" onclick="getFollow(' + j[i].ia + ', 1, \'auth\',\'\',' + j[i].ip + ')">' + ploc.get_follow + '</a></span><span class="getAuthWorksLnk"><a onclick="getAuthWorks(' + j[i].ia + ', ' + j[i].ip + ', 0, 3);return false;" href="#">' + ploc.last_works_loc + '</a><br><a onclick="getAuthWorks(' + j[i].ia + ', ' + j[i].ip + ', 1, 3);return false;" href="#">' + ploc.best_work_loc + '</a></span><div class="authTtipStat"><div class="attsLine"><div class="attsRoundBg"><span class="attsRatingIcon">&#xe934;</span></div><div class="attsText">' + j[i].ar + '</div></div><div class="attsLine"><div class="attsRoundBg"><span class="attsPhotosIcon">&#xe902;</span></div><div class="attsText">' + j[i].aic + '</div></div><div class="attsLine"><div class="attsRoundBg"><span class="attsFollowersIcon">&#xe92c;</span></div><div class="attsText">' + j[i].afc + '</div></div></div></div></div><a href="/author.php?id_auth=' + j[i].ia + '"><div class="small_portrait" style="background-image: url(' + j[i].av + ');"></div><div class="small_auth_name" style="max-width:' + maxW + '"><span data-id-img="' + j[i].ip + '" class="tickCatNew authGalleryTooltip">' + j[i].an + '</span></a>';
1337
1338            auth_name_photo += tmp2;
1339            auth_name_photo += '</div>';
1340        }
1341
1342        var imgMark = '<div class="iMark">';
1343
1344        if(j[i].ai == 1) imgMark += '<span class="whiteaiicon galaiicon"></span>';
1345
1346
1347        if (j[i].iwd == 1) {
1348            //imgMark = '<span title="' + ploc.work_of_day_loc + '" class="placeMark">' + ploc.workofday_let_loc + '</span>';
1349            imgMark += '<span class="menuIconPhoto placeMark workOfDayMark" title="' + ploc.work_of_day_loc + '">&#xe99e;</span>';
1350        }
1351
1352        imgMark += '</div>';
1353
1354
1355
1356        var range = '';
1357        if (j[i].ic % 100 != 0)
1358            range = '&range=365';
1359
1360        var work_url = '/work.php?id_photo=' + j[i].ip + params;
1361        if (domainEnd != 'by') {
1362            work_url = '/work/' + j[i].ip;
1363            if (params != '')
1364                work_url += '?' + params;
1365        }
1366
1367        // define styles of preview backgrounds
1368        var pw = parseInt(j[i].pw);
1369        var ph = parseInt(j[i].ph);
1370
1371        if (isMobVer) {
1372            pw = pw / 4;
1373            ph = ph / 4;
1374            //log(pw)
1375        }
1376
1377        var widthHeightRatio = pw / ph;
1378
1379        var bgSize = 'cover';
1380        var bgPosY = '50%';
1381
1382        if (isSquareGall) {
1383            if (widthHeightRatio >= 2.2) {
1384                bgSize = 'cover';
1385            }
1386        } else {
1387            // check if people category
1388            if (j[i].icp == 100 || j[i].icp == 1100 || j[i].icp == 301 || j[i].ic == 603 || j[i].ic == 701 || j[i].ic == 705 || j[i].ic == 706 || j[i].ic == 707 || j[i].ic == 708) {
1389                bgSize = 'cover'; //'120%';
1390                bgPosY = '35%';
1391                if (widthHeightRatio < 0.7 && pw <= ph)
1392                    bgPosY = '35%';
1393            } else {
1394                if (widthHeightRatio >= 2.2)
1395                    bgSize = 'cover';
1396            }
1397
1398            if (j[i].ic == 111) bgSize = 'cover';
1399        }
1400
1401        $gall_photos += '<div id="imgBoxNew' + j[i].ip + '"  class="imgBo
1401xNew" style="width:' + pw + 'px; height:' + ph + 'px; opacity: 0;">';
1402        $gall_photos += '<a class="aFullPage roundBL3" href="' + work_url + '" title="' + ploc.goto_photo_page_loc + '"><span class="iconFullScreen" style="font-size: 26px; line-height:11px; text-decoration: none;">&#xe924;</span></a><span id="iconFullSizeGall" class="iconFullSizeGall" data-src="' + getMainImage(j[i].iu) + '"><span class="iconFullSizeGallIcon" title="Fullscreen"  data-is-multi="1" data-id-photo="' + j[i].ip + '" data-src="' + j[i].iu + '" data-pos="' + pos + '"  data-ian="' + j[i].ian + '">&#xe936;</span></span>';
1403        $gall_photos += imgMark;
1404        $gall_photos += '<a href="' + work_url + '" data-is-multi="1" data-id-photo="' + j[i].ip + '" data-src="' + j[i].iu + '" data-pos="' + pos + '"  data-ian="' + j[i].ian + '" data-ph-w="' + j[i].pmw + '" data-ph-h="' + j[i].pmh + '" class="imgThumb aPopup' + blurClass + '" style="' + thumbBg + ' width: 100%; height: 100%; background-size: ' + bgSize + '; background-position-y: ' + bgPosY + '; opacity: 1; position: absolute; top: 0; left: 0;"></a>';
1405        //$gall_photos += '<a href="' + work_url + '" class="imgThumb aPopup' + blurClass + '" style="' + thumbBg + ' width: 100%; height: 100%; background-size: ' + bgSize + '; background-position-y: ' + bgPosY + '; opacity: 1; position: absolute; top: 0; left: 0;"></a>';
1406        $gall_photos += '<div class="phDescNew" data-is-multi="1" data-id-photo="' + j[i].ip + '" data-src="' + j[i].iu + '" data-pos="' + pos + '"  data-ian="' + j[i].ian + '" data-ph-w="' + j[i].pmw + '" data-ph-h="' + j[i].pmh + '"  style="opacity: 1;">';
1407        //$gall_photos += '<div class="phDescNew" style="opacity: 1;">';
1408
1409        if (j[i].stock_photo != 0) {
1410            price_label = ploc.stock_photo_loc;
1411            listed_in = ploc.stock_photos_loc;
1412        } else {
1413            price_label = ploc.art_photo_loc;
1414            listed_in = ploc.art_photos_loc;
1415        }
1416
1417        if (j[i].photo_license == 'editorial') {
1418            license_label = ploc.ed_license_label_loc;
1419        } else {
1420            license_label = ploc.comm_license_label_loc;
1421        }
1422
1423        //if (hash.search(/marketplace=/) != -1 || hash.search(/sale=/) != -1) {
1424
1425        if (j[i].listed_for_sale != 0) {
1426            $gall_photos += '<div class="priceWrap"><span class="cartIcon">&#xe966;</span>';
1427            $gall_photos += '<div class="priceLabel0">' + ploc.l_for_sale_loc + '<div class="priceLabel" title="' + listed_in + '">' + price_label + '</div></div>';
1428
1429            if (j[i].token_id != 0) {
1430                $gall_photos += '<div class="priceDiv">$' + j[i].photo_price + '<span class="priceFee" title="2% Protocol fee + 5% Service fee"> + 7% Fees</span></div>'; //'+j[i].fee+' '+ploc.fee_loc+
1431                $gall_photos += '<div class="priceBottomLabel">Royalty-free<br>' + license_label + '</div>';
1432            } else {
1433                $gall_photos += '<div class="priceDiv notMinted">Not minted</div>';
1434            }
1435
1436            $gall_photos += '</div>';
1437        }
1438
1439        if (j[i].stock_photo == 0) {
1440            $spoiler_class = (j[i].ns == 1) ? 'spoiler invert' : '';
1441            $gall_photos += '<a href="' + work_url + '" data-is-multi="1" data-id-photo="' + j[i].ip + '" data-src="' + j[i].iu + '" data-pos="' + pos + '"  data-ian="' + j[i].ian + '" class="phNameLink"><div class="phNameNew">';
1442            $gall_photos += '<span class="phN"><div class="inline '+$spoiler_class+'">' + j[i].pn + '</div></span> ';
1443            //if (j[i].ra > 0)
1444            $gall_photos += '<span id="ratingIcon' + j[i].ip + '" class="heart_gall">&#xe928;</span><span class="ratingNum" id="ratingNum' + j[i].ip + '" data-ph-rating="' + j[i].ra + '">' + j[i].ra + '</span>';
1445            if (j[i].id_auth != -1)
1446                $gall_photos += '<div id="recFromPreview" class="recFromPreview" data-id-author="' + j[i].ia + '" data-id-photo="' + j[i].ip + '" data-id-auth="' + hash.iauth + '" title="' + ploc.add_rec_loc + '">&#xe933;</div>';
1447            //$gall_photos += '<object class="pointer_svg_icon" type="image/svg+xml" data="/css/svg/pointer.svg"></object>';
1448            $gall_photos += '<div class="view_icon">&#xe946;</div>';
1449            $gall_photos += j[i].pv;
1450            $gall_photos += '</div></a>';
1451        }
1452
1453        $gall_photos += auth_name_photo;
1454
1455        $gall_photos += '<a class="tickCommNew tickCommBg" ' + noBgStyle + ' rel="nofollow" href="' + work_url + '#wrapWorkComm" title="' + ploc.comments_loc + '" data-date="' + j[i].pd + '" data-comms="' + j[i].cc + '">';
1456        if (j[i].cc > 0)
1457            $gall_photos += j[i].cc;
1458        $gall_photos += '</a>';
1459        $gall_photos += '</div>';
1460        $gall_photos += '</div>';
1461    }
1462
1463    if (!isInfinite) {
1464        $gall_photos += '</div>';
1465    }
1466
1467    //resizedElements = [];
1468
1469    return $gall_photos;
1470
1471}
1472
1473function getMarks(id_photo, mark) {
1474    $("#markWarn").html("<div style=\"padding-top:3px;font-size:11px;\">" + ploc.thankyou_mark_loc + "</div>");
1475    $.get(ajaxFld + "get_marks.php", {
1476        id_photo: id_photo,
1477        mark: mark
1478    }, function(data) {
1479        NProgress.done();
1480        $("#averMarkAjax").html(data);
1481        $("#mark", "input[name='mark']").attr("disabled", "disabled");
1482    });
1483    $("#previewMark").hide();
1484    $("#previewButtons").show();
1485}
1486
1487function viewFullScreen() {
1488    return false;
1489}
1490
1491function setBg(bg, textColor) {
1492    $workWrap = $("#workWrap");
1493    $cropBg = $('.cropper-drag-box');
1494
1495    $cropBg.css('background-color', bg);
1496
1497    $workWrap.css({
1498        "background-color": bg,
1499        'color': textColor
1500    });
1501
1502    $('#add_crop_lnk').css('color', textColor);
1503
1504    $workWrap.find('h1').css({
1505        'color': textColor
1506    });
1507    $workWrap.find('#addRecAjax').css({
1508        'color': textColor
1509    });
1510    $workWrap.find('#image_description').css({
1511        'color': textColor
1512    });
1513
1514    $workWrap.find('#add_crop_lnk').css({
1515        'color': textColor
1516    });
1517
1518    ph_bg = bg;
1519}
1520
1521var isCommPosted = false;
1522
1523function trimComm(comm_text) {
1524    return trim(comm_text.replace(/&nbsp;/g, '').replace(/\[vimeo\](.*?)\[\/vimeo\]/gi, "").replace(/\[youtube\](.*?)\[\/youtube\]/gi, "").replace(/\[img\](.*?)\[\/img\]/gi, "").replace(/\[code\](.*?)\[\/code\]/gi, "").replace(/\[url=?.*\](.*?)\[\/url\]/gi, "").replace(/\:wink/g, '').replace(/\:curvesmile/g, '').replace(/\:beer/g, '').replace(/\:confused/g, '').replace(/\:eek/g, '').replace(/\:evil/g, '').replace(/\:frown/g, '').replace(/\:idea/g, '').replace(/\:lamer/g, '').replace(/\:lol/g, '').replace(/\:puke/g, '').replace(/\:rolleyes/g, '').replace(/\:roof/g, '').replace(/\:insane/g, '').replace(/\:love/g, '').replace(/\:moderator/g, '').replace(':molotok:', '').replace(':naezd:', '').replace(/\:redtongue/g, '').replace(/\:shuffle/g, '').replace(/\:photo/g, '').replace(/\:super/g, '').replace(/\:weep/g, '').replace(/\:znaika/g, '').replace(/\:nopets/g, '').replace(/\:dislike/g, '').replace(/\:hairup/g, '').replace(/\:buzz/g, '').replace(/\:taz/g, '').replace(/\:/g, '').replace(/\!/g, '').replace(/\[quote\]/g, '').replace(/\[\/quote\]/g, '').replace(/\[b\]/g, '').replace(/\[\/b\]/g, '').replace(/\[u\]/g, '').replace(/\[\/u\]/g, '').replace(/\[i\]/g, '').replace(/\[\/i\]/g, '').replace(/\[s\]/g, '').replace(/\[\/s\]/g, '').replace(/[\(\)\ \t\.\:\,\;\\\/\!\?]/g, '').replace(/\s/gm, ""));
1525}
1526
1527function setReplay(id, id_answer, id_comm) {
1528    id_auth_answer = id_answer;
1529    id_comm_parent = id_comm;
1530    var reCrop = new RegExp(ploc.crop_var_loc);
1531    if (isOverlay)
1532        var answer = $('#spanCommText' + id).html();
1533    else
1534        var answer = $('#tdCommText' + id).html();
1535    answer = answer.replace(/<div class="commQuote" ?s?t?y?l?e?=?"?"?>[\s\S]+<\/div>/g, '');
1536    answer = answer.replace(/<br>/g, '').replace(/&nbsp;/g, '');
1537    answer = answer.replace(/<strong>/g, '[b]').replace(/<\/strong>/g, '[/b]').replace(/<u>/g, '[u]').replace(/<\/u>/g, '[/u]').replace(/<i>/g, '[i]').replace(/<\/i>/g, '[/i]');
1538    answer = answer.replace(/showCrop\((\d+), ?(\d+), ?(\d+), ?(\d+)\)/g, '>[Crop:$1:$2:$3:$4]<');
1539    answer = answer.replace(/#Crop:(\d+):(\d+):(\d+):(\d+)/g, '>[Crop:$1:$2:$3:$4]<');
1540    answer = answer.replace(/<\/?[^>]+(>|$)/g, "");
1541    answer = answer.replace(reCrop, '');
1542    answer = answer.replace(/^\n+/, '').replace(/\n+$/, '');
1543    answer = '[quote]' + trim(answer) + '[/quote]\n\n[b]' + $('#authName' + id).text() + '[/b], ';
1544
1545    if (isOverlay)
1546        var txtArea = $('#previewCommArea');
1547    else
1548        var txtArea = $('#comment');
1549
1550    if (txtArea.val() == '')
1551        txtArea.val(answer);
1552    else
1553        txtArea.val(txtArea.val() + '\n\n' + answer);
1554    txtArea.focus();
1555    //updateTextareaHeight(txtArea);
1556}
1557
1558function setReplayPopup(id, id_answer, id_comm, auth_name) {
1559    id_auth_answer = id_answer;
1560    id_comm_parent = id_comm;
1561    var reCrop = new RegExp(ploc.crop_var_loc);
1562    if (isOverlay)
1563        var answer = $('#spanCommText' + id).html();
1564    else
1565        var answer = $('#tdCommText' + id).html();
1566    answer = answer.replace(/<div class="commQuotePopup" ?s?t?y?l?e?=?"?"?>[\s\S]+<\/div>/g, '');
1567    answer = answer.replace(/<br>/g, '').replace(/&nbsp;/g, '');
1568    answer = answer.replace(/<strong>/g, '[b]').replace(/<\/strong>/g, '[/b]').replace(/<u>/g, '[u]').replace(/<\/u>/g, '[/u]').replace(/<i>/g, '[i]').replace(/<\/i>/g, '[/i]');
1569    answer = answer.replace(/showCrop\((\d+), ?(\d+), ?(\d+), ?(\d+)\)/g, '>[Crop:$1:$2:$3:$4]<');
1570    answer = answer.replace(/#Crop:(\d+):(\d+):(\d+):(\d+)/g, '>[Crop:$1:$2:$3:$4]<');
1571    answer = answer.replace(/<\/?[^>]+(>|$)/g, "");
1572    answer = answer.replace(reCrop, '');
1573    answer = answer.replace(/^\n+/, '').replace(/\n+$/, '');
1574    answer = '[quote]' + trim(answer) + '[/quote]\n\n';
1575    if (auth_name != '')
1576        answer += '[b]' + auth_name + '[/b], ';
1577
1578    if (isOverlay)
1579        var txtArea = $('#previewCommArea');
1580    else
1581        var txtArea = $('#comment');
1582    if (txtArea.val() == '')
1583        txtArea.val(answer);
1584    else
1585        txtArea.val(txtArea.val() + '\n\n' + answer);
1586    txtArea.focus();
1587    //updateTextareaHeight(txtArea);
1588}
1589
1590function cancelActionComm(comm_nr) {
1591    $("#commButtons" + comm_nr).html('');
1592}
1593
1594function setActionReply(comm_nr, id, id_answer, auth_name, type) {
1595    id_auth_answer = id_answer;
1596    isCommentFocus = true;
1597    var reCrop = new RegExp(ploc.crop_var_loc);
1598    var answer = '';
1599    var commParent = '';
1600    if (window.location.pathname === '/comm.php')
1601        commParent = trim($("#tdCommText" + comm_nr).html());
1602    else
1603        commParent = trim($("#tdCommText" + comm_nr).find("div").html());
1604    commParent = commParent.replace(/<div class="commQuote" ?s?t?y?l?e?=?"?"?>[\s\S]+<\/div>/g, '');
1605    commParent = commParent.replace(/<br>/g, '').replace(/&nbsp;/g, '');
1606    commParent = commParent.replace(/<strong>/g, '[b]').replace(/<\/strong>/g, '[/b]').replace(/<u>/g, '[u]').replace(/<\/u>/g, '[/u]').replace(/<i>/g, '[i]').replace(/<\/i>/g, '[/i]');
1607    commParent = commParent.replace(/#Crop:(\d+):(\d+):(\d+):(\d+)/g, '>[Crop:$1:$2:$3:$4]<');
1608    commParent = commParent.replace(/<\/?[^>]+(>|$)/g, "");
1609    commParent = commParent.replace(reCrop, '');
1610    commParent = commParent.replace(/^\n+/, '').replace(/\n+$/, '').replace(/\ {2,}/, ' ').replace(/\ {2,}/, ' ');
1611    if (commParent != '' && commParent != 'undefined')
1612        answer += '[quote]' + commParent + '[/quote]\n\n';
1613    if (auth_name != '')
1614        answer += '[b]' + auth_name + '[/b], ';
1615
1616    var html = '<textarea class="txtArea" id="comm_text' + comm_nr + '" name="comm_text" style="width:calc(100% - 18px); height: 100px; padding-bottom: 6px;"></textarea>';
1617    html += '<div class="addCommBtn">';
1618    html += '<a class="saveBtn cancelBtn" onclick="cancelActionComm(' + comm_nr + '); return false;" style="margin-right: 3px;">' + ploc.cancel_loc + '</a>';
1619    html += '<a class="saveBtn" onclick="postActionComm(' + comm_nr + ', ' + id + ', \'' + type + '\', ' + id_answer + '); return false;">' + ploc.add_comm_loc + '</a>';
1620    html += '</div>';
1621
1622    $("#commButtons" + comm_nr).html(html);
1623    var $comm_text_area = $("#comm_text" + comm_nr);
1624    $comm_text_area.focus().val(answer);
1625    $comm_text_area.scrollTop($comm_text_area[0].scrollHeight);
1626}
1627
1628function getComm(id, comm_nr, type) {
1629    var $cT = $("#commText" + comm_nr);
1630    var isUp = false;
1631    setTimeout(function() {
1632        if (!isUp)
1633            $cT.html(loaderGray);
1634    }, 500);
1635    $.get(ajaxFld + "get_comm.php", {
1636        id: id,
1637        type: type
1638    }, function(data) {
1639        NProgress.done();
1640        isUp = true;
1641        $cT.html(data);
1642    });
1643}
1644
1645function getCommVote(id, type) {
1646    //$("#commVoteBtn" + id).html(loaderGall);
1647    $.get(ajaxFld + "get_comm_vote.php", {
1648        id: id,
1649        type: type
1650    }, function(data) {
1651        NProgress.done();
1652
1653        $("#commVote" + id).text(data);
1654        $("#commVoteBtn" + id).removeClass('intrestBtnA').removeClass('nobodyVoted').removeClass('somebodyVoted').addClass('intrestBtnAVoted');
1655
1656        $("#commVotePopup" + id).text(data);
1657        $("#commVotePopupBtn" + id).removeClass('intrestBtnA').removeClass('nobodyVoted').removeClass('somebodyVoted').addClass('intrestBtnAVoted');
1658
1659    });
1660}
1661
1662function postActionComm(comm_nr, id, type, id_auth_answer) {
1663    var comm_text = $("#comm_text" + comm_nr).val();
1664
1665    if (document.URL.indexOf('feed.php') != -1 || document.URL.indexOf('actions.php') != -1)
1666        tmpClass = 'addedMsg2';
1667    else
1668        tmpClass = 'addedMsg';
1669
1670    $("#commButtons" + comm_nr).html('<span class="' + tmpClass + '">' + ploc.comm_added_loc + '</span>');
1671    $.post(ajaxFld + "post_comm.php", {
1672        id: id,
1673        comm_text: comm_text,
1674        type: type,
1675        id_auth_answer: id_auth_answer,
1676        id_comm_parent: 0
1677    }, function(data) {
1678        NProgress.done();
1679        id_auth_answer = 0;
1680        id_comm_parent = 0;
1681    }, 'json');
1682}
1683
1684function postComm(id, type, id_auth, auth_name) {
1685    var $comment = $("#comment");
1686    var comm_text = $comment.val();
1687
1688    var trimmed_comm = trimComm(comm_text);
1689
1690    if (trimmed_comm.length < minCommLen) {
1691        alert(ploc.be_constructive_loc);
1692        getEl('comment').focus();
1693        return false;
1694    } else if (comm_text.length > maxCommLen) {
1695        alert(ploc.max_comm_len_loc);
1696        return false;
1697    } else {
1698
1699        //log('commtext UNPARSED'+comm_text);
1700        //comm_text = twemoji.parse(comm_text);
1701        //log('commtext PARSED'+comm_text);
1702
1703        $("#postCommDiv").hide();
1704        $("#loaderComm").show();
1705        $.post(ajaxFld + "post_comm.php", {
1706            id: id,
1707            comm_text: comm_text,
1708            type: type,
1709            id_auth_answer: id_auth_answer,
1710            id_comm_parent: id_comm_parent
1711        }, function(data) {
1712            NProgress.done();
1713            id_auth_answer = 0;
1714            id_comm_parent = 0;
1715            var comm_cnt = data.cnt;
1716
1717            if (type == 'work')
1718                var comm_per_page = work_comm_per_page;
1719            else
1720                var comm_per_page = blog_comm_per_page;
1721            if ($('#recWithComm:checked').val() == 'on')
1722                getRecs(id_photo, id_auth, auth_name);
1723            var page = Math.ceil(comm_cnt / comm_per_page);
1724            var comm_url = window.location.toString();
1725            if (comm_url.search(/#/) == -1)
1726                comm_url += '#id=' + id + '&type=' + type + '&page=' + page + '&nj';
1727            else {
1728                if (comm_url.search(new RegExp('&page=' + page + '$')) == -1)
1729                    comm_url = '#id=' + id + '&type=' + type + '&page=' + page + '&nj';
1730                else
1731                    comm_url += '&nj';
1732            }
1733            if (typeof ga !== "undefined") {
1734                var work_url = '/work.php?id_photo=' + id;
1735                if (domainEnd != 'by')
1736                    work_url = '/work/' + id;
1737                ga("send", "pageview", {
1738                    "page": work_url,
1739                    "title": document.title
1740                });
1741                if (typeof isAuthorTrack !== "undefined")
1742                    ga("author.send", "pageview", {
1743                        "page": work_url,
1744                        "title": document.title
1745                    });
1746            }
1747
1748            window.location.replace(comm_url);
1749            //window.location = comm_url;
1750            //log('comm_url='+comm_url);
1751            isCommPosted = true;
1752        }, 'json');
1753    }
1754}
1755
1756function getVote(id, vote, type) {
1757    $.get(ajaxFld + "get_vote.php", {
1758        id: id,
1759        vote: vote,
1760        type: type
1761    }, function(data) {
1762        NProgress.done();
1763        var blog_vote = parseInt($("#blogVoteT").text()) + parseInt(data);
1764        if (blog_vote == 0) {
1765            $("#blogVoteT").css("color", "#979797").text(blog_vote).addClass("animated bounceIn");
1766            $("#blogVoteB").css("color", "#979797").text(blog_vote).addClass("animated bounceIn");
1767        } else if (blog_vote < 0) {
1768            $("#blogVoteT").css("color", "#df0909").text(blog_vote);
1769            $("#blogVoteB").css("color", "#df0909").text(blog_vote);
1770        } else {
1771            /* $("#blogVoteT").css("color", "#333").text("+" + blog_vote);
1772             $("#blogVoteB").css("color", "#333").text("+" + blog_vote);
1773             */
1774            $("#blogVoteT").text("+" + blog_vote);
1775            $("#blogVoteB").text("+" + blog_vote);
1776        }
1777        $("#voteBtnT").css("margin", "0 3px 0 15px").css("color", "#333").css("background", "#eaeaea").css("border-radius", "16px").css("padding", "8px 15px 6px 15px").css("position", "relative").css("top", "-1px").css("font-size", "12px").text(ploc.vote_accept_loc);
1778        $("#voteBtnB").css("margin", "0 3px 0 15px").css("color", "#333").css("background", "#eaeaea").css("border-radius", "16px").css("padding", "8px 15px 6px 15px").css("position", "relative").css("top", "-1px").css("font-size", "12px").text(ploc.vote_accept_loc);
1779    });
1780}
1781
1782function emoticon(str) {
1783    if (isOverlay)
1784        var comment = getEl("previewCommArea");
1785    else
1786        var comment = getEl('comment');
1787    if (comment != null) {
1788        comment.value += '' + str + ' ';
1789        comment.focus();
1790    }
1791}
1792
1793var isOverlay = false;
1794
1795function NavigateThrough(e) {
1796    if (!getEl)
1797        return;
1798    if (isOverlay)
1799        return;
1800    e = e || window.event;
1801    if (typeof e.shiftKey !== "undefined" && !e.shiftKey && !isCommentFocus) {
1802        var link = null;
1803        var href = null;
1804        switch (e.keyCode ? e.keyCode : e.which ? e.which : null) {
1805            case 0x25:
1806                link = getEl('PrevLink');
1807                if (link === null)
1808                    link = getEl('PrevLinkB');
1809                if (link !== null)
1810                    startNProgress();
1811                break;
1812            case 0x27:
1813                link = getEl('NextLink');
1814                if (link === null)
1815                    link = getEl('NextLinkB');
1816                if (link !== null)
1817                    startNProgress();
1818                break;
1819            case 0x24:
1820                href = '/';
1821                break;
1822            case 0x26:
1823                viewFullScreen();
1824                break;
1825        }
1826
1827        if (isLoadingGall || isLoadingPopup) {
1828            e.stopPropagation();
1829            e.preventDefault();
1830        } else {
1831            if (link && link.href) {
1832                document.location = link.href;
1833                //log(link.href)
1834                //closePopupUrl = link.href;
1835            }
1836            if (href)
1837                document.location = href;
1838        }
1839    }
1840}
1841
1842var expectedHash = "";
1843
1844function handleHistory(defParam, urlType) {
1845    if (window.location.hash.search(/page=/) != -1) {
1846        if (window.location.hash == "") {
1847            expectedHash = defParam;
1848            window.location.hash = expectedHash;
1849            pageload(expectedHash.substring(1), urlType);
1850        } else {
1851            if (window.location.hash != expectedHash) {
1852                expectedHash = window.location.hash;
1853                pageload(expectedHash.substring(1), urlType);
1854            }
1855        }
1856    }
1857    return true;
1858}
1859
1860var prev_id_cat = 0;
1861
1862function pollHash(defParam, urlType) {
1863    handleHistory(defParam, urlType);
1864    window.setInterval("handleHistory('" + defParam + "', '" + urlType + "')", 200);
1865    return true;
1866}
1867
1868function updateSectionA(range) {
1869    $("#vertMenuBySection a").each(function() {
1870        $(this).attr("href", $(this).attr("href").replace(/range=\d{1,3}/, "range=" + range));
1871    });
1872}
1873
1874function updateRangeA(section) {
1875    $("#vertMenuByTime a").each(function() {
1876        if ($(this).attr("href").search(/featured=1/) != -1) {
1877            $(this).attr("href", $(this).attr("href").replace(/featured=1/, section + "=1"));
1878        } else if ($(this).attr("href").search(/special=1/) != -1) {
1879            $(this).attr("href", $(this).attr("href").replace(/special=1/, section + "=1"));
1880        } else if ($(this).attr("href").search(/rated=1/) != -1) {
1881            $(this).attr("href", $(this).attr("href").replace(/rated=1/, section + "=1"));
1882        } else if ($(this).attr("href").search(/all=1/) != -1) {
1883            $(this).attr("href", $(this).attr("href").replace(/all=1/, section + "=1"));
1884        } else if ($(this).attr("href").search(/nofilter=1/) != -1) {
1885            $(this).attr("href", $(this).attr("href").replace(/nofilter=1/, section + "=1"));
1886        } else if ($(this).attr("href").search(/rate=1/) != -1) {
1887            $(this).attr("href", $(this).attr("href").replace(/rate=1/, section + "=1"));
1888        } else if ($(this).attr("href").search(/view=1/) != -1) {
1889            $(this).attr("href", $(this).attr("href").replace(/view=1/, section + "=1"));
1890        } else if ($(this).attr("href").search(/comm=1/) != -1) {
1891            $(this).attr("href", $(this).attr("href").replace(/comm=1/, section + "=1"));
1892        } else if ($(this).attr("href").search(/critique=1/) != -1) {
1893            $(this).attr("href", $(this).attr("href").replace(/critique=1/, section + "=1"));
1894        } else if ($(this).attr("href").search(/workofday=1/) != -1) {
1895            $(this).attr("href", $(this).attr("href").replace(/workofday=1/, section + "=1"));
1896        } else if ($(this).attr("href").search(/follow=1/) != -1) {
1897            $(this).attr("href", $(this).attr("href").replace(/follow=1/, section + "=1"));
1898        } else if ($(this).attr("href").search(/selected=1/) != -1) {
1899            $(this).attr("href", $(this).attr("href").replace(/selected=1/, section + "=1"));
1900        } else if ($(this).attr("href").search(/choice=1/) != -1) {
1901            $(this).attr("href", $(this).attr("href").replace(/choice=1/, section + "=1"));
1902        } else if ($(this).attr("href").search(/friends=1/) != -1) {
1903            $(this).attr("href", $(this).attr("href").replace(/friends=1/, section + "=1"));
1904        } else
1905            $(this).attr("href", $(this).attr("href").replace(/section=1/, section + "=1"));
1906    });
1907}
1908
1909function pageload(hash, urlType) {
1910    $("#vertMenuBySection p").each(function() {
1911        $(this).css("background-color", "transparent");
1912        $(this).find("a").css("color", inactMenuColor);
1913    });
1914    $("#vertMenuByTime p").each(function() {
1915        $(this).css("background-color", "transparent");
1916        $(this).find("a").css("color", inactMenuColor);
1917    });
1918    if (hash.search(/id_cat=/) == -1) {
1919        if (hash.search(/featured=1/) != -1) {
1920            $("#aSectionFeatured").css("background-color", actMenuBg);
1921            $("#aSectionFeatured a").css("color", actMenuColor);
1922            updateRangeA("featured");
1923        } else if (hash.search(/special=1/) != -1) {
1924            $("#aSectionSpecial").css("background-color", actMenuBg);
1925            $("#aSectionSpecial a").css("color", actMenuColor);
1926            updateRangeA("special");
1927        } else if (hash.search(/rated=1/) != -1) {
1928            $("#aSectionRated").css("background-color", actMenuBg);
1929            $("#aSectionRated a").css("color", actMenuColor);
1930            updateRangeA("rated");
1931        } else if (hash.search(/all=1/) != -1) {
1932            $("#aSectionAll").css("background-color", actMenuBg);
1933            $("#aSectionAll a").css("color", actMenuColor);
1934            updateRangeA("all");
1935        } else if (hash.search(/nofilter=1/) != -1) {
1936            $("#aSectionNofilter").css("background-color", actMenuBg);
1937            $("#aSectionNofilter a").css("color", actMenuColor);
1938            updateRangeA("nofilter");
1939        } else if (hash.search(/rate=1/) != -1) {
1940            $("#aSectionRate").css("background-color", actMenuBg);
1941            $("#aSectionRate a").css("color", actMenuColor);
1942            updateRangeA("rate");
1943        } else if (hash.search(/view=1/) != -1) {
1944            $("#aSectionView").css("background-color", actMenuBg);
1945            $("#aSectionView a").css("color", actMenuColor);
1946            updateRangeA("view");
1947        } else if (hash.search(/comm=1/) != -1) {
1948            $("#aSectionComm").css("background-color", actMenuBg);
1949            $("#aSectionComm a").css("color", actMenuColor);
1950            updateRangeA("comm");
1951        } else if (hash.search(/critique=1/) != -1) {
1952            $("#aSectionCritique").css("background-color", actMenuBg);
1953            $("#aSectionCritique a").css("color", actMenuColor);
1954            updateRangeA("critique");
1955        } else if (hash.search(/fineart=1/) != -1) {
1956            $("#aSectionFineart").css("background-color", actMenuBg);
1957            $("#aSectionFineart a").css("color", actMenuColor);
1958            updateRangeA("fineart");
1959        } else if (hash.search(/workofday=1/) != -1) {
1960            $("#aSectionWorkofday").css("background-color", actMenuBg);
1961            $("#aSectionWorkofday a").css("color", actMenuColor);
1962            updateRangeA("workofday");
1963        } else if (hash.search(/follow=1/) != -1) {
1964            $("#aSectionFavorites").css("background-color", actMenuBg);
1965            $("#aSectionFavorites a").css("color", actMenuColor);
1966            updateRangeA("favorites");
1967        } else if (hash.search(/selected=1/) != -1) {
1968            $("#aSectionSelected").css("background-color", actMenuBg);
1969            $("#aSectionSelected a").css("color", actMenuColor);
1970            updateRangeA("selected");
1971        } else if (hash.search(/friends=1/) != -1) {
1972            $("#aSectionFriends").css("background-color", actMenuBg);
1973            $("#aSectionFriends a").css("color", actMenuColor);
1974            updateRangeA("friends");
1975        }
1976
1977        if (hash.search(/range=7/) != -1) {
1978            $("#aSectionWeek").css("background-color", actMenuBg);
1979            $("#aSectionWeek a").css("color", actMenuColor);
1980            updateSectionA(7);
1981        } else if (hash.search(/range=365/) != -1) {
1982            $("#aSectionYear").css("background-color", actMenuBg);
1983            $("#aSectionYear a").css("color", actMenuColor);
1984            updateSectionA(365);
1985        } else if (hash.search(/range=30/) != -1) {
1986            $("#aSectionMonth").css("background-color", actMenuBg);
1987            $("#aSectionMonth a").css("color", actMenuColor);
1988            updateSectionA(30);
1989        } else if (hash.search(/range=3/) != -1) {
1990            $("#aSection3Days").css("background-color", actMenuBg);
1991            $("#aSection3Days a").css("color", actMenuColor);
1992            updateSectionA(3);
1993        } else if (hash.search(/range=1/) != -1) {
1994            $("#aSectionDay").css("background-color", actMenuBg);
1995            $("#aSectionDay a").css("color", actMenuColor);
1996            updateSectionA(1);
1997        } else {
1998            $("#aSectionForever").css("background-color", actMenuBg);
1999            $("#aSectionForever a").css("color", actMenuColor);
2000            updateSectionA(0)
2001        }
2002    }
2003
2004    if (window.location.hash.search(/type=/) == -1 && window.location.hash.search(/id_auth_photo=/) == -1 && window.location.hash.search(/id_auth=/) == -1) {
2005        var aGalleryT = $("#aGalleryT");
2006        var aGalleryTG = $("#aGalleryTG");
2007        var aGalleryTA = $("#aGalleryTA");
2008        var aTop200TA = $("#aTop200TA");
2009        var aFollowingTA = $("#aFollowingTA");
2010        var aMarket = $("#aMarket");
2011        var gallLinks = $('#gallLinks');
2012        var marketLinks = $('#marketLinks');
2013
2014        aGalleryT.attr("class", "menuLiAct");
2015        aGalleryTG.attr("class", "menuAAct");
2016
2017        if (window.location.hash.search(/follow=/) == 1) {
2018            aGalleryTA.removeClass("menuAAct");
2019            aTop200TA.removeClass("menuAAct");
2020            aFollowingTA.attr("class", "menuAAct");
2021            aMarket.removeClass("menuLiAct");
2022            gallLinks.show();
2023            marketLinks.hide();
2024        } else if (window.location.hash.search(/rate=/) == -1 && window.location.hash.search(/comm=/) == -1 && window.location.hash.search(/view=/) == -1 && window.location.hash.search(/market=/) == -1 && window.location.hash.search(/global=/) == -1 && window.location.hash.search(/marketplace=/) == -1) {
2025            aGalleryTA.attr("class", "menuAAct");
2026            aTop200TA.removeClass("menuAAct");
2027            aFollowingTA.removeClass("menuAAct");
2028            aMarket.removeClass("menuLiAct");
2029            gallLinks.show();
2030            marketLinks.hide();
2031        } else if (window.location.hash.search(/market=/) == 1 || window.location.hash.search(/global=/) == 1 || window.location.hash.search(/marketplace=/) == 1) {
2032            aGalleryT.removeClass("menuLiAct");
2033            aGalleryTG.removeClass("menuAAct");
2034            aMarket.addClass("menuLiAct");
2035            aMarket.find('a').addClass('menuAAct');
2036
2037            gallLinks.hide();
2038            marketLinks.show();
2039
2040        } else {
2041            aGalleryTA.removeClass("menuAAct");
2042            $(aTop200TA).attr("class", "menuAAct");
2043            $(aFollowingTA).removeClass("menuAAct");
2044            aMarket.removeClass("menuLiAct");
2045            gallLinks.show();
2046            marketLinks.hide();
2047        }
2048    }
2049
2050    function getCurrentSelectionParam(hashGall) {
2051        var currentSelectionParam = '';
2052        if (hashGall.search(/rate=/) !== -1)
2053            currentSelectionParam = '&rate=1';
2054        else if (hashGall.search(/comm=/) !== -1)
2055            currentSelectionParam = '&comm=1';
2056        else if (hashGall.search(/view=/) !== -1)
2057            currentSelectionParam = '&view=1';
2058        else if (hashGall.search(/rated=/) !== -1)
2059            currentSelectionParam = '&rated=1';
2060        else if (hashGall.search(/all=/) !== -1)
2061            currentSelectionParam = '&all=1';
2062        else if (hashGall.search(/critique=/) !== -1)
2063            currentSelectionParam = '&critique=1';
2064        else if (hashGall.search(/special=/) !== -1)
2065            currentSelectionParam = '&special=1';
2066        else if (hashGall.search(/workofday=/) !== -1)
2067            currentSelectionParam = '&workofday=1';
2068        else if (hashGall.search(/follow=/) !== -1)
2069            currentSelectionParam = '&follow=1';
2070        else if (hashGall.search(/selected=/) !== -1)
2071            currentSelectionParam = '&selected=1';
2072        else if (hashGall.search(/choice=/) !== -1)
2073            currentSelectionParam = '&choice=1';
2074        else if (hashGall.search(/featured=/) !== -1)
2075            currentSelectionParam = '&featured=1';
2076        else if (hashGall.search(/sale=/) !== -1)
2077            currentSelectionParam = '&sale=1';
2078        // else if (hashGall.search(/marketplace=1/) !== -1)
2079        //     currentSelectionParam = '&marketplace=1';
2080        // else if (hashGall.search(/marketplace=2/) !== -1)
2081        //     currentSelectionParam = '&marketplace=2';
2082        // else if (hashGall.search(/marketplace=3/) !== -1)
2083        //     currentSelectionParam = '&marketplace=3';
2084        else if (hashGall.search(/marketplace=4/) !== -1)
2085            currentSelectionParam = '&marketplace=4';
2086        return currentSelectionParam;
2087    }
2088
2089    function getCurrentRangeParam(hashGall) {
2090        var currentRangeParam = '';
2091        if (hashGall.search(/range=365/) !== -1)
2092            currentRangeParam = '&range=365';
2093        else if (hashGall.search(/range=30/) !== -1)
2094            currentRangeParam = '&range=30';
2095        else if (hashGall.search(/range=3/) !== -1)
2096            currentRangeParam = '&range=3';
2097        else if (hashGall.search(/range=1/) !== -1)
2098            currentRangeParam = '&range=1';
2099        else if (hashGall.search(/range=0/) !== -1)
2100            currentRangeParam = '&range=0';
2101        else
2102            currentRangeParam = '&range=7';
2103        return currentRangeParam;
2104    }
2105
2106    function getCurrentSortParam(hashGall) {
2107        var currentRangeParam = '';
2108        if (hashGall.search(/nosort=1/) !== -1)
2109            currentRangeParam = '&nosort=1';
2110        else if (hashGall.search(/sort=rating/) !== -1)
2111            currentRangeParam = '&sort=rating';
2112       
2113        return currentRangeParam;
2114    }
2115
2116    function getCurrentCategoryParam(hashGall) {
2117        var currentCategoryParam = '';
2118        var matches = hashGall.match(/id_cat=\d{3,4}/);
2119        if (matches && matches[0])
2120            currentCategoryParam = '&' + matches[0];
2121        return currentCategoryParam;
2122    }
2123
2124
2125    function getCurrentGalleryParam(hashGall) {
2126        var currentGalleryParam = '';
2127        var matches = hashGall.match(/gal_id=\d{2,6}/);
2128        if (matches && matches[0])
2129            currentGalleryParam = '&' + matches[0];
2130        return currentGalleryParam;
2131    }
2132
2133    if (hash) {
2134        isLoadingGall = true;
2135        $.ajax({
2136            url: ajaxFld + urlType + '.php?' + hash,
2137            cache: false,
2138            dataType: 'json',
2139
2140            beforeSend: function() {
2141                if (urlType == 'post_comm') {
2142                    $("#pagerTop").html(loaderComm);
2143                } else {
2144                    $("#pagerTop").html(loaderGall);
2145                }
2146
2147                if (urlType == 'get_gallery')
2148                    $("#pagerBottom").html('');
2149
2150                var matches = hash.match(/id_cat=\d{3,4}\&/g);
2151                if (matches == undefined) {
2152                    if (prev_id_cat != 0) {
2153                        $('#headCat' + ((Math.floor(prev_id_cat / 100) * 100) / 100 - 1)).css('background-color', 'transparent').css("color", inactMenuColor);
2154                    }
2155                    prev_id_cat = 0;
2156                } else {
2157                    var cur_id_cat = matches[0].substring(7, matches[0].indexOf('&'));
2158                    if (prev_id_cat != 0) {
2159                        $('#headCat' + ((Math.floor(prev_id_cat / 100) * 100) / 100 - 1)).css('background-color', 'transparent').css("color", inactMenuColor);
2160                    }
2161                    prev_id_cat = cur_id_cat;
2162                    $('#headCat' + ((Math.floor(cur_id_cat / 100) * 100) / 100 - 1)).css('background-color', actMenuBg).css("color", actMenuColor);
2163                }
2164            },
2165
2166            error: function(jqXHR, textStatus, errorThrown) {
2167                info(jqXHR + ' : ' + textStatus + ' : ' + errorThrown)
2168            },
2169
2170            success: function(data, textStatus) {
2171                NProgress.done();
2172
2173                //var aw = document.getElementById('authorWorks');
2174                //if(aw !== null) checkWidth();
2175
2176                $('#wSubMenu').css('position', '');
2177                $('#wSubMenu').show();
2178
2179                setTimeout(function() {
2180                    momentDate();
2181                }, 500);
2182
2183                if (window.location.hash.search('favor=') != -1 || window.location.hash.search('recs=') != -1) {
2184                    $('#authMenuSortingTab').hide();
2185                } else {
2186                    $('#authMenuSortingTab').show();
2187                }
2188
2189                if (hash.search(/&nj$/) !== -1) {
2190                    hash = hash.replace(/&nj$/, '');
2191                    expectedHash = '#' + hash;
2192                    window.location.hash = hash;
2193                }
2194
2195                if (document.URL.indexOf('more=1') != -1 && (window.location.hash.search('comm_give=') != -1 || window.location.hash.search('comm_got=') != -1 || window.location.hash.search('recs=1') != -1 || window.location.hash.search('favor=1') != -1)) {
2196
2197                    $('#authorWorks').css('width', '100%').css('padding', '90px 0 26px 0').css('border-radius', '0px');
2198                    $('.gallAjaxAuthor').css('width', '915px').css('margin', '0 auto');
2199                    //$('#authProfilMenu').css('border-radius', '10px 10px 0 0').css('width','901px');
2200                    $('.getAuthMoreText').css('margin-top', '17px;');
2201                    //setSmallMenu();
2202
2203                } else {
2204                    $('#authorWorks').removeProp('width').removeProp('padding').removeProp('border-radius');
2205                    $('.gallAjaxAuthor').css('width', '').css('margin', '');
2206                    //$('#authProfilMenu').css('border-radius', '').css('width','');
2207                    //if (typeof restoreMenu !== 'undefined')
2208                    //restoreMenu();  
2209
2210                }
2211
2212                //if (window.location.hash.search('sort=rating') != -1 || window.location.hash.search('nosort=1') != -1) {
2213                //    $("#authProfilMenu").css('margin-left', '0px');
2214                //}
2215
2216                // handle series styles
2217                if (window.location.hash.search('id_serie=') != -1) {
2218
2219                    $("#authSerieBlk").css('display', 'block');
2220
2221                    //$('.profileLink').css('font-size','16px');
2222                    $('.profileLink.dots').css('font-size', '');
2223                } else {
2224                    $("#authSerieBlk").hide();
2225                    //$('.profileLink').css('font-size','');
2226                }
2227
2228                var serieM = window.location.hash.match(/id_serie=(\d+)/);
2229
2230                if (serieM != null) {
2231
2232                    $("#authSerieLines").children("p").each(function() {
2233                        $(this).find("a").addClass('inactiveSerie').removeClass('activeSerie');
2234                    });
2235
2236                    $("#authSerieBlk").on({
2237                        mouseenter: function() {
2238                            $("#authSerieBlk").css('width', '335px');
2239                            $("#authSerieLines a").css('visibility', 'visible');
2240
2241                        },
2242                        mouseleave: function() {
2243                            $("#authSerieBlk").css('width', '');
2244                            $("#authSerieLines a").css('visibility', 'hidden');
2245
2246                        }
2247                    });
2248
2249                    $("#authMenuSerieContent").children("span").each(function() {
2250                        $(this).find("a").css({
2251                            "font-weight": 400
2252                        });
2253                    });
2254
2255                    $("#serieDropDown" + serieM[1]).find("a").addClass('activeSerie');
2256
2257                    $("#serie" + serieM[1]).find("a").addClass('activeSerie');
2258
2259                    if (window.location.hash.search('id_serie=') != -1) {
2260
2261                        $('#authMenuSortingContent').children("a").each(function() {
2262
2263                            if ($(this).attr('href').search('id_serie=') == -1) {
2264                                $(this).attr('href', $(this).attr('href') + '&id_serie=' + data.idserie);
2265                                //log('id_serie detected');
2266                            } else {
2267                                var link = $(this).attr('href');
2268                                link2 = link.replace(/id_serie=(\d+)/, 'id_serie=' + data.idserie);
2269                                //log('link=' + link2);
2270                                $(this).attr('href', link2);
2271
2272                            }
2273
2274                        });
2275                    }
2276
2277                }
2278
2279                var $gallAjax = $("#gallAjax");
2280                var $contentDiv = $("#contentDiv");
2281
2282                /*
2283                var tmpMargin = 9;
2284                var tmpMaxRowHeight = 305;
2285                var tmpGallAspectRatio = 5;
2286                var tmpGallRowHeight = 250;
2287
2288                if (window.location.hash.search(/id_auth_photo=/) != -1 || window.location.hash.search(/recs=/) != -1 || window.location.hash.search(/favor=/) != -1 || window.location.hash.search(/bookmark=/) != -1) {
2289                    tmpMargin = 6;
2290
2291                }
2292                */
2293
2294                // setting active gallery submenu tab
2295                var hashGall = window.location.hash;
2296                var $gallMenuHeaderTab2 = $('#gallMenuHeaderTab2');
2297                if (hashGall.search('rated=') == 1) {
2298                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2299                    //$gallMenuHeaderTab.removeClass('menuAct');
2300                    $('#ratedW').addClass('gallMenuAct');
2301                } else if (hashGall.search('featured=') == 1) {
2302                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2303                    //$gallMenuHeaderTab.removeClass('menuAct');
2304                    $('#recW').addClass('gallMenuAct');
2305                } else if (hashGall.search('all=') == 1) {
2306                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2307                    //$gallMenuHeaderTab.removeClass('menuAct');
2308                    $('#allW').addClass('gallMenuAct');
2309                } else if (hashGall.search('special=') == 1) {
2310                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2311                    //$gallMenuHeaderTab.removeClass('menuAct');
2312                    $('#specialW').addClass('gallMenuAct');
2313                } else if (hashGall.search('workofday=') == 1) {
2314                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2315                    //$gallMenuHeaderTab.removeClass('menuAct');
2316                    $('#dayW').addClass('gallMenuAct');
2317                } else if (hashGall.search('follow=') == 1) {
2318                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2319                    //$gallMenuHeaderTab.removeClass('menuAct');
2320                    $('#favW').addClass('gallMenuAct');
2321                } else if (hashGall.search('rate=') == 1 || hashGall.search('comm=') == 1 || hashGall.search('view=') == 1) {
2322                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2323                    //$gallMenuHeaderTab.removeClass('menuAct');
2324                    $('#rateW').addClass('gallMenuAct');
2325                } else if (hashGall.search('sale=') == 1 || hashGall.search('&sale=') == 1) {
2326
2327                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2328                    $('#saleW').addClass('gallMenuAct');
2329
2330                } else {
2331                    $gallMenuHeaderTab2.find("div").removeClass('gallMenuAct');
2332                    //$gallMenuHeaderTab.addClass('menuAct');
2333                }
2334
2335                if (data.ps == '') {
2336                    if (window.location.hash.search(/followers=/) != -1)
2337                        $gallAjax.html('<div class="noWorks">' + ploc.no_followers_loc + '</div>');
2338                    else if (window.location.hash.search(/id_auth_photo=/) != -1)
2339                        $gallAjax.html('<div class="noWorks">' + ploc.no_auth_works_loc + '</div>');
2340                    else
2341                        $gallAjax.html('<div class="noWorks">' + ploc.no_works_loc + '</div>');
2342
2343                     if (hashGall.search('gal_id=') == 1) { 
2344                        $('#wrapGallPath .subGallHeader').html(data.headtitle);
2345                        $('#commentGallHeader').html(data.subtitle);
2346                    }
2347
2348                } else {
2349                    if (urlType == 'get_gallery') {
2350                        if (data.title != "")
2351                            document.title = data.title;
2352
2353                        //////////////////////////////////////////////////////////////////
2354                        var hashGall = window.location.hash;
2355                        var $wrapGallMenu = $('#wrapGallMenu');
2356                        var $gallMenuHeaderTab2 = $('#gallMenuHeaderTab2');
2357                        var images = '';
2358                        //var $gallMenuHeaderTab = $('#gallMenuHeaderTab');
2359                        //var $gallMenuHeaderTab = $('#gHeader');
2360
2361                        // update gallery header
2362                        //$('#gallMenuHeaderTab #gHeader', $wrapGallMenu).html(data.title);
2363
2364                        if (hashGall.search('keyword=') == 1 || hashGall.search('market=') == 1 || hashGall.search('global=') == 1 || hashGall.search('all=') == 1) {
2365                            images = ' ' + ploc.images_loc;
2366                            $('#commentGallHeader').html(ploc.all_photos_loc);
2367                        } else {
2368                            $('#commentGallHeader').html(data.subtitle);
2369                        }
2370
2371                        $('#wrapGallPath .subGallHeader').html(data.headtitle + images);
2372
2373
2374                        // show/hide gallery sorting menu
2375                        var $wrapGallMenuSorting = $('#wrapGallMenuSorting');
2376                        if (hashGall.search(/choice=/) === -1 && hashGall.search(/global=/) === -1 && hashGall.search(/keyword=/) === -1 && hashGall.search(/market=/) === -1 && hashGall.search(/favorites=/) === -1 && hashGall.search(/rate=/) === -1 && hashGall.search(/comm=/) === -1 && hashGall.search(/view=/) === -1)
2377                            $wrapGallMenuSorting.show();
2378                        else
2379                            $wrapGallMenuSorting.hide();
2380
2381
2382
2383                        // update sorting header
2384                        $wrapGallMenuSorting.find('span').html(data.gall_sort);
2385                        $('#authMenuSortingTab').find('span').html(data.gall_sort);
2386                        var $gallMenuPeriodTab = $('#wrapGallMenuPeriod');
2387                        if (hashGall.search(/choice=/) === -1 && hashGall.search(/global=/) === -1 && hashGall.search(/keyword=/) === -1 && hashGall.search(/market=/) === -1)
2388                            $gallMenuPeriodTab.show();
2389                        else
2390                            $gallMenuPeriodTab.hide();
2391                        $gallMenuPeriodTab.find('span').html(data.gall_range);
2392
2393                        //update gallery parameters
2394                        var $gallMenuPeriodContent = $('#gallMenuPeriodContent');
2395                        $gallMenuPeriodContent.find("a").each(function(i, a) {
2396                            $(a).attr('href', data.hu + 'gallery.php#' + getCurrentSelectionParam(hashGall) + '&range=' + $(a).attr('data-range') + getCurrentCategoryParam(hashGall) + getCurrentGalleryParam(hashGall) + '&page=1');
2397                        });
2398
2399                        var $gallSortNoA = $('#gallSortNoA');
2400                        $gallSortNoA.attr('href', data.hu + 'gallery.php#' + getCurrentSelectionParam(hashGall) + getCurrentRangeParam(hashGall) + getCurrentCategoryParam(hashGall) + getCurrentGalleryParam(hashGall) + '&nosort=1&page=1');
2401                        var $gallSortRatingA = $('#gallSortRatingA');
2402                        $gallSortRatingA.attr('href', data.hu + 'gallery.php#' + getCurrentSelectionParam(hashGall) + getCurrentRangeParam(hashGall) + getCurrentCategoryParam(hashGall) + getCurrentGalleryParam(hashGall) + '&sort=rating&page=1');
2403
2404
2405                        //  $('#gallMenuPeriodContent a').each(function() {
2406                        //     var range = $(this).data('range');
2407                        //     var newHref = data.hu + 'gallery.php#' + getCurrentSelectionParam(hashGall) + getCurrentCategoryParam(hashGall) + getCurrentGalleryParam(hashGall) + getCurrentSortParam(hashGall) + '&range=' + range;
2408                        //     $(this).attr('href', newHref);
2409                        // });
2410
2411
2412                        //////////////////////////////////////////////////////////////////
2413                        $gallAjax.html(buildGall(hashGall, data.ps)).css({
2414                            "margin-top": "0"
2415                        });
2416
2417                        updateIeNudeThumbs($gallAjax);
2418
2419                        isLastPage = data.isLastPage;
2420
2421                        let m = 10;
2422                        if (hashGall.search(/id_auth_photo=/) !== -1) m = 20;
2423
2424                        resizeToEqualHeight($("#gallAjax .imgBoxWrap"), false, undefined, undefined, m, true); //, tmpGallRowHeight, tmpMaxRowHeight, tmpMargin, tmpGallAspectRatio); 
2425
2426                        if (utils.isTouch() && !isMobVer)
2427                            $contentDiv.find(".aFullPage").show();
2428
2429                        if (typeof ga !== "undefined") {
2430                            ga("send", "pageview", {
2431                                "page": window.location.pathname + window.location.search + window.location.hash,
2432                                "title": document.title
2433                            });
2434                            if (typeof isAuthorTrack !== "undefined")
2435                                ga("author.send", "pageview", {
2436                                    "page": window.location.pathname + window.location.search + window.location.hash,
2437                                    "title": document.title
2438                                });
2439                        }
2440                        if ($.browser.mozilla && parseFloat($.browser.version) <= 1.8) {
2441                            $(".imgBoxWrap > *").css("float", "left").css("margin-right", "10px");
2442                        }
2443                        if ($.browser.opera && parseFloat($.browser.version) < 9.5) {
2444                            $(".imgBoxWrap").css("text-align", "left");
2445                            $(".imgBoxWrap > *").css("margin-right", "10px");
2446                        }
2447
2448                        if (isShareToView && cookie.getCookie("share_views_cnt") >= 5 && cookie.getCookie("share_post_id") == null) {
2449                            closePreviewPopupGlobal();
2450
2451                            $("#previewOverlay2").css({
2452                                "background-color": "rgba(0, 0, 0, .45)"
2453                            }).delay(5000).fadeIn(500);
2454                            $("#shareToView").delay(5000).fadeIn(500);
2455                            $("#signClose").delay(8500).fadeIn(0);
2456                        }
2457                    } else {
2458                        if (urlType == 'post_comm') {
2459                            $("#showAllCommA").hide();
2460                            if (typeof twemoji !== 'undefined')
2461                                var commWithEmojis = twemoji.parse(data.comm, { folder: 'svg', ext: '.svg' });
2462                            else
2463                                var commWithEmojis = data.comm;
2464                            $("#comm0").html(commWithEmojis);
2465                            updateQuoteHover($("#contentDiv"));
2466                            if (!utils.isTouch()) {
2467                                $('#comm0 .commButtonsTd').hover(function() {
2468                                    $('#commButtons' + $(this).attr('id').substring(13)).show();
2469                                }, function() {
2470                                    $('#commButtons' + $(this).attr('id').substring(13)).hide();
2471                                });
2472                            } else {
2473                                $contentDiv.find(".commButtons").show();
2474                            }
2475                        } else {
2476                            $gallAjax.html(data.ps);
2477                            resizeToEqualHeight($gallAjax.find(".imgBoxWrap"), false, undefined, undefined, m, true); //, tmpGallRowHeight, tmpMaxRowHeight, tmpMargin, tmpGallAspectRatio);
2478
2479                            if ($.browser.chrome)
2480                                $gallAjax.css("padding-left", "0");
2481
2482                            if (typeof ga !== "undefined") {
2483                                ga("send", "pageview", {
2484                                    "page": window.location.pathname + window.location.search + window.location.hash,
2485                                    "title": document.title
2486                                });
2487                                if (typeof isAuthorTrack !== "undefined")
2488                                    ga("author.send", "pageview", {
2489                                        "page": window.location.pathname + window.location.search + window.location.hash,
2490                                        "title": document.title
2491                                    });
2492                            }
2493                        }
2494                    }
2495                }
2496
2497                if (urlType == 'post_comm') {
2498                    $("#postCommDiv").show();
2499                    $("#loaderComm").hide();
2500                    if (isCommPosted) {
2501                        setTimeout("$('#comment').val('')", 500);
2502                        isCommPosted = false;
2503                    }
2504                } else {
2505                    var gallPath = getEl("gallPath");
2506                    var gallPath2 = getEl("gallPath2");
2507                    var authInfoBlk = getEl("authInfoBlk");
2508
2509                    //var headerBottom = getEl("headerBottom");
2510                    //var hHeight = $("#headerCover").innerHeight() - 330 + 'px';
2511                    //var hHeight2 = $("#headerCover").innerHeight() - 330 + 'px';
2512
2513                    gallPath.innerHTML = data.path;
2514                    if (gallPath2) {
2515                        gallPath2.innerHTML = data.path;
2516                    }
2517                    if (data.path) {
2518                        if (gallPath) {
2519                            gallPath.style.display = 'block';
2520
2521                        }
2522                        //if (headerBottom)
2523                        //   headerBottom.style.top = hHeight;
2524
2525                        //if (authInfoBlk) authInfoBlk.style.top = '0px';
2526                    } else {
2527                        if (gallPath) {
2528                            gallPath.style.display = 'none';
2529
2530                        }
2531                        // if (headerBottom)
2532                        //     headerBottom.style.top = hHeight2;
2533
2534                        //if (authInfoBlk) authInfoBlk.style.top = '70px';
2535                    }
2536
2537                    getEl("gallSort").innerHTML = data.s + " &nbsp;" + data.sl;
2538                    getEl("imgPerPage").innerHTML = data.ipp;
2539                }
2540
2541                var pagerTop = data.pt;
2542                var pagerBottom = data.pb;
2543
2544                if (pagerTop != "")
2545                    $("#pagerTop").html(pagerTop).show();
2546                else
2547                    $("#pagerTop").text("");
2548
2549                if (pagerBottom != "")
2550                    $("#pagerBottom").html(pagerBottom).show();
2551                else
2552                    $("#pagerBottom").text("");
2553
2554                $("#ajaxq").html(data.ajaxq);
2555
2556                isLoadingGall = false;
2557
2558                scrollTopPos = 0;
2559
2560                if (urlType == 'post_comm') {
2561                    if (hash.search(/page=/) !== -1) {
2562                        scrollTopPos = $('#wrapWorkComm').offset().top - 80; 
2563                        scrollPage(scrollTopPos);
2564                    } else {
2565                        scrollTopPos = $('.commNrA').last().offset().top - 80; 
2566                        scrollPage(scrollTopPos);
2567                    }
2568                } else if (urlType == 'get_gallery') {
2569                    if (hash.search(/id_auth_photo=/) !== -1 && hash.search(/id_serie=/) == -1) { 
2570                        if (isAuthCover)
2571                            scrollTopPos = $('#authProfileNew').offset().top - 520; 
2572                        scrollPage(scrollTopPos);
2573                    } else if (hash.search(/recs=/) !== -1 || hash.search(/favor=/) !== -1 || hash.search(/comm_give=/) !== -1 || hash.search(/comm_got=/) !== -1 ) { // || hash.search(/id_serie=/) !== -1
2574                        if (isAuthCover)
2575                            scrollTopPos = $('#authProfileNew').offset().top - 520; 
2576                        scrollPage(scrollTopPos);
2577                    } else if (hash.search(/id_serie=/) !== -1) {
2578                        // ok
2579
2580                    } else {
2581                        scrollPage(0);
2582                        // ok
2583                    }
2584                } else if (urlType == 'get_auth_more') {
2585                    if (isAuthCover)
2586                        scrollTopPos = $('#authProfileNew').offset().top - 520; 
2587                    scrollPage(scrollTopPos);
2588                }
2589
2590                
2591
2592                // decide if "scrollToTop" is needed
2593                log('urlType:', urlType);
2594                log('hash:', hash);
2595
2596
2597
2598
2599
2600                // // do, the same scrolling, to make sure that scrolled to needed postion
2601                // setTimeout(function() {
2602                //     scrollTopPos = 0;
2603
2604                //     if (urlType == 'post_comm') {
2605                //         if (hash.search(/page=/) !== -1) {
2606                //             scrollTopPos = $('#wrapWorkComm').offset().top - 80; console.log('80-3');
2607                //         } else {
2608                //             scrollTopPos = $('.commNrA').last().offset().top - 80; console.log('80-4');
2609                //         }
2610                //     } else if (urlType == 'get_gallery') {
2611                //         if (hash.search(/id_auth_photo=/) !== -1) {
2612                //             if (isAuthCover)
2613                //                 scrollTopPos = $('#authProfileNew').offset().top - 100; console.log('140-2');
2614                //         } else if (hash.search(/recs=/) !== -1 || hash.search(/favor=/) !== -1 || hash.search(/comm_give=/) !== -1 || hash.search(/comm_got=/) !== -1 || hash.search(/id_serie=/) !== -1) {
2615                //             if (isAuthCover)
2616                //                 scrollTopPos = $('#authProfileNew').offset().top - 308; console.log('308-3');
2617                //         } else if (hash.search(/marketplace=/) !== -1) {
2618                //             // ok
2619                //         } else {
2620                //             // ok
2621                //         }
2622                //     } else if (urlType == 'get_auth_more') {
2623                //         if (isAuthCover)
2624                //             scrollTopPos = $('#authProfileNew').offset().top - 308; console.log('308-4');
2625                //     }
2626
2627                //     scrollPage(scrollTopPos);
2628
2629                //     log('scrollTop:', $(document).scrollTop());
2630                // }, 500);
2631
2632
2633
2634
2635
2636
2637
2638
2639                if (urlType == 'get_auth_followers') {
2640                    $('#authorWorks').css('width', 'calc(100% - 6px)').css('border-radius', '0px');
2641                    $('.gallAjaxAuthor').css('width', '1190px').css('margin', '0 auto');
2642                    $('#pagerBottom').css('padding-right', '27px');
2643                }
2644            }
2645        });
2646    }
2647}
2648
2649function setCode(code) {
2650    var el = getEl('comment');
2651    var textVal = el.value;
2652    var sta = textVal.length;
2653    var end = sta;
2654    if (isIE && document.selection) {
2655        var range = document.selection.createRange();
2656        var stored_range = range.duplicate();
2657        stored_range.moveToElementText(el);
2658        stored_range.setEndPoint('EndToEnd', range);
2659        el.selectionStart = stored_range.text.length - range.text.length;
2660        el.selectionEnd = el.selectionStart + range.text.length;
2661        sta = el.selectionStart;
2662        end = el.selectionEnd;
2663    } else {
2664        if (el.selectionStart == undefined) {
2665            var r = document.selection.createRange();
2666            sta = r.start;
2667            end = r.end;
2668        } else {
2669            sta = el.selectionStart;
2670            end = el.selectionEnd;
2671        }
2672    }
2673    var selText = textVal.substring(sta, end);
2674    if (code == 'url')
2675        var openCode = '[' + code + '=url]';
2676    else
2677        var openCode = '[' + code + ']';
2678    var closeCode = '[/' + code + ']';
2679    textVal = textVal.substring(0, sta) + openCode + textVal.substring(sta, end) + closeCode + textVal.substring(sta + selText.length);
2680    el.value = textVal;
2681}
2682
2683function setCode2(code) {
2684    var el = getEl('previewCommArea');
2685    var textVal = el.value;
2686    var sta = textVal.length;
2687    var end = sta;
2688    if (isIE && document.selection) {
2689        var range = document.selection.createRange();
2690        var stored_range = range.duplicate();
2691        stored_range.moveToElementText(el);
2692        stored_range.setEndPoint('EndToEnd', range);
2693        el.selectionStart = stored_range.text.length - range.text.length;
2694        el.selectionEnd = el.selectionStart + range.text.length;
2695        sta = el.selectionStart;
2696        end = el.selectionEnd;
2697    } else {
2698        if (el.selectionStart == undefined) {
2699            var r = document.selection.createRange();
2700            sta = r.start;
2701            end = r.end;
2702        } else {
2703            sta = el.selectionStart;
2704            end = el.selectionEnd;
2705        }
2706    }
2707    var selText = textVal.substring(sta, end);
2708    if (code == 'url')
2709        var openCode = '[' + code + '=url]';
2710    else
2711        var openCode = '[' + code + ']';
2712    var closeCode = '[/' + code + ']';
2713    textVal = textVal.substring(0, sta) + openCode + textVal.substring(sta, end) + closeCode + textVal.substring(sta + selText.length);
2714    el.value = textVal;
2715}
2716
2717function setQuote() {
2718    var obj = document.selection;
2719    var txtArea = getEl('comment');
2720    var newTxt = '';
2721    if (typeof(obj) != "undefined" && document.selection.type == "Text") {
2722        range = obj.createRange();
2723        newTxt = txtArea.value + '[quote]' + range.text + '[/quote]\n\n';
2724    } else if (window.getSelection && window.getSelection() != "") {
2725        newTxt = txtArea.value + '[quote]' + window.getSelection() + '[/quote]\n\n';
2726    } else {
2727        newTxt = txtArea.value + '[quote] ... [/quote]\n\n';
2728    }
2729    txtArea.focus();
2730    txtArea.value = newTxt;
2731}
2732
2733function setQuotePop() {
2734    var obj = document.selection;
2735    var txtArea = getEl('previewCommArea');
2736    var newTxt = '';
2737    if (typeof(obj) != "undefined" && document.selection.type == "Text") {
2738        range = obj.createRange();
2739        newTxt = txtArea.value + '[quote]' + range.text + '[/quote]\n\n';
2740    } else if (window.getSelection && window.getSelection() != "") {
2741        newTxt = txtArea.value + '[quote]' + window.getSelection() + '[/quote]\n\n';
2742    } else {
2743        newTxt = txtArea.value + '[quote] ... [/quote]\n\n';
2744    }
2745    txtArea.focus();
2746    txtArea.value = newTxt;
2747}
2748
2749function getNextUploadTime() {
2750    $.get(ajaxFld + "get_next_upload_time.php", {}, function(data) {
2751        NProgress.done();
2752        if (data == '') {
2753            $("#gallUploadLnk").html(ploc.add_work1_loc + ' <a href="/add.php" style="text-decoration:underline;" title="' + ploc.in_gall_note_loc + '">' + ploc.in_gall_loc + '</a> ' + ploc.add_work2_loc);
2754            $("#uploadUploadNote1").html(ploc.gallery_form_upload_warn_loc);
2755        } else {
2756            $("#gallUploadLnk").html(data);
2757            $("#uploadUploadNote1").html('');
2758        }
2759    });
2760}
2761
2762function trim(str) {
2763    str = '' + str;
2764    var re = /^ */;
2765    var res = str.replace(re, '');
2766    re = / *$/;
2767    return (res.replace(re, ''));
2768}
2769
2770function ShowAlert(sAlertString, hForm, FormElement) {
2771    alert(sAlertString);
2772    if ((!hForm.elements[FormElement].disabled) && (!hForm.elements[FormElement].length)) {
2773        if (hForm.elements[FormElement].type != 'hidden')
2774            hForm.elements[FormElement].focus();
2775    }
2776    return false;
2777}
2778
2779function GetValue(el) {
2780    if ((el.length) && (!el.options)) {
2781        for (var i = 0; i < el.length; i++)
2782            if (el[i].checked)
2783                return el[i].value;
2784        return '';
2785    } else
2786        return el.value;
2787}
2788
2789function is_leap_year(year) {
2790    return ((year % 4 == 0) && !((year % 100 == 0) && (year % 400 != 0)));
2791}
2792
2793function isValidEmail(str) {
2794    var re = /^ *([a-z0-9_-]+\.)*[a-z0-9_-]+@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2,20})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) *$/;
2795    return (re.test(str.toLowerCase()));
2796}
2797
2798function isValidDomain(str) {
2799    var re = /^[a-z0-9]+[a-z0-9_\-]*[a-z0-9]+$/;
2800    return (re.test(str.toLowerCase()));
2801}
2802
2803function isValidPhone(phonestr) {
2804    var re = /^\(?[0-9]{3}\)?[\-\. ]*[0-9]{3}[\-\. ]*[0-9]{4}$/;
2805    return re.test(phonestr);
2806}
2807
2808function isValidNumber(num_str) {
2809    var re = /^[0-9]+(\.?[0-9]+)?$/;
2810    return re.test(num_str);
2811}
2812
2813function isValidUsDate(str) {
2814    var re = /^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/;
2815    return re.test(str);
2816}
2817
2818function isValidEuDate(str) {
2819    var re = /^([0-9]{1,2})\.([0-9]{1,2}\.([0-9]{4}))$/;
2820    return re.test(str);
2821}
2822
2823function urlencode(str) {
2824    var hexStr = function(dec) {
2825        return '%' + dec.toString(16).toUpperCase();
2826    };
2827    var ret = '',
2828        unreserved = /[\w.-]/;
2829    str = (str + '').toString();
2830    for (var i = 0, dl = str.length; i < dl; i++) {
2831        var ch = str.charAt(i);
2832        if (unreserved.test(ch)) {
2833            ret += ch;
2834        } else {
2835            var code = str.charCodeAt(i);
2836            if (code === 32) {
2837                ret += '+';
2838            } else if (code < 128) {
2839                ret += hexStr(code);
2840            } else if (code >= 128 && code < 2048) {
2841                ret += hexStr((code >> 6) | 0xC0);
2842                ret += hexStr((code & 0x3F) | 0x80);
2843            } else if (code >= 2048 && code < 65536) {
2844                ret += hexStr((code >> 12) | 0xE0);
2845                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
2846                ret += hexStr((code & 0x3F) | 0x80);
2847            } else if (code >= 65536) {
2848                ret += hexStr((code >> 18) | 0xF0);
2849                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
2850                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
2851                ret += hexStr((code & 0x3F) | 0x80);
2852            }
2853        }
2854    }
2855    return ret;
2856}
2857
2858function createOverlay(elem, overDivId, opacity, closeClick, closeEsc) {
2859    elem.attr('rel', '#' + overDivId).overlay({
2860        expose: {
2861            loadSpeed: 10,
2862            opacity: opacity,
2863            color: '#333'
2864        },
2865        closeOnClick: closeClick,
2866        closeOnEsc: closeEsc,
2867        fixed: false,
2868        onClose: function() {
2869            setTimeout(function() {
2870                $("#resultMsg").text("").fadeOut();
2871            }, 2000);
2872        }
2873    });
2874}
2875
2876var $myWnd = $(window);
2877
2878var commandPressed = false;
2879var ctrlPressed = false;
2880$myWnd.keydown(function(evt) {
2881    if (evt.which == 17) // ctrl
2882        ctrlPressed = true;
2883    else if (isMac() && evt.which == 91) // command
2884        commandPressed = true;
2885}).keyup(function(evt) {
2886    if (evt.which == 17) // ctrl
2887        ctrlPressed = false;
2888    else if (isMac() && evt.which == 91) // command
2889        commandPressed = false;
2890});
2891
2892function scrollPage(pos) {
2893
2894    //setTimeout(function() {
2895
2896    scrollTopMenu(pos);
2897
2898
2899    //$(window).trigger('scroll');
2900
2901    /*
2902    if (pos) {
2903        $(".parallax-slider").animate({
2904            opacity: 1
2905        }, 500);
2906    }
2907    */
2908
2909    //}, 100);
2910}
2911
2912function closePreviewPopupGlobal() {
2913
2914    $("#previewPopup").scrollTop(0);
2915    $("#previewPopup").hide();
2916
2917    $("#previewOverlay").hide();
2918    $("#previewPrevIcon").hide();
2919
2920    $("body").css({
2921        overflow: "auto",
2922        "margin-right": "0"
2923    });
2924    isOverlay = false;
2925    imgPos = 0;
2926    $("#imgPopup").attr("src", "/1.gif");
2927    $("#imgPopup").find("image").remove();
2928    //resizeToEqualHeight($("#gallAjax").find(".imgBoxWrap"), false);
2929
2930    //if (window.history.replaceState) {
2931    //   window.history.replaceState(closePopupUrl, closePopupUrl, closePopupUrl);
2932    //}
2933
2934    if (typeof viewer !== 'undefined')
2935        viewer = viewer.destroy();
2936}
2937
2938function getMainImage(src) {
2939    return src.replace(/gridx/g, 'main').replace(/grid/g, 'main').replace(/square/g, 'main');
2940}
2941
2942var id_photo_prev = 0;
2943
2944function initImgArr(id_photo, imgPos, data_src, width, height, ph_name, ian, isCacheImage) {
2945    //log(id_photo, imgPos, data_src, width, height, ph_name, ian, isCacheImage);
2946    
2947    if (typeof imgArr[id_photo] !== "undefined")
2948        return;
2949
2950    //if (imgPos == -1 && typeof imgArr[id_photo] !== "undefined")
2951        //return;
2952
2953    imgArr[id_photo] = new Image();
2954    imgArr[id_photo].imgPos = imgPos;
2955    imgArr[id_photo].data_src = data_src;
2956    imgArr[id_photo].width = width;
2957    imgArr[id_photo].height = height;
2958    imgArr[id_photo].ph_name = ph_name;
2959    imgArr[id_photo].ian = ian;
2960    //imgArr[id_photo].auth_name = '';
2961    //imgArr[id_photo].id_auth = 1;
2962
2963    imgArr[id_photo].id_photo = id_photo;
2964    imgArr[id_photo].id_photo_prev = id_photo_prev;
2965    imgArr[id_photo].id_photo_next = 0;
2966    if (typeof imgArr[id_photo_prev] !== 'undefined')
2967        imgArr[id_photo_prev].id_photo_next = id_photo;
2968    id_photo_prev = id_photo;
2969
2970    if (typeof imgArr[id_photo].loaded === "undefined")
2971        imgArr[id_photo].loaded = 0;
2972
2973    if (isCacheImage) {
2974        imgArr[id_photo].src = getMainImage(data_src);
2975        imgArr[id_photo].addEventListener('load', function() {
2976            imgArr[this.id_photo].loaded = 1;
2977        });
2978    }
2979}
2980
2981function initImgArrByEl(el, imgPos, isCacheImage) {
2982    initImgArr(el.data("idPhoto"), imgPos, el.data("src"), el.data("phW"), el.data("phH"), el.data("phName"), el.data("ian"), isCacheImage);
2983}
2984
2985function findImgArr(el) {
2986    imgPos = 0;
2987    el.find("a.aPopup").each(function(i) {
2988        var isCacheImage = false;
2989        if (imgPos == 0 || imgPos == 1) {
2990            isCacheImage = true;
2991        }
2992        initImgArrByEl($(this), imgPos, isCacheImage);
2993        imgPos++;
2994    });
2995}
2996
2997function updateIeNudeThumbs(el) {
2998    el.find("a.aPopup").each(function(i) {
2999        var el = $(this);
3000
3001        if (isIE && getIEVer() >= 10 && (el.hasClass("blurThumb") || el.find("img").hasClass("blurThumb"))) {
3002            if (el.find("img").length)
3003                el.find("img").attr("src", "1.gif").css({
3004                    "background": bgColor + " url(css/" + theme + "/nu.png) no-repeat 50% 50%/cover"
3005                });
3006            else
3007                el.css({
3008                    "background": bgColor + " url(css/" + theme + "/nu.png) no-repeat 50% 50%/cover"
3009                });
3010        }
3011    });
3012}
3013
3014function dropDownMenuShow(menuName) {
3015
3016    $('#header.authProfileHeader').show();
3017    if (menuName) {
3018        menuName.show();
3019
3020        setTimeout(function() {
3021            menuName.removeClass('animOut');
3022            menuName.addClass('anim');
3023
3024        }, 10);
3025
3026        setTimeout(() => menuName.show(), 50);
3027    }
3028}
3029
3030function dropDownMenuHide(menuName) {
3031    // setTimeout(function() {
3032    if (menuName) {
3033        menuName.removeClass('anim');
3034        menuName.addClass('animOut');
3035
3036        setTimeout(function() {
3037            menuName.hide();
3038        }, 120);
3039    }
3040    //}, 50);
3041}
3042
3043function getRecImages() {
3044    var recommendedImagesArray = new Array();
3045    if (window.localStorage["recommendedImages"]) {
3046        recommendedImagesArray = JSON.parse(localStorage.getItem('recommendedImages'));
3047    }
3048
3049    return recommendedImagesArray;
3050
3051}
3052
3053function setRecWorks() {
3054    recsArr = new Array();
3055    var tmpArr = getRecImages();
3056    tmpArr.forEach(function(item, i, tmpArr) {
3057        recsArr[i] = parseInt(tmpArr[i], 10);
3058    });
3059    var pageImages = new Array();
3060
3061    $('a.imgThumb').each(function(i) {
3062        pageImages[i] = $(this).data('id-photo');
3063    });
3064
3065    var intersection = pageImages.filter(function(x) { recsArr.includes(x) });
3066    intersection.forEach(function(item, i, intersection) {
3067        $('#ratingIcon' + item).html('&#xe934;');
3068    });
3069}
3070
3071function storeRecsArray(idImg) {
3072    var arr = getRecImages();
3073
3074    if (jQuery.inArray(idImg, arr) == -1) {
3075        arr.push(idImg);
3076        localStorage.setItem('recommendedImages', JSON.stringify(arr));
3077    }
3078}
3079
3080function closePreviewPopup() {
3081    var $body = $("body");
3082    var $previewPrevIcon = $("#previewPrevIcon");
3083    var $previewOverlay = $("#previewOverlay");
3084    var $previewPopup = $("#previewPopup");
3085    var $imgPopup = $("#imgPopup");
3086    var $previewNext = $("#previewNext");
3087
3088    
3089    $("#addCommImgInput").attr("data-id-photo", "");
3090
3091    //setTimeout(function() {
3092        $previewPopup.scrollTop(0);
3093    //}, 200);
3094    $previewPopup.fadeOut(100, 'linear');
3095
3096
3097    //log('closing popup');
3098    //$previewPopup.hide();
3099
3100    $previewOverlay.hide();
3101    $previewPrevIcon.hide();
3102
3103    setTimeout(function() {
3104        $body.css({
3105            overflow: "auto",
3106            "margin-right": "0"
3107        });
3108
3109    }, 200);
3110
3111    clearPreviewComm();
3112    isOverlay = false;
3113    imgPos = 0;
3114    $imgPopup.attr("src", "/1.gif");
3115    $imgPopup.find("image").remove();
3116
3117    $("#previewPhName").text(' ');
3118
3119
3120
3121    //resizeToEqualHeight($("#gallAjax").find(".imgBoxWrap"), false);
3122
3123    //if (window.history.replaceState) {
3124    //   window.history.replaceState(closePopupUrl, closePopupUrl, closePopupUrl);
3125    //}
3126    $("#previewRec").children('a').remove();
3127}
3128
3129function clearPreviewComm() {
3130    var comment = getEl("previewCommArea");
3131    if (comment != null)
3132        comment.value = '';
3133}
3134
3135// $(window).on("load", function() {
3136//   // When the page has loaded
3137//   $("body").animate({opacity: 1}, 500);
3138// });
3139
3140$(document).ready(function() {
3141
3142
3143$("body").on("click", ".spoiler", function(){
3144    $(this).removeClass("spoiler invert repeat");
3145});
3146
3147
3148
3149    $(".commQuote, .commQuotePopup").on('click', function() {
3150
3151        if (!$(this).hasClass('quoteOpen')) {
3152            $(this).addClass('quoteOpen');
3153        } else {
3154            $(this).removeClass('quoteOpen');
3155        }
3156
3157    });
3158
3159    $(".offerHeader").on('click', function() {
3160
3161        if (!$("#offerBlock").hasClass('offerClose')) {
3162            $("#offerBlock").addClass('offerClose');
3163        } else {
3164            $("#offerBlock").removeClass('offerClose');
3165        }
3166
3167    });
3168
3169    $('#copyIcon').click(function(e) {
3170        var input = document.body.appendChild(document.createElement("input"));
3171        input.value = '0xf31fc7260c433389f223b8a80ecbe73740eaa0ed';
3172        //input.focus();
3173        input.select();
3174        document.execCommand('copy');
3175
3176        document.body.removeChild(input);
3177
3178    });
3179
3180    var $selector = $("#selector");
3181    var $selectorMenu = $("#selectorMenu");
3182    var timer;
3183
3184    $selector.click(function() {
3185        $selectorMenu.css('display', 'inline-block');
3186        //$('#qSearch').css('border-radius','30px 30px 30px 0');
3187    });
3188
3189    $(document.body).click(function(e) {
3190        if (!$(e.target).is("#selectorMenu") && !$(e.target).is("#selector") && !$(e.target).is("#containerSelect")) {
3191            $selectorMenu.hide();
3192            if (document.getElementById("searchTD") !== null || document.getElementById("qSearch") !== null) {
3193                borderRadiusDefault();
3194            }
3195        }
3196    });
3197
3198    // init global search
3199    $whereToSearch = 'global';
3200
3201    $("#stockSelect").click(function() {
3202        $("#containerSelect").text(ploc.stock_photos_loc);
3203
3204        $whereToSearch = 'market';
3205    });
3206
3207    $("#artSelect").click(function() {
3208        $("#containerSelect").text(ploc.art_photos_loc);
3209
3210        $whereToSearch = 'keyword';
3211    });
3212
3213    $("#allSelect").click(function() {
3214        $("#containerSelect").text(ploc.all_photos_loc);
3215
3216        $whereToSearch = 'global';
3217    });
3218
3219    // update search type drop down
3220    var hashGall = window.location.hash;
3221    if (hashGall.search('keyword=') == 1) {
3222        $("#artSelect").click();
3223    } else if (hashGall.search('market=') == 1) {
3224        $("#stockSelect").click();
3225    } else if (hashGall.search('global=') === 1) {
3226        $("#allSelect").click();
3227    }
3228
3229    var $myWndW, $myWndH;
3230
3231    setTimeout(function() {
3232        //setRecWorks();
3233
3234        $myWndW = $myWnd.width();
3235        $myWndH = $myWnd.height();
3236    }, 500);
3237
3238    var lastPos;
3239
3240    var $cookieWarn = $("#cookieWarn");
3241    if (cookie.getCookie("cookieWarn")) $cookieWarn.hide();
3242    else $cookieWarn.show();
3243
3244    $("#cookieWarnClose").on("click", function(e) {
3245        $cookieWarn.hide();
3246        cookie.setMinutesCookie("cookieWarn", 1, 60 * 24 * 365);
3247        e.preventDefault();
3248    });
3249
3250    /* -----------------------------------------------  */
3251    var $body = $("body");
3252    var $contentDiv = $("#contentDiv");
3253    var $previewOverlay = $("#previewOverlay");
3254    var $previewPopup = $("#previewPopup");
3255    var $imgPopup = $("#imgPopup");
3256    var $previewNext = $("#previewNext");
3257    var $previewPrevIcon = $("#previewPrevIcon");
3258    var $shareToView = $("#shareToView");
3259    var isAuthBlocked = false;
3260
3261    updateIeNudeThumbs($contentDiv);
3262
3263    var $previewCommBtn = $("#previewCommBtn");
3264    //var $workCommBB = $("#workCommBB");
3265    //var $add_comm_btn = $("#add_comm_btn");
3266
3267    var $previewCommArea = $('#previewCommArea');
3268    //var $comment = $('#comment');
3269
3270    $previewCommArea.on("focus", function(e) { //$previewCommBtn.css({visibility: 'visible'});
3271        //$workCommBB.css({visibility: 'visible'});
3272    });
3273
3274    function clearPreviewComm() {
3275        var comment = getEl("previewCommArea");
3276        if (comment != null)
3277            comment.value = '';
3278    }
3279
3280    var $fullScreenWrapPopup = $('#fullScreenWrapPopup');
3281
3282    $fullScreenWrapPopup.bind('mousewheel DOMMouseScroll', function(e) {
3283
3284        //var screenH = window.innerHeight;
3285        //var screenW = window.innerWidth;
3286        var screenRatio = screenW / screenH;
3287        var ivImage2 = document.getElementById('ivImage2'); // Этого элемента нету в коде пока не вызван iv-viewer поэтому объявляя его в ready получаешь ничего. 
3288        var ivImageH = 1;
3289        var ivImageW = 1;
3290
3291        if (ivImage2) {
3292            ivImageH = parseInt(ivImage2.style.height);
3293            ivImageW = parseInt(ivImage2.style.width);
3294        }
3295
3296        var imgRatio = ivImageW / ivImageH;
3297
3298        //log('ivImageH='+ivImageH+' ivImageW='+ivImageW);
3299
3300        if (imgRatio <= screenRatio) var B = ivImageH <= screenH + 70;
3301        else var B = ivImageW <= screenW + 70;
3302
3303        //log('imageH='+ivImageH+' screenH='+screenH);
3304
3305        if (!(e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) && B) {
3306
3307            if (FSOpen) closePreviewPopup();
3308            closeFScreen();
3309
3310        }
3311    });
3312
3313    var fullScreenWrapPopup = document.getElementById('fullScreenWrapPopup');
3314
3315    if (fullScreenWrapPopup) {
3316        fullScreenWrapPopup.addEventListener("click", function(e) {
3317            if (e.target.className === 'iv-image-view') {
3318
3319                closePreviewPopup();
3320                closeFScreen();
3321
3322            }
3323
3324            return false;
3325        });
3326
3327    }
3328
3329    function arrowsShow() {
3330        $('.prevLeft, .nextRight').show();
3331    }
3332
3333    function arrowsHide() {
3334        $('.prevLeft, .nextRight').hide();
3335    }
3336
3337    function gotoNextPrevPreviewPopup(dir) {
3338        //setLastPos();
3339
3340        if (typeof viewer !== 'undefined')
3341            viewer = viewer.destroy();
3342
3343        var $gallAjax = {};
3344        if ($("#panelLastWorks").length)
3345            $gallAjax = $("#panelLastWorks");
3346        else if ($("#authorWorks").length)
3347            $gallAjax = $("#authorWorks");
3348        else
3349            $gallAjax = $("#gallAjax");
3350
3351        var $NextPrevLink = {};
3352        if (dir == 1)
3353            $NextPrevLink = $("#NextLink");
3354        else
3355            $NextPrevLink = $("#PrevLink");
3356        
3357        if (imgCurId != 0) {
3358            if (dir == 1)
3359                imgCurId = imgArr[imgCurId].id_photo_next;
3360            else
3361                imgCurId = imgArr[imgCurId].id_photo_prev;
3362        }
3363
3364        // !!!
3365        //log('imgCurId', imgCurId, 'visible', $gallAjax.find("#imgBoxNew" + imgCurId).is(':visible'), 'isInfinite', isInfinite);
3366
3367        if (imgCurId != 0) {
3368            imgPos += dir;
3369
3370            $("#previewPhName").text(' '); 
3371
3372            updatePreviewPopup();
3373            clearPreviewComm();
3374
3375            if ($gallAjax.find("#imgBoxNew" + imgCurId).is(':visible')) {
3376                // ok, do nothing
3377            }
3378            else {
3379                if (!isInfinite && $NextPrevLink.length) {
3380                    window.location.href = $NextPrevLink.attr("href");
3381                }
3382            }
3383        }
3384        else {
3385            closePreviewPopup();
3386
3387            if ($NextPrevLink.length) {
3388                window.location.href = $NextPrevLink.attr("href");
3389            }
3390        }
3391
3392        /*
3393        if (imgCurId > 0 && $gallAjax.find("#imgBoxNew" + imgCurId).is(':visible')) {
3394            imgPos += dir;
3395            updatePreviewPopup();
3396            clearPreviewComm();
3397        } else if ($NextPrevLink.length && Object.keys(imgArr).length > 1 && !utils.isTouch()) {
3398            //
3399
3400            if (imgCurId > 0) {
3401                imgPos += dir;
3402                updatePreviewPopup();
3403                clearPreviewComm();
3404            }
3405        } else {
3406            closePreviewPopup();
3407        }
3408        */
3409    }
3410
3411    function gotoNextPreviewPopup() {
3412        gotoNextPrevPreviewPopup(1);
3413    }
3414
3415    function gotoPrevPreviewPopup() {
3416        gotoNextPrevPreviewPopup(-1);
3417    }
3418
3419    function getPopupSize() {
3420        var imgCoof = 1;
3421        var imgXPad = 200;
3422        var imgYPad = 180; // 180;
3423        // popup padding, to show buttons under image
3424        var imgW = 1200;
3425        var imgH = 600;
3426        if (imgArr[imgCurId]) {
3427            imgW = imgArr[imgCurId].width;
3428            imgH = imgArr[imgCurId].height;
3429        }
3430        if (imgW > ($myWndW - imgXPad)) {
3431            imgCoof = ($myWndW - imgXPad) / imgW;
3432            imgW = imgCoof * imgW;
3433            imgH = imgCoof * imgH;
3434        }
3435        if (imgH > ($myWndH - imgYPad)) {
3436            imgCoof = ($myWndH - imgYPad) / imgH;
3437            imgW = imgCoof * imgW;
3438            imgH = imgCoof * imgH;
3439        }
3440        imgW = Math.round(imgW);
3441        imgH = Math.round(imgH);
3442
3443        return [imgW, imgH];
3444    }
3445
3446    var popupSize = getPopupSize();
3447    var imgW = popupSize[0];
3448    var imgH = popupSize[1];
3449
3450    /*
3451    setTimeout(function(){
3452        log('imgW='+imgW+' imgH='+imgH+' $myWndH='+$myWndH+' window.height='+$(window).innerHeight());
3453    }, 500);
3454    */
3455
3456    /*
3457    $previewNext.css({
3458        width: imgW + "px",
3459        height: imgH + "px"
3460    });
3461
3462    $imgPopup.css({
3463        width: imgW + "px",
3464        height: imgH + "px"
3465    });
3466    */
3467
3468    var $previewGoad = $("#previewGoad");
3469    var $previewGoadRight = $("#previewGoadRight");
3470    var isPrevBlur = false;
3471    var $gallContainer = $("#gallContainer");
3472
3473    function updatePreviewData(data) {
3474        //$previewGoad.css({height: "0"});
3475
3476        var editor = document.querySelector("#previewCommArea");
3477        if (window.localStorage["TextEditorData"]) {
3478            editor.value = window.localStorage["TextEditorData"];
3479        }
3480        editor.addEventListener("keyup", function() {
3481            window.localStorage["TextEditorData"] = editor.value;
3482        });
3483
3484        //setLastPos();
3485
3486        data = data.responseJSON || false;
3487        if (data && typeof imgArr[imgCurId] !== "undefined") {
3488            //if (window.history.replaceState) {
3489            //   window.history.replaceState('/work/' + data.photo[0].id_photo, '/work/' + data.photo[0].id_photo, '/work/' + data.photo[0].id_photo);
3490            //}
3491
3492            var in_gals = $("#in_gals");
3493
3494            $(".addGalLink, .remGalLink").data("idphoto", data.photo[0].id_photo).attr("data-idphoto", data.photo[0].id_photo);
3495            $(".addCommImgInput").data("id-photo", data.photo[0].id_photo).attr("data-id-photo", data.photo[0].id_photo);
3496            $(".remGalLink").hide();
3497
3498            if (data.photo[0].gals != '') {
3499                in_gals.show();
3500
3501                $("#in_gals_wrap").html(data.photo[0].gals_html);
3502
3503                var gals_array = data.photo[0].gals.split(",");
3504                $.each(gals_array, function(i, val){
3505                    $("#remGall"+val).show();
3506                });
3507            } else {
3508                in_gals.hide();
3509                $("#in_gals_wrap").html("");
3510            }
3511
3512            if (data.photo[0].ph_status == 0) {
3513                $imgPopup.attr("src", "/1.gif");
3514                $imgPopup.find("image").remove();
3515                $("#authBlockedD").show();
3516                isAuthBlocked = true;
3517            } else {
3518                $imgPopup.show();
3519                $("#authBlockedD").hide();
3520                isAuthBlocked = false;
3521            }
3522
3523            if (data.photo[0].is_allowed_comm == 0) {
3524                $("#workCommBB").hide();
3525                $("#previewCommBox").hide();
3526            } else {
3527                $("#workCommBB").show();
3528                $("#previewCommBox").show();
3529            }
3530
3531            if (data.photo[0].marks == '') {
3532                $("#previewMark").hide();
3533                $("#previewButtons").show();
3534            } else {
3535                $("#previewMarkScale").html(data.photo[0].marks);
3536                $("#previewMark").show();
3537                $("#previewButtons").hide();
3538            }
3539
3540            //imgCurId = imgArr[imgCurId].id_photo;
3541
3542            var work_url = '/work.php?id_photo=' + imgArr[imgCurId].id_photo;
3543            if (domainEnd != 'by')
3544                work_url = '/work/' + imgArr[imgCurId].id_photo;
3545            $("#previewFullA").attr("href", work_url);
3546            //$("#previewPhName").attr("href", work_url);
3547
3548            if (data.photo[0].is_blur == 1 || isPrevBlur) {
3549                isPrevBlur = true;
3550                $("#imgPopupDiv").html(data.photo[0].ph_img);
3551                // !!!
3552                //$imgPopup = $("#imgPopup");
3553                //$previewNext = $("#previewNext");
3554            } else if ($imgPopup.attr("src") != data.photo[0].ph_img_src || $imgPopup.attr("src") == "/1.gif") {
3555                isPrevBlur = false;
3556                // !!! used, to update prev/next photo after viewing blocked author photo
3557                if (!isAuthBlocked) {
3558                    //$imgPopup.attr("src", data.photo[0].ph_img_src);
3559                }
3560            }
3561
3562            var popupSize = getPopupSize();
3563            var imgW = popupSize[0];
3564            var imgH = popupSize[1];
3565
3566            /*
3567            $previewNext.css({
3568                width: imgW + "px",
3569                height: imgH + "px"
3570            });
3571
3572            $imgPopup.css({
3573                width: imgW + "px",
3574                height: imgH + "px"
3575            });
3576            */
3577
3578            $imgPopup.find("image").attr("width", imgW).attr("height", imgH);
3579
3580            /* 
3581            if (imgW < 600) //imgW = 600;
3582            $previewNext.css({
3583                "width": imgW + "px"
3584            });
3585
3586            */
3587            $("#imgPopupNudeWarn").css({
3588                "min-width": "849px",
3589                width: imgW + "px",
3590                height: "px",
3591                "margin-top": (imgH / 2 - 30) + "px"
3592            });
3593
3594            $spoiler_name_class = (data.photo[0].ph_ns == 1) ? 'class="spoiler invert"' : '';
3595            $spoiler_desc_class = (data.photo[0].ph_ds == 1) ? 'class="spoiler inline repeat"' : '';
3596
3597            $("#previewPhName").text(imgArr[imgCurId].ph_name).html('<div '+$spoiler_name_class+'>'+data.photo[0].ph_name+'</div>');
3598
3599            if (isScrollPopup)
3600                $previewPopup.animate({
3601                    scrollTop: 0
3602                }, 100);
3603            isScrollPopup = true;
3604
3605            if (data.photo[0].id_auth == 26 || data.photo[0].id_auth == 1)
3606                $("#haLink").html('<a href=/work.php?id_photo=' + data.photo[0].id_photo + '&id_cat_set=2205 class="saveBtn fineArtBtn popBtn">HA</a>');
3607
3608            $("#previewAuthName").html(data.photo[0].auth_name);
3609            $("#previewDesc").html('<div '+$spoiler_desc_class+'>'+data.photo[0].ph_desc+'</div>');
3610            $("#previewRec").attr('data-ph-rating', data.photo[0].rec_val);
3611            $("#previewRec").html(data.photo[0].rec);
3612            $("#previewHomeAlbum").html(data.photo[0].home_album);
3613            $("#previewFavor").html(data.photo[0].favor);
3614            $("#previewBookmark").html(data.photo[0].bookmark);
3615            $("#previewFineart").html(data.photo[0].fineart);
3616            if (typeof twemoji !== 'undefined')
3617                $("#previewComm").html(twemoji.parse(data.photo[0].comm), { folder: 'svg', ext: '.svg' });
3618            else
3619                $("#previewComm").html(data.photo[0].comm);
3620            $("#previewCommCnt").html(data.photo[0].comm_cnt);
3621            $("#previewCommCnt2").html(data.photo[0].comm_cnt);
3622            if (data.photo[0].all_comm == 0 && data.photo[0].comm_cnt > 5)
3623                $("#showMoreComm").html('<span id="showMoreCommIcon" class="iconArrowDownShowMoreComm">&#xf0e6;</span>' + ploc.show_all_comm_loc);
3624            else
3625                $("#showMoreComm").text("");
3626
3627            if (data.photo[0].ph_ai == "1")
3628                $('#ailabel').addClass('whiteaiicon');
3629            else $('#ailabel').removeClass('whiteaiicon');
3630
3631
3632
3633            if (data.photo[0].comm != "")
3634                $('#discussionHead').addClass('discussionHeadNOBorder').removeClass('discussionHeadBorder');
3635            else
3636                $('#discussionHead').addClass('discussionHeadBorder').removeClass('discussionHeadNOBorder');
3637
3638            $("#previewPhData").html(data.photo[0].ph_data);
3639            $previewGoad.html(data.photo[0].goad);
3640            $previewGoadRight.html(data.photo[0].goad_right);
3641
3642            $("#buyPhotoEthPrice").html(data.photo[0].eth_price);
3643            $("#buyPhotoUsdPrice").html(data.photo[0].photo_price);
3644
3645            $("#buyPhotoWsize").html(data.photo[0].ph_orig_w);
3646            $("#buyPhotoHsize").html(data.photo[0].ph_orig_h);
3647
3648            $("#buyPhotoLicense").html(data.photo[0].photo_license);
3649            $("#buyPhotoCreatorAddress").attr("title", data.photo[0].creator_address);
3650            $("#buyPhotoRelease").html(data.photo[0].model_release);
3651            var stock = (data.photo[0].stock_photo == 0) ? 'Gallery' : 'Marketplace';
3652            $("#buyPhotoType").html(stock);
3653
3654            $("#buyPhotoButtonBuy").attr("data-token-id", data.photo[0].token_id);
3655            $("#buyPhotoButtonAdd").attr({"data-token-id": data.photo[0].token_id, "data-listing-id": data.photo[0].listing_id, "data-image-url": data.photo[0].ph_img_src, "data-nft-name": data.photo[0].ph_name });
3656
3657            var wallet = data.photo[0].creator_address;
3658            trimmed_wallet = wallet.substr(0, 6) + '...' + wallet.substr((wallet.length - 4), wallet.length);
3659
3660            $("#buyPhotoCreatorAddress").html(trimmed_wallet);
3661            $("#buyPhotoTokenId").html(data.photo[0].token_id);
3662
3663            // Offer Block
3664            $(".offerSubmit").attr("data-id", data.photo[0].id_photo);
3665            $("#offerList").html(data.photo[0].offers);
3666
3667            if (data.photo[0].stock_photo != 0) {
3668                $("#previewRec").hide();
3669                $("#previewCommCnt").hide();
3670            } else {
3671                $("#previewRec").show();
3672                $("#previewCommCnt").show();
3673            }
3674
3675            if (data.photo[0].listed_for_sale == 0) {
3676                $("#buyPhotoBlock").hide();
3677                $("#offerBlock").show();
3678            } else {
3679                $("#buyPhotoBlock").show();
3680                $("#offerBlock").hide();
3681            }
3682
3683            updateQuoteHover($('#previewComm'));
3684
3685            if (typeof ga !== "undefined") {
3686                var work_url = '/popup/work.php?id_photo=' + imgArr[imgCurId].id_photo;
3687                if (domainEnd != 'by')
3688                    work_url = '/popup/work/' + imgArr[imgCurId].id_photo;
3689                ga("send", "pageview", {
3690                    "page": work_url,
3691                    "title": imgArr[imgCurId].ph_name
3692                });
3693                if (typeof isAuthorTrack !== "undefined")
3694                    ga("author.send", "pageview", {
3695                        "page": work_url,
3696                        "title": imgArr[imgCurId].ph_name
3697                    });
3698            }
3699
3700        }
3701        isLoadingPopup = false;
3702
3703        //log('data.photo[0].ph_id_cat'+data.photo[0].ph_id_cat);
3704
3705        // !!!
3706        //if (0)
3707            $.ajax({
3708                url: ajaxFld + 'get_popup_more_photos.php?ph_id_cat=' + data.photo[0].ph_id_cat + '&id_photo=' + data.photo[0].id_photo,
3709                cache: false,
3710                dataType: 'html',
3711                success: function(data) {
3712                    $gallContainer.html(data);
3713                },
3714
3715                complete: function() {
3716                    resizeToEqualHeight($gallContainer, false, undefined, undefined, 20);
3717                }
3718            });
3719
3720    }
3721
3722
3723    function showSkeleton() {
3724
3725        $('.round3PopupAvatar').attr('src', '/1.gif');
3726        $('.previewCatName').html('<div class="skeletSmall skAnimation"><div class="smallBlock"></div></div>');
3727        $('#pAuthName').html('<div class="skeletBig skAnimation"></div>');
3728        $('#previewCommCnt').html('...');
3729        //$('#recName').html(ploc.add_rec_loc);
3730
3731    }
3732
3733    function getPreviewData(all_comm) {
3734        if (typeof imgArr[imgCurId] === 'undefined') {
3735            closePreviewPopup();
3736            return false;
3737        }
3738
3739        isLoadingPopup = true;
3740        if (all_comm)
3741            isScrollPopup = false;
3742
3743        tmpTmId = setTimeout(function() {
3744            showSkeleton();
3745        }, 200);
3746
3747        $.ajax({
3748            url: ajaxFld + 'get_work.php?id_photo=' + imgArr[imgCurId].id_photo + '&all_comm=' + all_comm,
3749            data: { importance: 'high' },
3750            cache: false,
3751            complete: function(data) {
3752                updatePreviewData(data);
3753                clearTimeout(tmpTmId);
3754            }
3755        });
3756    }
3757
3758    var closePopupUrl = '';
3759
3760    function showPopup() {
3761        //closePopupUrl = window.location.href;
3762
3763        $('.uMenuClass').hide();
3764        $(".burgerIconMin").removeClass('is-active');
3765
3766        if (isMac())
3767            $body.css({
3768                overflow: "hidden"
3769            });
3770        else
3771            $body.css({
3772                overflow: "hidden",
3773                "margin-right": "17px"
3774            });
3775
3776        
3777
3778        $previewOverlay.show();
3779        $previewPopup.show();
3780
3781        if (Object.keys(imgArr).length && Object.keys(imgArr).length > 1 && globalIsMulti)
3782            $previewPrevIcon.show();
3783
3784        isOverlay = true;
3785
3786        //setLastPos();
3787
3788        setTimeout(function() {
3789            momentDate();
3790
3791        }, 200);
3792
3793    }
3794
3795    function setLastPos() {
3796        setTimeout(function() {
3797            lastPos = $('#lastPos').position().top + $('#previewPopup').scrollTop();
3798        }, 400);
3799    }
3800
3801    function updatePreviewPopup() {
3802        if (typeof imgArr[imgCurId] !== "undefined" && typeof imgArr[imgCurId].ian !== "undefined" ) { //&& imgArr[imgCurId].ian == "1"
3803
3804            var popupSize = getPopupSize();
3805            var imgW = popupSize[0];
3806            var imgH = popupSize[1];
3807
3808            var $comment = $("#previewCommArea");
3809            $comment.css({
3810                'height': ''
3811            });
3812
3813            //$previewCommBtn.css({visibility: 'hidden'});
3814            //$workCommBB.css({visibility: 'hidden'});
3815
3816            if (!isAuthBlocked && ($imgPopup.attr("src") != imgArr[imgCurId].src || $imgPopup.attr("src") == "/1.gif")) {
3817                if (imgArr[imgCurId].loaded) {
3818                    $previewNext.css({
3819                        width: imgW + "px",
3820                        height: imgH + "px"
3821                    });
3822
3823                    $imgPopup.css({
3824                        width: imgW + "px",
3825                        height: imgH + "px"
3826                    });
3827
3828                    console.log('!!! 111', 'imgPos', imgArr[imgCurId].imgPos, 'imgCurId', imgCurId, 'loaded', imgArr[imgCurId].loaded);
3829                    $imgPopup.attr("src", imgArr[imgCurId].src);
3830                } 
3831                else {
3832                    $previewNext.css({
3833                        width: imgW + "px",
3834                        height: imgH + "px"
3835                    });
3836
3837                    $imgPopup.css({
3838                        width: imgW + "px",
3839                        height: imgH + "px"
3840                    });
3841
3842                    console.log('!!! 222', 'imgPos', imgArr[imgCurId].imgPos, 'imgCurId', imgCurId, 'loaded', imgArr[imgCurId].loaded);
3843                    $imgPopup.attr("src", imgArr[imgCurId].data_src);
3844
3845                    imgArr[imgCurId].src = getMainImage(imgArr[imgCurId].data_src);
3846                    imgArr[imgCurId].addEventListener('load', function() {
3847                        imgArr[this.id_photo].loaded = 1;
3848                        $imgPopup.attr("src", imgArr[imgCurId].src);
3849                    });
3850                }
3851            }
3852         }
3853
3854
3855        getPreviewData(0);
3856
3857        // cache prev next images
3858        if (imgArr[imgCurId].id_photo_next && typeof imgArr[imgArr[imgCurId].id_photo_next] !== 'undefined' && imgArr[imgArr[imgCurId].id_photo_next].loaded == 0) {
3859            imgArr[imgArr[imgCurId].id_photo_next].src = getMainImage(imgArr[imgArr[imgCurId].id_photo_next].data_src);
3860            imgArr[imgArr[imgCurId].id_photo_next].addEventListener('load', function() {
3861                imgArr[this.id_photo].loaded = 1;
3862            });
3863
3864
3865        }
3866
3867        if (imgArr[imgCurId].id_photo_prev && typeof imgArr[imgArr[imgCurId].id_photo_prev] !== 'undefined' && imgArr[imgArr[imgCurId].id_photo_prev].loaded == 0) {
3868            imgArr[imgArr[imgCurId].id_photo_prev].src = getMainImage(imgArr[imgArr[imgCurId].id_photo_prev].data_src);
3869            imgArr[imgArr[imgCurId].id_photo_prev].addEventListener('load', function() {
3870                imgArr[this.id_photo].loaded = 1;
3871            });
3872        }
3873    }
3874
3875    var txtArea = $('#comment');
3876    txtArea.css({
3877        'height': '276px'
3878    });
3879
3880    $(document).keyup(function(e) {
3881        //if (txtArea.length)
3882        //  updateTextareaHeight(txtArea);
3883
3884        if (e.keyCode == 13) { // enter
3885
3886        } else if (e.keyCode == 27) {
3887            // esc
3888            if ($shareToView.css("display") != "block")
3889                closePreviewPopup();
3890
3891            if (typeof fullScreenWrapPopup !== 'undefined' && fullScreenWrapPopup) {
3892                fullScreenWrapPopup.style.display = 'none';
3893                document.body.style.height = '';
3894                document.body.style.overflow = '';
3895                $(this).scrollTop(curScroll);
3896                if (typeof viewer !== 'undefined')
3897                    viewer = viewer.destroy();
3898            }
3899
3900            if (typeof fullScreenWrap !== 'undefined' && fullScreenWrap) {
3901                fullScreenWrap.style.display = 'none';
3902                document.body.style.height = '';
3903                document.body.style.overflow = '';
3904                $(this).scrollTop(curScroll);
3905                if (typeof viewer !== 'undefined')
3906                    viewer = viewer.destroy();
3907            }
3908        } else if (e.keyCode == 37) {
3909            // left
3910            if (isLoadingGall || isLoadingPopup) {
3911                e.stopPropagation();
3912                e.preventDefault();
3913            } else if (isOverlay && !e.shiftKey && !isCommentFocus) {
3914                gotoPrevPreviewPopup();
3915                e.stopPropagation();
3916            }
3917        } else if (e.keyCode == 39) {
3918            // right
3919            if (isLoadingGall || isLoadingPopup) {
3920                e.stopPropagation();
3921                e.preventDefault();
3922            } else if (isOverlay && !e.shiftKey && !isCommentFocus) {
3923                gotoNextPreviewPopup();
3924                e.stopPropagation();
3925            }
3926        } else if (e.keyCode == 82 && !isCommentFocus) {
3927            if ($("#previewRec").has('a').length > 0) $('#previewRec a').click();
3928            else $('#addRecBtn').click();
3929        }
3930    });
3931
3932    // open work page 
3933    $("#previewFullA").click(function(e) {
3934        e.stopPropagation();
3935    });
3936
3937    if (!isMobVer) {
3938        $(".closePopupPreview, .scrollWarn").click(function(e) {
3939            e.preventDefault();
3940            closePreviewPopup();
3941        });
3942
3943        $(".closePopupPreview").bind("contextmenu", function(e) {
3944            closePreviewPopup();
3945            (e.stopPropagation ? e.stopPropagation() : (e.preventDefault ? e.preventDefault() : (e.returnValue = false)));
3946            return false;
3947        });
3948
3949        $("#previewPopup").bind("mouseup", function(e) {
3950
3951            if (e.button == 3 || e.button == 4) {
3952                closePreviewPopup();
3953                (e.stopPropagation ? e.stopPropagation() : (e.preventDefault ? e.preventDefault() : (e.returnValue = false)));
3954
3955            }
3956
3957            return false;
3958
3959        });
3960
3961        /*$("#previewPrevClose2").click(function(e) {
3962            e.preventDefault();
3963            closePreviewPopup();
3964
3965        });
3966        $("#previewClose").click(function(e) {
3967            e.preventDefault();
3968            closePreviewPopup();
3969
3970        });
3971        $("#previewClose2").click(function(e) {
3972            e.preventDefault();
3973            closePreviewPopup();
3974        });*/
3975    }
3976
3977    setTimeout(function() {
3978        var $emojis = $("#emojis");
3979
3980        if ($emojis && typeof $emojis.disMojiPicker === "function") {
3981            $emojis.disMojiPicker();
3982            if (typeof twemoji !== 'undefined')
3983                twemoji.parse(document.body);
3984
3985            var showEmoji = false;
3986            $('.emojiPick').on('click', function() {
3987
3988                if (!showEmoji) {
3989                    $emojis.show();
3990                    showEmoji = true;
3991                } else {
3992                    $emojis.hide();
3993                    showEmoji = false;
3994                }
3995            });
3996
3997            $(document).on('click', function(e) {
3998                if (!$(e.target).is("#emojis") && !$(e.target).is(".emojiPick") && !$(e.target).is(".emoji") && !$(e.target).is("#emoji-smileys") && !$(e.target).is(".emoji-selectables")) {
3999                    $emojis.hide();
4000                    showEmoji = false;
4001                }
4002            });
4003
4004            $emojis.picker(function(emoji) {
4005                emoticon(emoji);
4006            });
4007        }
4008    }, 1000);
4009
4010    $previewPopup.bind('scroll', function() {
4011
4012
4013        // Закрытие попапа при скроллинге
4014        // setTimeout(function() {
4015        //     if ($previewPopup.scrollTop() >= lastPos - window.innerHeight) {
4016        //         closePreviewPopup();
4017        //     }
4018        // }, 250);
4019
4020
4021
4022        //log('scroll:', $previewPopup.scrollTop(), 'lastPos=',lastPos, 'innerHeight=',window.innerHeight);    
4023    });
4024
4025    /* -----------------------------------------------  */
4026
4027    var $wookmark = false;
4028    var $justify = true;
4029
4030    $myWnd.resize(function() {
4031        if ($justify) {
4032            waitForFinalEvent(function() {
4033                //if ($myWndW != $(this).width()) {
4034                    //resizedElements = [];
4035                //}
4036
4037                $myWndW = $(this).width();
4038                $myWndH = $(this).height();
4039
4040                isMobVer = utils.isMobile();
4041                //screenH = Math.min(window.innerHeight, screen.height);
4042                //screenW = Math.min(window.innerWidth, screen.width);
4043                var screenW = document.documentElement.clientWidth || document.body.clientWidth;
4044                var screenH = document.documentElement.clientHeight || document.body.clientHeight;
4045                log('isMobVer:', isMobVer, 'screenW:', screenW, 'screenH:', screenH);
4046                cookie.setCookie('isMobVer', isMobVer);
4047
4048                //if ($myWndW < 1300) {
4049                //if (typeof $searchTD !== "undefined") {
4050                //$searchTD.hide();
4051                //$searchTD.parent().attr("width", "1");
4052                //}
4053                //} else {
4054                //if (typeof $searchTD !== "undefined") {
4055                //$searchTD.show();
4056                //$searchTD.parent().attr("width", "147");
4057                //}
4058                //}
4059                if ($myWndW < $verySmallWndW) {
4060                    //if (typeof $moodTxt !== "undefined") $moodTxt.hide();
4061                    if (typeof $aForumT !== "undefined")
4062                        $aForumT.hide();
4063                    if (typeof $aAdmAuthorsT !== "undefined")
4064                        $aAdmAuthorsT.hide();
4065                    if (typeof $aAdmStatT !== "undefined")
4066                        $aAdmStatT.hide();
4067                } else {
4068                    //if (typeof $moodTxt !== "undefined") $moodTxt.show();
4069                    if (typeof $aForumT !== "undefined")
4070                        $aForumT.show();
4071                    if (typeof $aAdmAuthorsT !== "undefined")
4072                        $aAdmAuthorsT.show();
4073                    if (typeof $aAdmStatT !== "undefined")
4074                        $aAdmStatT.show();
4075                }
4076            }, 300, "delayed_resize");
4077        }
4078    });
4079
4080    if ($justify) { // ok do nothing
4081    } else if ($wookmark) {
4082        $lastWorks.find(".imgBox").css({
4083            height: "auto"
4084        }).wookmark({
4085            align: 'left',
4086            autoResize: true,
4087            container: $lastWorks,
4088            fillEmptySpace: true,
4089            offset: 12
4090        });
4091    }
4092
4093    if (!utils.isTouch()) {
4094        $('#comm0 .commButtonsTd').hover(function() {
4095            $('#commButtons' + $(this).attr('id').substring(13)).show();
4096        }, function() {
4097            $('#commButtons' + $(this).attr('id').substring(13)).hide();
4098        });
4099    } else {
4100        $contentDiv.find(".commButtons").show();
4101    }
4102
4103    var tTipTimeout;
4104    var tTipId;
4105
4106    if (!isMobVer) {
4107        $contentDiv.on({
4108            mouseenter: function(e) {
4109                if (!utils.isTouch()) { //var $tickRate = $(this).parent().find(".tickRateNew");
4110                    //$tickRate.toggleClass("tickRateBg").html('<span class="tickViewsNew"><b>' + $tickRate.data("views") + "</b> " + $tickRate.data("views-str") + '</span>');
4111                    //var $tickComm = $(this).parent().find(".tickCommNew");
4112                    //$tickComm.toggleClass("tickCommBg").html('<span class="tickDateNew">' + $tickComm.data("date") + '</span>');
4113                }
4114            },
4115            mouseleave: function(e) {
4116                if (!utils.isTouch()) { //var $tickRate = $(this).parent().find(".tickRateNew");
4117                    //$tickRate.toggleClass("tickRateBg").text($tickRate.data("rating"));
4118                    //var $tickComm = $(this).parent().find(".tickCommNew");
4119                    //$tickComm.toggleClass("tickCommBg");
4120                    //if ($tickComm.data("comms") != 0) $tickComm.text($tickComm.data("comms"));
4121                    //else $tickComm.text("");
4122                }
4123            },
4124            click: function(e) {//console.log('e.target=',e.target);
4125                if (!$(e.target).is("#recFromPreview")) {
4126                    if (!ctrlPressed && !commandPressed) {
4127
4128
4129
4130
4131                        if ($(this).data("isMulti") == 1) {
4132                            imgPos = $(this).data("pos");
4133                            imgCurId = $(this).data("idPhoto");
4134                            arrowsShow();
4135                            globalIsMulti = true;
4136                        } else {
4137                            imgPos = -1;
4138                            imgCurId = $(this).data("idPhoto");
4139                            initImgArrByEl($(this), imgPos, true);
4140                            arrowsHide();
4141                            globalIsMulti = false;
4142                        }
4143
4144                        if (imgArr[imgCurId] && !($(e.target).hasClass("tickCatNew")) && !($(e.target).hasClass("small_portrait")) && !($(e.target).hasClass("small_auth_name"))) {
4145                            if ($('#previewPopup').css('display') == 'none') {
4146                                updatePreviewPopup();
4147                            }
4148                            showPopup();
4149
4150                            e.preventDefault();
4151                        } 
4152
4153
4154
4155
4156                    }
4157                } else {
4158                    e.preventDefault();
4159                    recFromPreviewFunction(this);
4160                }
4161            }
4162        }, "a.aPopup, a.phNameLink, .phDescNew, .iconFullSizeGallIcon");
4163         //}, ".imgBoxNew, .iconFullSizeGallIcon");
4164
4165        function showTtip(target) {
4166
4167            if (tTipTimeout !== undefined) clearTimeout(tTipTimeout);
4168
4169            idImg = target.data('id-img');
4170            tTipId = $("#idAuth" + idImg);
4171            tTipId.css('display', 'inline-block');
4172            $('#authorWorks').css('z-index', '600');
4173
4174            var wdth = tTipId.innerWidth();
4175            var previewWidth = target.closest('.imgBoxNew').innerWidth();
4176            var leftPos = target.offset().left;
4177
4178            var nameW = target.innerWidth();
4179            var screenW = window.innerWidth / 2;
4180
4181            var r = previewWidth - 49 - nameW;
4182
4183            if (leftPos >= screenW)
4184                tTipId.css('left', 'auto').css('right', r + 'px').removeClass('beforeLeft').addClass('beforeRight');
4185
4186            target.closest('.imgBoxNew').css('overflow', 'unset');
4187            $('.imgBoxWrap').css('overflow', 'unset');
4188            //target.closest('.imgBoxNew').find('.blurThumb').css('transform', 'none').css('filter', 'none');
4189        }
4190
4191        function hideTtip(target) {
4192            $tmp = target;
4193
4194            tTipTimeout = setTimeout(function() {
4195                $tmp.closest('.imgBoxNew').css('overflow', 'hidden');
4196                $('.imgBoxWrap').css('overflow', 'hidden');
4197                $tmp.closest('.imgBoxNew').find('.blurThumb').css('transform', 'scale(1.05)').css('filter', '');
4198                if (tTipId)
4199                    tTipId.hide();
4200                $('#authorWorks').css('z-index', '');
4201            }, 400);
4202
4203        }
4204
4205        $contentDiv.on({
4206
4207            mouseenter: function() {
4208
4209                if (document.URL.indexOf('author.php') == -1) {
4210                    showTtip($(this));
4211                }
4212
4213            },
4214
4215            mouseleave: function() {
4216                hideTtip($(this));
4217
4218            }
4219        }, ".authGalleryTooltip");
4220
4221        $contentDiv.on({
4222
4223            mouseenter: function() {
4224
4225                clearTimeout(tTipTimeout);
4226            },
4227
4228            mouseleave: function() {
4229
4230                hideTtip($(this));
4231
4232            }
4233        }
4233, ".aTtip");
4234
4235        $('#previewPopup').on({
4236
4237            mouseenter: function() {
4238
4239                showTtip($(this));
4240                $('.justified-gallery').css('overflow', 'unset');
4241
4242            },
4243
4244            mouseleave: function() {
4245
4246                hideTtip($(this));
4247                $('.justified-gallery').css('overflow', '');
4248
4249            }
4250        }, ".authGalleryTooltip");
4251
4252        $('#previewPopup').on({
4253            mouseenter: function() {
4254
4255                clearTimeout(tTipTimeout);
4256                $('.justified-gallery').css('overflow', 'unset');
4257            },
4258            mouseleave: function() {
4259
4260                hideTtip($(this));
4261                $('.justified-gallery').css('overflow', '');
4262
4263            }
4264        }, ".aTtip");
4265
4266        $('#previewPopup').on({
4267            mouseenter: function() {
4268                if (!utils.isTouch()) { //var $tickRate = $(this).parent().find(".tickRateNew");
4269                    //$tickRate.toggleClass("tickRateBg").html('<span class="tickViewsNew"><b>' + $tickRate.data("views") + "</b> " + $tickRate.data("views-str") + '</span>');
4270                    //var $tickComm = $(this).parent().find(".tickCommNew");
4271                    //$tickComm.toggleClass("tickCommBg").html('<span class="tickDateNew">' + $tickComm.data("date") + '</span>');
4272                }
4273            },
4274            mouseleave: function() {
4275                if (!utils.isTouch()) { //var $tickRate = $(this).parent().find(".tickRateNew");
4276                    //$tickRate.toggleClass("tickRateBg").text($tickRate.data("rating"));
4277                    //var $tickComm = $(this).parent().find(".tickCommNew");
4278                    //$tickComm.toggleClass("tickCommBg");
4279                    //if ($tickComm.data("comms") != 0) $tickComm.text($tickComm.data("comms"));
4280                    //else $tickComm.text("");
4281                }
4282            },
4283            click: function(e) {
4284                if (!$(e.target).is("#recFromPreview")) {
4285                    if (!ctrlPressed && !commandPressed) {
4286                        if ($(this).data("isMulti") == 1) {
4287                            imgPos = $(this).data("pos");
4288                            imgCurId = $(this).data("idPhoto");
4289                            arrowsShow();
4290                            globalIsMulti = true;
4291                        } else {
4292                            imgPos = -1;
4293                            imgCurId = $(this).data("idPhoto");
4294                            initImgArrByEl($(this), imgPos, true);
4295                            arrowsHide();
4296                            globalIsMulti = false;
4297                        }
4298
4299                        if (imgArr[imgCurId] && !($(e.target).hasClass("tickCatNew")) && !($(e.target).hasClass("small_portrait")) && !($(e.target).hasClass("small_auth_name"))) {
4300                            updatePreviewPopup();
4301                            showPopup();
4302
4303                            e.preventDefault();
4304                        }
4305                    }
4306
4307                } else {
4308                    e.preventDefault();
4309                    recFromPreviewFunction(this);
4310                }
4311            }
4312        }, "a.aPopup, a.phNameLink, .phDescNew, .iconFullSizeGallIcon");
4313
4314        $contentDiv.on({
4315            mouseenter: function() {
4316                $(this).find(".commActionsRight").show();
4317                $(this).find(".commReplyBtnRight").show();
4318            },
4319            mouseleave: function() {
4320                $(this).find(".commActionsRight").hide();
4321                $(this).find(".commReplyBtnRight").hide();
4322            }
4323
4324        }, ".commTextTd, .commTextTdNew, .commTextDiv");
4325
4326        $contentDiv.on({
4327            mouseenter: function() {
4328                if (!utils.isTouch() && !isMobVer) {
4329                    if ($(this).parent().attr('id') !== 'blogs') {
4330                        $(this).find(".aFullPage").show();
4331                        $(this).find(".phDescNew").show();
4332                        $(this).find(".iconFullSizeGall").show();
4333
4334                        //$(this).find(".phDescNew").show();
4335
4336                        //$(this).find(".phDescNew").css({opacity: 1});
4337                        /*var $tickCommNew = $(this).find(".tickCommNew");
4338                        $tickCommNew.removeClass('tickCommBg').addClass('tickCommDate');
4339                        $tickCommNew.text($tickCommNew.attr('data-date'));*/
4340                    }
4341                }
4342            },
4343            mouseleave: function() {
4344                if (!utils.isTouch() && !isMobVer) {
4345                    if ($(this).parent().attr('id') !== 'blogs') {
4346                        $(this).find(".aFullPage").hide();
4347                        $(this).find(".phDescNew").hide();
4348                        $(this).find(".iconFullSizeGall").hide();
4349
4350                        $('.aTtip').hide();
4351
4352                        //$(this).find(".phDescNew").hide();
4353                        //$(this).find(".phDescNew").css({opacity: 0});
4354                        /*var $tickCommNew = $(this).find(".tickCommNew");
4355                        $tickCommNew.removeClass('tickCommDate').addClass('tickCommBg');
4356                        if($tickCommNew.attr('data-comms') !== '0')
4357                            $tickCommNew.text($tickCommNew.attr('data-comms'));
4358                        else
4359                            $tickCommNew.text('');*/
4360                    }
4361                }
4362            }
4363        }, ".imgBoxNew");
4364
4365        $("#previewPopup").on({
4366            mouseenter: function() {
4367                if (!utils.isTouch() && !isMobVer) {
4368                    if ($(this).parent().attr('id') !== 'blogs') {
4369                        $(this).find(".aFullPage").show();
4370                        $(this).find(".phDescNew").show();
4371                        $(this).find(".iconFullSizeGall").show();
4372
4373                    }
4374                }
4375            },
4376            mouseleave: function() {
4377                if (!utils.isTouch() && !isMobVer) {
4378                    if ($(this).parent().attr('id') !== 'blogs') {
4379                        $(this).find(".aFullPage").hide();
4380                        $(this).find(".phDescNew").hide();
4381                        $(this).find(".iconFullSizeGall").hide();
4382
4383                        $('.aTtip').hide();
4384
4385                    }
4386                }
4387            }
4388        }, ".imgBoxNew");
4389
4390        $("#previewPopup").on({
4391            click: function(e) {
4392                window.location = $(this).data("href");
4393                e.stopPropagation();
4394            }
4395        }, "span.aFullPage");
4396
4397        $contentDiv.on({
4398            mouseenter: function() {
4399                if (!utils.isTouch() && !isMobVer)
4400                    $(this).find(".aFullPage").show();
4401                $(this).find(".phDescNew").show();
4402                $(this).find(".iconFullSizeGall").show();
4403            },
4404            mouseleave: function() {
4405                if (!utils.isTouch() && !isMobVer)
4406                    $(this).find(".aFullPage").hide();
4407                $(this).find(".phDescNew").hide();
4408                $(this).find(".iconFullSizeGall").hide();
4409            }
4410        }, ".phImg");
4411
4412        $contentDiv.on({
4413            click: function(e) {
4414                window.location = $(this).data("href");
4415                e.stopPropagation();
4416            }
4417        }, "span.aFullPage");
4418
4419        if (Object.keys(imgArr).length == 0) {
4420            var $gallAjax = {};
4421            if ($("#panelLastWorks").length)
4422                $gallAjax = $("#panelLastWorks");
4423            else
4424                $gallAjax = $("#gallAjax");
4425
4426            // used to cache images for gallery build on backend
4427            findImgArr($gallAjax);
4428        }
4429
4430        $("#previewNextImg").on("click", function(e) {
4431            if(globalIsMulti) { 
4432                gotoNextPreviewPopup(); 
4433
4434            }
4435            else closePreviewPopup();
4436            e.stopPropagation();
4437        });
4438
4439        $previewPrevIcon.on("click", function(e) {
4440            gotoPrevPreviewPopup();
4441            e.stopPropagation();
4442        });
4443
4444        $('.prevLeft').on("click", function(e) {
4445
4446            gotoPrevPreviewPopup();
4447            //if($('#previewPopup').css('display') == 'block') {
4448            var srcPopup = getMainImage(document.getElementById('imgPopup').src);
4449
4450            //} 
4451
4452            if (srcPopup.indexOf('1.gif') == -1)
4453                openFScreen(srcPopup);
4454            else closeFScreen();
4455
4456            e.stopPropagation();
4457        });
4458
4459        $('.prevLeftArrow, .nextRightArrow, .prevLeft, .nextRight').on('mouseenter', function(e) {
4460
4461            if (e.target.className == 'prevLeftArrow' || e.target.className == 'prevLeft')
4462                $('.prevLeftArrow').css('background-color', '#ffffff45').css('opacity', '1');
4463            else if (e.target.className == 'nextRightArrow' || e.target.className == 'nextRight')
4464                $('.nextRightArrow').css('background-color', '#ffffff45').css('opacity', '1');
4465        });
4466
4467        $('.prevLeftArrow, .nextRightArrow, .prevLeft, .nextRight').on('mouseleave', function() {
4468            $(this).children().css('background-color', 'transparent').css('opacity', '0.6');
4469        });
4470
4471        $('.nextRight').on("click", function(e) {
4472            gotoNextPreviewPopup();
4473
4474            var srcPopup = getMainImage(document.getElementById('imgPopup').src);
4475
4476            if (srcPopup.indexOf('1.gif') == -1)
4477                openFScreen(srcPopup);
4478            else closeFScreen();
4479
4480            e.stopPropagation();
4481        });
4482
4483        $("#showMoreComm").on("click", function(e) {
4484            $(this).text("");
4485            getPreviewData(1);
4486
4487            e.preventDefault();
4488        });
4489
4490        $previewPrevIcon.hover(function() {
4491            $(this).css({
4492                "background-color": "rgba(0,0,0,.5)",
4493                opacity: 1
4494            });
4495        }, function() {
4496            $(this).css({
4497                "background-color": "transparent",
4498                opacity: 1
4499            });
4500        });
4501    }
4502
4503    //////////////////////////////////////////////////////////////
4504    var commActionsMenuHideTimeout = 400;
4505    var isCommActionsMenuOpened = false;
4506    var isCommActMenuOpened = false;
4507    var $wrapWorkComm = $('#wrapWorkComm');
4508
4509    $wrapWorkComm.on({
4510        mouseenter: function() {
4511            var idComm = $(this).attr('data-id-comm');
4512            var $commActionsMenu = $('#commActionsMenu' + idComm);
4513
4514            var commNumber = $(this).attr('data-comm-number');
4515            var idAuth = $(this).attr('data-id-author');
4516            var $commActMenu = $('#commAct' + idAuth + commNumber);
4517
4518            if (isCommActionsMenuOpened)
4519                $commActionsMenu.hide();
4520            else
4521                $commActionsMenu.show();
4522
4523            if (isCommActMenuOpened)
4524                $commActMenu.hide();
4525            else
4526                $commActMenu.show();
4527
4528            isCommActMenuOpened = !isCommActMenuOpened;
4529            isCommActionsMenuOpened = !isCommActionsMenuOpened;
4530
4531            $commActionsMenu.on({
4532                mouseenter: function() {
4533                    isCommActionsMenuOpened = true;
4534                },
4535                click: function() {
4536                    $commActionsMenu.hide();
4537                    isCommActionsMenuOpened = false;
4538                },
4539                mouseleave: function() {
4540                    isCommActionsMenuOpened = false;
4541                    setTimeout(function() {
4542                        if (!isCommActionsMenuOpened) {
4543                            $commActionsMenu.hide();
4544                            isCommActionsMenuOpened = false;
4545                        }
4546                    }, commActionsMenuHideTimeout);
4547                }
4548            });
4549
4550            $commActMenu.on({
4551                mouseenter: function() {
4552                    isCommActMenuOpened = true;
4553                },
4554                click: function() {
4555                    $commActMenu.hide();
4556                    isCommActMenuOpened = false;
4557                },
4558                mouseleave: function() {
4559                    isCommActMenuOpened = false;
4560                    setTimeout(function() {
4561                        if (!isCommActMenuOpened) {
4562                            $commActMenu.hide();
4563                            isCommActMenuOpened = false;
4564                        }
4565                    }, commActionsMenuHideTimeout);
4566                }
4567            });
4568        },
4569        mouseleave: function() {
4570            var idComm = $(this).attr('data-id-comm');
4571            var $commActionsMenu = $('#commActionsMenu' + idComm);
4572
4573            var commNumber = $(this).attr('data-comm-number');
4574            var idAuth = $(this).attr('data-id-author');
4575            var $commActMenu = $('#commAct' + idAuth + commNumber);
4576
4577            isCommActionsMenuOpened = false;
4578            isCommActMenuOpened = false;
4579
4580            setTimeout(function() {
4581                if (!isCommActionsMenuOpened) {
4582                    $commActionsMenu.hide();
4583                    isCommActionsMenuOpened = false;
4584                }
4585            }, commActionsMenuHideTimeout);
4586
4587            setTimeout(function() {
4588                if (!isCommActMenuOpened) {
4589                    $commActMenu.hide();
4590                    isCommActMenuOpened = false;
4591                }
4592            }, commActionsMenuHideTimeout);
4593
4594        }
4595    }, ".messageDots, .commActIcon, .commActAv");
4596    //////////////////////////////////////////////////////////////
4597
4598    //////////////////////////////////////////////////////////////
4599    var commActionsMenuHideTimeout = 400;
4600    var isCommActionsMenuOpened = false;
4601    var $previewCommBlk = $('#previewCommBlk');
4602    $previewCommBlk.on({
4603        click: function() {
4604            var idComm = $(this).attr('data-id-comm');
4605            var $commActionsMenu = $('#commActionsMenu' + idComm);
4606
4607            if (isCommActionsMenuOpened)
4608                $commActionsMenu.hide();
4609            else
4610                $commActionsMenu.show();
4611
4612            isCommActionsMenuOpened = !isCommActionsMenuOpened;
4613
4614            $commActionsMenu.on({
4615                mouseenter: function() {
4616                    isCommActionsMenuOpened = true;
4617                },
4618                click: function() {
4619                    $commActionsMenu.hide();
4620                    isCommActionsMenuOpened = false;
4621                },
4622                mouseleave: function() {
4623                    isCommActionsMenuOpened = false;
4624                    setTimeout(function() {
4625                        if (!isCommActionsMenuOpened) {
4626                            $commActionsMenu.hide();
4627                            isCommActionsMenuOpened = false;
4628                        }
4629                    }, commActionsMenuHideTimeout);
4630                }
4631            });
4632        },
4633        mouseleave: function() {
4634            var idComm = $(this).attr('data-id-comm');
4635            var $commActionsMenu = $('#commActionsMenu' + idComm);
4636
4637            isCommActionsMenuOpened = false;
4638            setTimeout(function() {
4639                if (!isCommActionsMenuOpened) {
4640                    $commActionsMenu.hide();
4641                    isCommActionsMenuOpened = false;
4642                }
4643            }, commActionsMenuHideTimeout);
4644        }
4645    }, ".messageDotsPopup");
4646
4647    //////////////////////////////////////////////////////////////
4648
4649    $previewCommBtn.on("click", function(e) {
4650        if (typeof $loginAvatar.data("idAuth") != "undefined" || typeof $loginAvatarMin.data("idAuth") != "undefined" || typeof $loginAvatarImg.data("idAuth") != "undefined") {
4651            // author is logged
4652
4653            localStorage.removeItem('TextEditorData');
4654
4655            var loginAvatar = '';
4656            var loginName = '';
4657            var loginPremium = 0;
4658            var loginRating = '0.00';
4659            if (typeof $loginAvatar.data("idAuth") != "undefined") {
4660                loginAvatar = $loginAvatar.data("authAvatar");
4661                loginName = $loginAvatar.data("authName");
4662                loginPremium = $loginAvatar.data("authPremium");
4663                loginRating = $loginAvatar.data("authRating");
4664                loginHref = $loginAvatar.data("authHref");
4665            } else if (typeof $loginAvatarImg.data("idAuth") != "undefined") {
4666                loginAvatar = $loginAvatarImg.data("authAvatar");
4667                loginName = $loginAvatarImg.data("authName");
4668                loginPremium = $loginAvatarImg.data("authPremium");
4669                loginRating = $loginAvatarImg.data("authRating");
4670                loginHref = $loginAvatarImg.data("authHref");
4671            } else {
4672                loginAvatar = $loginAvatarMin.data("authAvatar");
4673                loginName = $loginAvatarMin.data("authName");
4674                loginPremium = $loginAvatarMin.data("authPremium");
4675                loginRating = $loginAvatarMin.data("authRating");
4676                loginHref = $loginAvatarMin.data("authHref");
4677            }
4678
4679            var loginPremiumSrc = '';
4680            if (loginPremium >= 30) {
4681                loginPremiumSrc = '<div class="premiumBadge proBg" title="Pro Account">PRO</div>';
4682            } else if (loginPremium === 20) {
4683                loginPremiumSrc = '<div class="premiumBadge premiumBg" title="Premium Account">PREMIUM</div>';
4684            } else if (loginPremium >= 10) {
4685                loginPremiumSrc = '<div class="premiumBadge plusBg" title="Plus Account">PLUS</div>';
4686            }
4687
4688            var premiumBadgeString = '';
4689            if (loginPremium != 0)
4690                premiumBadgeString = loginPremiumSrc;
4691
4692            var id = imgArr[imgCurId].id_photo;
4693            var $comment = $("#previewCommArea");
4694            var $previewCommLoader = $("#previewCommLoader");
4695            var comm_text = trim($comment.val());
4696            var trimmed_comm = trimComm(comm_text);
4697            if (trimmed_comm.length < minCommLen) {
4698                alert(ploc.be_constructive_loc);
4699                $comment.focus();
4700            } else if (comm_text.length > 30000) {
4701                alert(ploc.max_comm_len_loc);
4702                $comment.focus();
4703            } else {
4704                $previewCommLoader.show();
4705                $previewCommBtn.hide();
4706                $.post(ajaxFld + "post_comm.php", {
4707                    id: id,
4708                    comm_text: comm_text,
4709                    type: "work",
4710                    id_auth_answer: id_auth_answer,
4711                    id_comm_parent: id_comm_parent
4712                }, function(data) {
4713                    NProgress.done();
4714                    id_auth_answer = 0;
4715                    id_comm_parent = 0;
4716
4717                    data.cnt = data.cnt || 1;
4718                    data.id_comm_last = data.id_comm_last || 0;
4719
4720                    comm_text = comm_text.replace(/\[b\]/g, '<strong>').replace(/\[\/b\]/g, '</strong>').replace(/\[u\]/g, '<u>').replace(/\[\/u\]/g, '</u>').replace(/\[i\]/g, '<i>').replace(/\[\/i\]/g, '</i>').replace(/\[quote\]/g, '<div class="commQuotePopup">').replace(/\[\/quote\]/g, '</div>');
4721                    comm_text = comm_text.replace(/\[img\]/g, '').replace(/\[\/img\]/g, '').replace(/\[url\]/g, '').replace(/\[\/url\]/g, '').replace(/\[youtube\]/g, '').replace(/\[\/youtube\]/g, '').replace(/\[vimeo\]/g, '').replace(/\[\/vimeo\]/g, '').replace(/\[mp3\]/g, '').replace(/\[\/mp3\]/g, '');
4722
4723                    comm_text = comm_text.replace(/\[spoiler\]/g, '<span class="spoiler">').replace(/\[\/spoiler\]/g, '</span>');
4724
4725                    var commLine = '<div class="previewCommLine clearfix">';
4726                    commLine += '<div class="previewCommL">';
4727                    commLine += '<a href="' + loginHref + '" title="' + ploc.auth_profile_loc + '"><img class="round3PopupAvatar" src="' + loginAvatar + '" width="38.192" height="38.192" alt="' + loginName + '"></a>';
4728                    commLine += '</div>';
4729                    commLine += '<div class="previewCommR">';
4730                    commLine += '<div class="previewCommAuName">';
4731                    commLine += '<span><a id="authName0" title="' + ploc.click_to_paste_name_loc + '" onclick="emoticon(\'[b]' + loginName + '[/b],\'); return false;" href="#">
4731' + loginName + '</a></span>';
4732                    commLine += premiumBadgeString;
4733                    //commLine += '<span class="commAuthRate">' + loginRating + '</span>';
4734                    commLine += '<span class="commDate">' + '' + '</span>';
4735                    commLine += '</div>';
4736                    commLine += '<span id="spanCommText0" class="previewComm">' + comm_text + '</span>';
4737
4738                    commLine += '<div class="commPopupActions">';
4739                    commLine += '<span class="intrestBtnApopup nobodyVoted" id="commVoteBtn' + data.id_comm_last + '"><a onclick="getCommVote(' + data.id_comm_last + ', \'work\');return false;" href="#">&#xe928;</a></span> <span class="commVotePopup" id="commVote' + data.id_comm_last + '" title="' + ploc.voter_for_meaning_loc + '"></span><div class="commPopupActionsRight"><a onclick="setReplayPopup(0, 1, ' + data.id_comm_last + ',\'' + loginName + '\'); return false;" href="#" class="buttonA replyBtnA" title="' + ploc.answer_loc + '"><span class="replyBtnApopup">&#xe960;</span></a><a onclick="setQuotePop(); return false;" href="#" title="' + ploc.sel_citation_loc + '" style="text-decoration: none;"><span class="quoteBtnApopup">&#xe963;</span></a><span data-id-comm="' + data.id_comm_last + '" class="messageDotsPopup">&#xe939;</span></div>';
4740                    commLine += '<div id="commActionsMenu' + data.id_comm_last + '" class="commActionsMenu" style="display: none;">';
4741                    commLine += '<span id="aEdit0"><a onclick="editCommPopup(' + data.id_comm_last + ', 0, \'work\'); return false;" href="#" class="editCommA" style="border: none;" title="' + ploc.edit_comm_loc + '"><i class="about_icon about_icon_popup">&#xe813;</i>' + ploc.edit_comm_loc + '</a></span>';
4742                    commLine += '<a href="#comm0" onclick="if(confirm(\'' + ploc.do_want_del_comm_loc + '\')) deleteComm(' + data.id_comm_last + ', 64300, 0, \'work\')" class="delCommA" style="border: none;" title="' + ploc.del_loc + '"><i class="about_icon about_icon_popup">&#xe828;</i>' + ploc.del_loc + '</a>';
4743                    commLine += '<a href="#comm0" onclick="appealComm(' + data.id_comm_last + ', 0, 0, \'work\')" class="delCommA" style="border: none;" title="' + ploc.appeal_loc + '"><i class="about_icon about_icon_popup">&#xe827;</i>' + ploc.appeal_loc + '</a>';
4744
4745                    commLine += '</div>';
4746                    commLine += '</div>';
4747                    commLine += '</div>';
4748
4749                    commLine += '</div>';
4750                    $("#previewComm").append(commLine);
4751
4752                    $comment.val("");
4753                    $previewCommLoader.hide();
4754                    $previewCommBtn.show();
4755
4756                    if (typeof twemoji !== 'undefined')
4757                        twemoji.parse(document.body, { folder: 'svg', ext: '.svg' });
4758
4759                }, "json");
4760            }
4761        }
4762        e.stopPropagation();
4763    });
4764
4765    function delayUnhover(elem) {
4766        setTimeout(function() {
4767            if (elem.attr("id") == "headerSubmenu" && !isAGalleryTHover && !isHeaderSubmenuHover) {
4768                elem.hide();
4769                if (typeof isCoverPage !== "undefined")
4770                    aGalleryTG.css({
4771                        "background": "none"
4772                    });
4773            }
4774        }, 500);
4775    }
4776
4777    var isAGalleryTHover = false;
4778    var aGalleryTG = $("#aGalleryTG");
4779    var aGalleryT = $("#aGalleryT, #aGalleryTpopup");
4780    var aAllCommT = $('#aAllCommT, #aAllCommT2');
4781    var NFTlink = $('#NFTlink, #NFTlink2');
4782
4783    var btnConnect = $("#prepareConnect");
4784
4785    var isHeaderSubmenuHover = false;
4786    var headerSubmenu = $("#headerSubmenu");
4787    var headerSubmenuPopup = $("#headerSubmenuPopup");
4788    var dropDownWallet = $("#dropDownWallet");
4789
4790    var shoppingCartWrap = $("#shoppingCartWrap");
4791    var scDropDown = $("#scDropDown");
4792
4793    var shoppingCartWrap2 = $("#shoppingCartWrap2");
4794    var scDropDown2 = $("#scDropDown2");
4795
4796    var menuTimerId, actTimer1, actTimer2, actTimer3, actTimer4, actTimer5, actTimer, qTimer, tmpT;
4797
4798    var hSubmenu = null;
4799
4800
4801
4802
4803
4804    aGalleryT.hover(function() {
4805
4806        dropDownMenuHide($('#headerSubmenuActivity'));
4807        dropDownMenuHide($('#NFTSubmenu'));
4808
4809        hSubmenu = $(this).find("#headerSubmenu, #headerSubmenuPopup");
4810        clearTimeout(menuTimerId);
4811        dropDownMenuShow(hSubmenu);
4812        //dropDownMenuShow(headerSubmenuPopup);
4813
4814    }, function() {
4815
4816        menuTimerId = setTimeout(function() {
4817            dropDownMenuHide(hSubmenu);
4818        }, 300);
4819
4820    });
4821
4822
4823
4824
4825
4826    var hActivity = null;
4827
4828    aAllCommT.hover(function() {
4829
4830        dropDownMenuHide($('#NFTSubmenu'));
4831        dropDownMenuHide($("#headerSubmenu")); 
4832        dropDownMenuHide($("#headerSubmenuPopup"));
4833        
4834
4835        hActivity = $(this).find('#headerSubmenuActivity');
4836        clearTimeout(actTimer); 
4837        dropDownMenuShow(hActivity);
4838    }, function() {
4839        actTimer = setTimeout(function() {
4840            dropDownMenuHide(hActivity);
4841        }, 300);
4842    });
4843
4844    NFTlink.hover(function() {
4845
4846        dropDownMenuHide($('#headerSubmenuActivity'));
4847        dropDownMenuHide($("#headerSubmenu")); 
4848        dropDownMenuHide($("#headerSubmenuPopup"));
4849
4850        hNFT = $(this).find('#NFTSubmenu');
4851        clearTimeout(actTimer2);
4852        dropDownMenuShow(hNFT);
4853    }, function() {
4854        actTimer2 = setTimeout(function() {
4855            dropDownMenuHide(hNFT);
4856        }, 300);
4857    });
4858
4859    // btnConnect.hover(function() {
4860
4861    //     clearTimeout(actTimer3);
4862    //     if (localStorage.getItem('WALLET_ADDRESS') != undefined) {
4863    //         dropDownMenuShow(dropDownWallet);
4864    //         dropDownMenuHide(scDropDown);
4865
4866    //     }
4867    // }, function() {
4868    //     actTimer3 = setTimeout(function() {
4869    //         dropDownMenuHide(dropDownWallet);
4870    //     }, 600);
4871    // });
4872
4873    shoppingCartWrap.hover(function() {
4874
4875        clearTimeout(actTimer4);
4876        dropDownMenuHide(dropDownWallet);
4877        dropDownMenuShow(scDropDown);
4878
4879    }, function() {
4880        actTimer4 = setTimeout(function() {
4881            dropDownMenuHide(scDropDown);
4882        }, 600);
4883    });
4884
4885    shoppingCartWrap2.hover(function() {
4886
4887        clearTimeout(actTimer5);
4888        dropDownMenuHide(dropDownWallet);
4889        dropDownMenuShow(scDropDown2);
4890
4891    }, function() {
4892        actTimer5 = setTimeout(function() {
4893            dropDownMenuHide(scDropDown2);
4894        }, 600);
4895    });
4896
4897    $('#qicon, #qicon2').hover(function() {
4898        clearTimeout(qTimer);
4899        var qId = $(this).parents('div').find('#qiconTip, #qiconTip2');
4900
4901        tmpT = setTimeout(function() {
4902            dropDownMenuShow(qId);
4903        }, 600);
4904    }, function() {
4905
4906        clearTimeout(tmpT);
4907        var qId = $(this).parents('div').find('#qiconTip, #qiconTip2');
4908        qTimer = setTimeout(function() {
4909            dropDownMenuHide(qId);
4910        }, 400);
4911    });
4912
4913    var $smileDiv = $("#smileDiv");
4914    var smilesActive = false;
4915
4916    $smileDiv.click(function(e) {
4917
4918        if (!smilesActive) {
4919            smilesActive = true;
4920            $("#postCommDivPopup").animate({
4921                height: 'toggle'
4922            }, 100);
4923        } else {
4924            smilesActive = false;
4925            $("#postCommDivPopup").animate({
4926                height: 'hide'
4927            }, 100);
4928        }
4929
4930        e.preventDefault();
4931
4932    });
4933
4934    var $smileDivWork = $("#smileDivWork");
4935    var smilesActiveWork = false;
4936
4937    $smileDivWork.click(function(e) {
4938
4939        if (!smilesActiveWork) {
4940            smilesActiveWork = true;
4941            $("#postCommDivWork").css('display', 'inline-block');
4942        } else {
4943            smilesActiveWork = false;
4944            $("#postCommDivWork").hide();
4945        }
4946
4947        e.preventDefault();
4948
4949    });
4950
4951    var isAuthActMenuHover = false;
4952    var $authActivityLnk = $("#authActivityLnk");
4953    var $authActivityMenu = $("#authActivityMenu");
4954    $authActivityLnk.click(function() {
4955        if (!isAuthActMenuHover) {
4956
4957            dropDownMenuShow($authActivityMenu);
4958
4959        }
4960        isAuthActMenuHover = !isAuthActMenuHover;
4961
4962    });
4963
4964    $('#banAuthor').click(function(event) {
4965        event.stopPropagation();
4966
4967    });
4968    /*$authActivityLnk.hover(
4969        function () {
4970            isAuthActMenuHover = true;
4971            $authActivityMenu.show();
4972        },
4973        function () {
4974            isAuthActMenuHover = false;
4975        }
4976    );*/
4977
4978    $authActivityMenu.hover(function() {
4979        isAuthActMenuHover = true;
4980    }, function() {
4981        isAuthActMenuHover = false;
4982    });
4983
4984    $vertMenuWrap = $('#vertMenuWrap');
4985
4986    var isUserMenuHover = false;
4987
4988    $body.click(function(e) {
4989
4990        if (e.target.id == "userMenu" || $(e.target).parents('#userMenu').length > 0)
4991            return;
4992
4993        if (e.target.id == "loginAvatarMin2" || $(e.target).parents('#loginAvatarMin2').length > 0 || e.target.id == "loginDivName" || $(e.target).parents('#loginDivName').length > 0) {
4994
4995            if (!$burgerIconMin.hasClass('is-active')) {
4996
4997                dropDownMenuShow($userMenu);
4998                //$userMenu.show();
4999                //isUserMenuHover = true;
5000                $burgerIconMin.addClass('is-active');
5001                //$burgerIconMin2.addClass('is-active');
5002            } else {
5003
5004                dropDownMenuHide($userMenu);
5005                //$userMenu.hide();
5006                //isUserMenuHover = false;
5007                $burgerIconMin.removeClass('is-active');
5008                //$burgerIconMin2.removeClass('is-active');
5009            }
5010
5011        } else if ($burgerIconMin.hasClass('is-active')) {
5012
5013            dropDownMenuHide($userMenu);
5014
5015            //$userMenu.hide();
5016
5017            isUserMenuHover = false;
5018            $burgerIconMin.removeClass('is-active');
5019            //$burgerIconMin2.removeClass('is-active');
5020        }
5021
5022        if (!isAuthActMenuHover) {
5023            isAuthActMenuHover = false;
5024
5025            dropDownMenuHide($authActivityMenu);
5026            //$("#authProfilMenu").css('border-radius', '30px');
5027        }
5028
5029        if (e.target.id != 'menuHamburger' && e.target.id != 'menuHamburgerIcon') {
5030            if (!utils.isTouch() && !isMobVer) {
5031                $vertMenuWrap.css({
5032                    opacity: 0
5033                });
5034            }
5035        }
5036    });
5037
5038    if ($.browser.mozilla && parseFloat($.browser.version) <= 1.8) {
5039        $(".imgBoxWrap > *").css("float", "left").css("margin-right", "10px");
5040        $(".wrapWorkOfDay > *").css("float", "left");
5041    }
5042    if ($.browser.opera && parseFloat($.browser.version) < 9.5) {
5043        $(".imgBoxWrap").css("text-align", "left");
5044        $(".imgBoxWrap > *").css("margin-right", "10px");
5045    }
5046
5047    var $loginAvatarMin = $("#loginAvatarMin");
5048    var $loginAvatarMin2 = $("#loginAvatarMin2");
5049    var $loginAvatarImg = $("#loginAvatarImg");
5050    var $loginAvatar = $("#loginAvatar");
5051
5052    var $loginDivName = $(".loginDiv");
5053    var $userMenu = $("#userMenu");
5054    var $burgerIconMin = $(".burgerIconMin");
5055
5056    // $loginAvatar.on("click", function() {
5057    //     //isUserMenuHover = true;
5058    //     dropDownMenuShow($userMenu);
5059
5060    //     $burgerIconMin.addClass('is-active');
5061    //     //$userMenu.show();
5062
5063    // }, function() {});
5064
5065    var $loginPopup = $('#header.headerPopup #loginDivName');
5066    $loginPopup.click(function() {
5067        document.location.href = '/login.php';
5068    });
5069
5070    $loginDivName.click(function() {
5071        //isUserMenuHover = true;
5072
5073        var uMenu = $(this).parents('#loginDiv, #headerWrap, #headerWrapPopup, body').find('#userMenu');
5074        dropDownMenuShow(uMenu);
5075
5076        $burgerIconMin.addClass('is-active');
5077        //$userMenu.show();
5078
5079    }, function() {});
5080
5081    if ($burgerIconMin.length) {
5082        $burgerIconMin.click(function(e) {
5083            var uMenu = $(this).parents('#loginDiv, #headerWrap, #headerWrapPopup, body').find('#userMenu');
5084            if (!$burgerIconMin.hasClass('is-active')) {
5085                //isUserMenuHover = true;
5086
5087                dropDownMenuShow(uMenu);
5088                //$userMenu.show();
5089                $burgerIconMin.addClass('is-active');
5090
5091            } else {
5092                //isUserMenuHover = false;
5093                dropDownMenuHide(uMenu);
5094                //$userMenu.hide();
5095                $burgerIconMin.removeClass('is-active');
5096
5097            }
5098            e.preventDefault();
5099            e.stopPropagation();
5100        });
5101    } else {
5102        /*
5103        $loginDivName.click(function(e) {
5104            if (!isUserMenuHover) {
5105                isUserMenuHover = true;
5106                dropDownMenuShow($userMenu);
5107                //$userMenu.show();
5108                $burgerIconMin.addClass('is-active');
5109               
5110            } else {
5111                isUserMenuHover = false;
5112                dropDownMenuHide($userMenu);
5113                //$userMenu.hide();
5114                $burgerIconMin.removeClass('is-active');
5115                
5116            }
5117            e.preventDefault();
5118            e.stopPropagation();
5119        });
5120        */
5121    }
5122
5123    $(document).on("click", "a", function() {
5124        if (ctrlPressed || commandPressed) {
5125            // ok, do nothing
5126        } else if ($(this).attr("href") && utils.endsWith(window.location.href, $(this).attr("href"))) {
5127            // ok, do nothing
5128        } else if ($(this).attr("href") && ($(this).attr("href") == "#" || $(this).attr("href").match(/^#\d+$/) || $(this).attr("href").match(/^#comm\d+$/) || $(this).attr("href") == "#wrapWorkComm")) {
5129            if ($(this).attr("id") && $(this).attr("id") == "loginBtn")
5130                startNProgress();
5131            // ok, do nothing
5132        } else if ($(this).attr("target") && $(this).attr("target") == "_blank") {
5133            // ok, do nothing
5134        } else if ($(this).hasClass("aPopup") || $(this).hasClass("blogCommCnt") || $(this).hasClass("phNameLink") || $(this).hasClass("modBtn") || $(this).hasClass("inactTabA") || $(this).hasClass("re-icon") || $(this).hasClass("anchor_hash")) {
5135            // ok, do nothing
5136        } else if ($(this).hasClass("saveBtn") || $(this).hasClass("commButtons") || $(this).hasClass("addBtn") || $(this).hasClass("themeBtn")) {
5137            if ($(this).hasClass("facebook"))
5138                startNProgress();
5139            else if ($(this).attr("id") && $(this).attr("id") == "submit_login")
5140                startNProgress();
5141            // ok, do nothing
5142        } else if ($(this).attr("id") && $(this).attr("id") == "loginDivName") {
5143            // ok, do nothing
5144        } else {
5145            startNProgress();
5146        }
5147    }).on("click", "#previewCatName", function(e) {
5148        closePreviewPopup();
5149    }).on("click", "#closeMobVerLnk", function(e) {
5150        cookie.setMinutesCookie("mobVerBlkHidden", 1, 60 * 24 * 7);
5151        $('#mobVerBlk').slideUp();
5152        e.preventDefault();
5153    });
5154
5155    updateQuoteHover($contentDiv);
5156
5157    if (window.location.pathname !== '/gallery.php' && isShareToView && cookie.getCookie("share_views_cnt") >= 5 && cookie.getCookie("share_post_id") == null) {
5158        closePreviewPopup();
5159
5160        $("#previewOverlay2").css({
5161            "background-color": "rgba(0, 0, 0, .45)"
5162        }).delay(5000).fadeIn(500);
5163        $("#shareToView").delay(5000).fadeIn(500);
5164        $("#signClose").delay(8500).fadeIn(0);
5165    }
5166
5167    var $shareToViewVK = $("#shareToViewVK");
5168    $shareToViewVK.click(function(e) {
5169        cookie.setMinutesCookie("share_post_id", "1", 60 * 24 * 365);
5170    });
5171
5172    $("#goad, #previewGoad").on("click", function(e) {
5173        var goad = "<i>" + (new Date()).toString() + "</i><br><a href=\"" + window.location.href + "\" target=\"_blank\">" + window.location.href + "</a>" + "<br><b>id_auth</b>: " + id_auth_log;
5174        $.get('/classes/goad.php?goad=' + encodeURIComponent(goad));
5175    });
5176
5177});
5178
5179// handle image crop
5180var CropMode = false;
5181var BWMode = false;
5182var cropBoxResizable = true;
5183var aspectRatio = 0;
5184var crop_padding = 40;
5185var crop_x = crop_padding;
5186var crop_y = crop_padding;
5187var crop_w = crop_padding * 2;
5188var crop_h = crop_padding * 2;
5189
5190function pasteCropInComm() {
5191    if (CropMode) {
5192        var cropBoxData = $mainImage.cropper('getCropBoxData');
5193        var factor = 1;
5194        if (utils.isTouch() && $myWndW <= $ipadWndW) {
5195            factor = imageBGMainWInit / ph_width;
5196            if (factor > 1)
5197                factor = 1;
5198        }
5199        crop_x = Math.round(cropBoxData.left / factor);
5200        crop_y = Math.round(cropBoxData.top / factor);
5201        crop_w = Math.round(cropBoxData.width / factor);
5202        crop_h = Math.round(cropBoxData.height / factor);
5203
5204        getEl("comment").value = getEl("comment").value + " [Crop:" + crop_x + ":" + crop_y + ":" + crop_w + ":" + crop_h + "] ";
5205        getEl('comment').focus();
5206        scrollTopMenu(document.body.scrollHeight);
5207    }
5208}
5209
5210function destroyCrop() {
5211    $('#mainImage').cropper('destroy');
5212}
5213
5214function showCrop(x, y, w, h) {
5215    if (BWMode)
5216        doDesaturate();
5217    var factor = 1;
5218    if (utils.isTouch() && $myWndW <= $ipadWndW) {
5219        factor = imageBGMainWInit / ph_width;
5220        if (factor > 1)
5221            factor = 1;
5222    }
5223    crop_x = x * factor;
5224    crop_y = y * factor;
5225    crop_w = w * factor;
5226    crop_h = h * factor;
5227    toggleCrop(true);
5228
5229}
5230
5231function removeHash() {
5232    history.pushState("", document.title, window.location.pathname + window.location.search);
5233}
5234
5235function updateCropUI(isToUpdate) {
5236    if (CropMode && !isToUpdate) {
5237        $("#crop_button").attr("src", "/img/tool_crop1.gif");
5238        $("#crop_down").hide();
5239        $("#add_crop_lnk__wrap").hide();
5240        CropMode = false;
5241    } else {
5242        scrollTopMenu(50);
5243        $("#crop_button").attr("src", "/img/tool_crop2.gif");
5244        $("#crop_down").show();
5245        $("#add_crop_lnk__wrap").show();
5246        CropMode = true;
5247        // remove hash from url
5248        removeHash();
5249    }
5250}
5251
5252function toggleCrop(isToUpdate) {
5253    if (BWMode)
5254        doDesaturate();
5255
5256    if (CropMode) {
5257        if (isToUpdate) {
5258            $mainImage.cropper('setCropBoxData', {
5259                left: crop_x,
5260                top: crop_y,
5261                width: crop_w,
5262                height: crop_h
5263            });
5264            updateCropUI(isToUpdate);
5265        } else {
5266            destroyCrop();
5267            updateCropUI(isToUpdate);
5268        }
5269    } else {
5270        $mainImage.cropper({
5271            viewMode: 0,
5272            checkCrossOrigin: false,
5273            checkOrientation: false,
5274            modal: false,
5275            background: false,
5276            autoCropArea: 1,
5277            aspectRatio: aspectRatio,
5278            cropBoxResizable: cropBoxResizable,
5279            rotatable: false,
5280            zoomable: false,
5281            highlight: false,
5282            minContainerWidth: 20,
5283            minContainerHeight: 20,
5284            built: function() {
5285                $mainImage.cropper('setCropBoxData', {
5286                    left: crop_x,
5287                    top: crop_y,
5288                    width: crop_w,
5289                    height: crop_h
5290                });
5291            },
5292            crop: function(e) {
5293                crop_x = e.x;
5294                crop_y = e.y;
5295                crop_w = e.width;
5296                crop_h = e.height;
5297            }
5298        });
5299        updateCropUI(isToUpdate);
5300    }
5301
5302    $workWrap = $("#workWrap");
5303    $cropBg = $('.cropper-drag-box');
5304
5305    bg = $workWrap.css('background-color');
5306    tc = $workWrap.find('#image_description').css('color');
5307    $cropBg.css('background-color', bg);
5308
5309    $('#add_crop_lnk').css('color', tc);
5310}
5311
5312function grayscaleIE10(src) {
5313    var canvas = document.createElement('canvas');
5314    var ctx = canvas.getContext('2d');
5315    var imgObj = new Image();
5316    imgObj.src = src;
5317    canvas.width = imgObj.width;
5318    canvas.height = imgObj.height;
5319    ctx.drawImage(imgObj, 0, 0);
5320    var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
5321    for (var y = 0; y < imgPixels.height; y++) {
5322        for (var x = 0; x < imgPixels.width; x++) {
5323            var i = (y * 4) * imgPixels.width + x * 4;
5324            var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
5325            imgPixels.data[i] = avg;
5326            imgPixels.data[i + 1] = avg;
5327            imgPixels.data[i + 2] = avg;
5328        }
5329    }
5330    ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
5331    return canvas.toDataURL();
5332}
5333
5334function doDesaturate() {
5335    if (!BWMode) {
5336        if (CropMode) {
5337            destroyCrop();
5338            updateCropUI(false);
5339        }
5340
5341        $("#mainImage").addClass("grayscale");
5342        if (document.getElementById('bw_button'))
5343            document.getElementById('bw_button').src = '/img/tool_bw2.gif';
5344    } else {
5345        $("#mainImage").removeClass("grayscale");
5346        if (document.getElementById('bw_button'))
5347            document.getElementById('bw_button').src = '/img/tool_bw1.gif';
5348    }
5349    BWMode = !BWMode;
5350}
5351
5352function showImgFromLnk(o) {
5353    var oHtml = o.innerHTML;
5354    if (oHtml.indexOf("<img ") === -1)
5355        o.innerHTML = '<img src="' + oHtml + '">';
5356    return false;
5357
5358    //setLastPos();
5359}
5360/*
5361window["scroll_evt"] = {
5362    "delta": 0,
5363    "delay": 0,
5364    "direction": 0,
5365    "time": Date.now(),
5366    "pos": $(window).scrollTop(),
5367    "min_delta": 80,
5368    "min_delay": 10
5369};
5370
5371
5372
5373$(window).scroll(function() {
5374
5375
5376    var currentScroll = $(this).scrollTop();
5377
5378
5379    var currentTime = Date.now();
5380    var boolRun = (window["scroll_evt"]["min_delay"] > 0) ? (Math.abs(currentTime - window["scroll_evt"]["time"]) > window["scroll_evt"]["min_delay"]) : false;
5381    boolRun = boolRun && ((window["scroll_evt"]["min_delta"] > 0) ? (Math.abs(currentScroll - window["scroll_evt"]["pos"]) > window["scroll_evt"]["min_delta"]) : false);
5382    if (boolRun) {
5383        window["scroll_evt"]["delta"] = currentScroll - window["scroll_evt"]["pos"];
5384        window["scroll_evt"]["direction"] = window["scroll_evt"]["delta"] > 0 ? 'down' : 'up';
5385        window["scroll_evt"]["delay"] = currentTime - window["scroll_evt"]["time"];
5386        //in milisecs
5387        window["scroll_evt"]["pos"] = currentScroll;
5388        window["scroll_evt"]["time"] = currentTime;
5389        handleScroll(currentScroll);
5390
5391    }
5392});
5393*/
5394
5395var scrollDirection;
5396
5397$(window.document).on('mousewheel DOMMouseScroll', function(e) {
5398
5399    if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
5400        scrollDirection = 'up';
5401
5402    } else {
5403        scrollDirection = 'down';
5404
5405    }
5406
5407});
5408
5409$(window).scroll(function() {
5410    handleScroll(scrollDirection);
5411});
5412
5413var mouseY;
5414$(window).mousemove(function(e) {
5415    mouseY = Math.round(e.pageY - $(window).scrollTop());
5416}).mouseover();
5417
5418
5419
5420
5421
5422function setSmallHeader1() {
5423    $("#header").addClass('smallHeader');
5424    $("#header").addClass('wsubShadow');
5425
5426    $('#logo a').addClass('colorBlack');
5427
5428
5429    $('#header.smallHeader #loginAvatar .usmenu').css({ width: '38px', height: '38px' });
5430    $('#header.smallHeader #loginDiv table').css('margin-top', '0px');
5431    $('#userMenu').css({ top: '47px' });
5432    $('.hamburger-inner').addClass('grayBurgerIcon');
5433    $('#header.smallHeader #burgerIconMin3.hamburger').css('padding-top', '7px');
5434
5435    $('#qSearch, #selector, #selectorMenu').addClass('blackBorderColor');
5436
5437
5438}
5439
5440function restoreHeader1() {
5441    $("#header").removeClass('smallHeader');
5442    $("#header").removeClass('wsubShadow');
5443
5444
5445    $('#logo a').removeClass('colorBlack');
5446
5447
5448    $('#loginAvatar .usmenu').css({ width: '44px', height: '44px' }).css('filter', '');
5449    $('#loginDiv table').css('margin-top', '');
5450    $('#userMenu').css({ top: '53px' });
5451    $('.hamburger-inner').removeClass('grayBurgerIcon');
5452    $('#burgerIconMin3.hamburger').css('padding-top', '');
5453
5454
5455    $('.wrapGallPath').show();
5456
5457    $('#menuTbl li').css('height', '');
5458
5459    $('#qSearch, #selector, #selectorMenu').removeClass('blackBorderColor');
5460}
5461
5462function fdSwitch() {
5463
5464    if (window.location.hash.search('followers') != -1 || window.location.hash.search('comm_give') != -1 || window.location.hash.search('comm_got') != -1 || document.URL.indexOf('more=') != -1 && (window.location.hash.search('recs=') != -1 || window.location.hash.search('favor=') != -1)) {
5465        $("#authorWorks").removeClass('fdSwitch');
5466        //$(".flexDiv").removeClass('fdSwitch');
5467        //$("#contentTableProfile, #authInfoBlk").removeClass('fdSwitch');
5468        $(".footer-dark").removeClass('fdSwitch');
5469        $("#contentDiv").removeClass('fdSwitch');
5470        //$(".aboutPortraitWrap").css('margin-top', '56px');
5471    }
5472}
5473
5474function handleScroll(scrollDirection) {
5475
5476    var currScroll = Math.round($(document).scrollTop());
5477
5478
5479    //log('currentScroll:', currentScroll);
5480
5481    var $wSubMenu = $("#wSubMenu");
5482    var $thinWS = $("#wSubMenu.thinWS");
5483    var $apmWbg = $("#apmWbg");
5484    var $header = $("#header");
5485    var $wrapGallPath = $('#wrapGallPath');
5486    var $wrapWorkComm = $('#wrapWorkComm');
5487    var $content = $('#content.galleryContent');
5488    var $mainContent = $('#content');
5489    var $formContent = $('.formContent, .myWorksContent');
5490    var $searchTD = $("#searchTD");
5491    var $wrapWorkActions = $("#wrapWorkActions");
5492    var ws = document.getElementById('wSubMenu');
5493    var apmWbg = document.getElementById('apmWbg');
5494
5495    var authorProfil = $("#header").hasClass("authProfileHeader");
5496
5497    var noPreviewPopup = $("#previewPopup").css('display') == 'none';
5498
5499    var padd, posit;
5500
5501    if (document.URL.indexOf('/add.php') != -1 || document.URL.indexOf('/my_galleries.php') != -1 || document.URL.indexOf('/pers.php') != -1 || document.URL.indexOf('/pass.php') != -1 || document.URL.indexOf('/settings.php') != -1 || document.URL.indexOf('/subscribe.php') != -1 || document.URL.indexOf('/banned.php') != -1 || document.URL.indexOf('/abo.php') != -1 || document.URL.indexOf('/my_series.php') != -1 || document.URL.indexOf('/my_albums.php') != -1 || document.URL.indexOf('/my_portfolio.php') != -1 || document.URL.indexOf('/my_themes.php') != -1 || document.URL.indexOf('/my_css.php') != -1 || document.URL.indexOf('/my_index.php') != -1 || document.URL.indexOf('/my_pages.php') != -1 || document.URL.indexOf('/comm.php') != -1 || document.URL.indexOf('/comm.debug.php') != -1 || document.URL.indexOf('/feed.debug.php') != -1 || document.URL.indexOf('/actions.debug.php') != -1 || document.URL.indexOf('/feed.php') != -1 || document.URL.indexOf('/actions.php') != -1 || document.URL.indexOf('/my_works.php') != -1 || document.URL.indexOf('/my_works.debug.php') != -1 || document.URL.indexOf('/my_market.php') != -1 || document.URL.indexOf('/assets_ownership.php') != -1 || document.URL.indexOf('/sales.php') != -1 || document.URL.indexOf('/global.php') != -1) {
5502        padd = 40;
5503        posit = 'fixed';
5504        top = 0;
5505    } else if (document.URL.indexOf('/galleries.php') != -1) {
5506        padd = 40;
5507        posit = 'fixed';
5508        top = 0;
5509    } else {
5510        padd = 110;
5511        posit = 'absolute';
5512        top = 30;
5513    }
5514
5515    if (document.URL.indexOf('/comm.php') != -1 || document.URL.indexOf('/feed.php') != -1 || document.URL.indexOf('/actions.php') != -1) {
5516        posit = 'absolute';
5517    }
5518
5519    if (noPreviewPopup) {
5520
5521        if (currScroll >= 25) {
5522
5523          
5524
5525            $header.addClass('wsubShadow');
5526
5527       
5528
5529        } else {
5530
5531            $header.removeClass('wsubShadow');
5532
5533            $wrapGallPath.show();
5534        
5535        }
5536    }
5537
5538    // work.php page
5539    if (typeof imageBGMain !== 'undefined') {
5540
5541
5542        if (scrollDirection == "up" && currScroll > $wrapWorkActions.offset().top) {
5543            $header.css('position', 'fixed');
5544        } else {
5545            $header.css('position', 'absolute');
5546        }
5547
5548    } else if ((ws !== null || apmWbg !== null) && noPreviewPopup && !authorProfil) {
5549        //if (window["scroll_evt"]["direction"] == "down" && currentScroll >= 680) {
5550        if (scrollDirection == "down") {
5551
5552            if (currScroll >= 700) {
5553
5554                //$header.css('background', 'transparent');
5555                $header.fadeOut(250);
5556                //$wSubMenu.fadeOut(50);
5557                //$searchTD.fadeOut(50);
5558
5559                $(".tr00rDiv, .blogsSticky").css('top', '10px');
5560
5561                //$apmWbg.fadeOut(250);
5562
5563                //$apmWbg.css('visibility', 'hidden');
5564
5565                dropDownMenuHide($('.uMenuClass'));
5566                $(".burgerIconMin").removeClass('is-active');
5567
5568
5569            }
5570
5571        } else {
5572
5573            if(mouseY <= 400 || currScroll < 250) {
5574            
5575                $header.fadeIn(150);
5576                //$wSubMenu.fadeIn(50);
5577                //$searchTD.fadeIn(50);
5578                // setTimeout(function() {
5579                //     $header.css('background', '');
5580                // }, 50);
5581
5582                $(".tr00rDiv, .blogsSticky").css('top', '105px');
5583
5584                //$apmWbg.fadeIn(250);
5585                //$apmWbg.css('visibility', 'visible');
5586            }
5587           
5588
5589        }
5590    }
5591}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.