PageSourceSearch

https://godsdirectcontact.net/js/main.js?327919264536

js godsdirectcontact.net collected 2026-09-24 21:21:35 UTC 127,190 bytes, 4,040 lines download raw bytes

1// JavaScript Document
2var LANG_DIR_ADD = "1";       //fix for url 1 addon,en1,ch1
3var LANGS_ARRAY = new Array(); 	//from language menu
4var VW_MOBILE = 970;
5var VW_NOTEBOOK = 1400;
6var videoPlayerData = { "sourceDefault": "video", "upnextPoster": "", "upnextVideoTitle": "", "upnextVideoLength": "", "upnextUrl": "" };
7
8var mainObjLang = null;
9var mainObjSearch = null;
10var mainObjPlayer = null;
11var mainObjPlayerBox = null; //not use
12var mainObjPlayList = null;
13var mainObjPlayPage = null;
14var mainObjNav = null;
15var youtubeApiloaded = false;
16var ipCountry = '';
17
18var processDataServer = "https://www2.suprememastertv.com/";
19if (String(window.location.host).indexOf("localhost") > -1) {
20   processDataServer = "http://localhost:5001/";
21}
22var mainHeaderStatus = { "visibility": "hidden", "style": "normal" };
23
24////////////////////////////////
25
26function scrollDisable() {
27   if(isPc()){
28     document.documentElement.style.overflow = 'hidden';
29   }
30}
31function scrollEnable() {
32   if(isPc()){
33     document.documentElement.style.overflow = 'auto';
34   }
35}
36
37function getXml(data, flag) {
38   var reg = new RegExp("<" + flag + ">([\\s\\S]*)</" + flag + ">", "i");
39   var code = data.match(reg);
40   var find = code == null ? "" : code[1];
41   return find;
42}
43
44function empty(obj) {
45   if (typeof obj == "undefined") {
46      return true;
47   }
48   obj = String(obj).replace(/\s*/g, "");
49   if (obj == null || obj == "") {
50      return true;
51   } else {
52      return false;
53   }
54}
55function exist(id) {
56   if (document.getElementById(id)) {
57      return true;
58   }
59   return false;
60}
61
62function setCookie(cname, cvalue, exdays) {
63   var d = new Date();
64   d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
65   var expires = "expires=" + d.toUTCString();
66   document.cookie = cname + "=" + cvalue + "; " + expires;
67}
68
69function getCookie(cname) {
70   var name = cname + "=";
71   var ca = document.cookie.split(';');
72   for (var i = 0; i < ca.length; i++) {
73      var c = ca[i];
74      while (c.charAt(0) == ' ') c = c.substring(1);
75      if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
76   }
77   return "";
78}
79
80function getNum() {
81   var str = arguments[0] ? arguments[0] : "";
82   var type = arguments[1] ? arguments[1] : "float";
83   if (str == "") { return 0; }
84
85   var num = 0;
86   if (type == "int") {
87      num = parseInt(str);
88   }
89   if (type == "float") {
90      num = parseFloat(str);
91   }
92
93   num = isNaN(num) ? 0 : num;
94   return num;
95}
96
97function getObjWidth() {
98   //obj type=int,type=float	
99   var obj = arguments[0] ? arguments[0] : null;
100   var type = arguments[1] ? arguments[1] : "float";
101   if ($(obj).length == 0) { return 0 }
102   var w = 0;
103   w = getNum(obj.width(), type);
104   w += getNum(obj.css("padding-left"), type);
105   w += getNum(obj.css("padding-right"), type);
106   w += getNum(obj.css("border-left"), type);
107   w += getNum(obj.css("border-right"), type);
108   w += getNum(obj.css("margin-left"), type);
109   w += getNum(obj.css("margin-right"), type);
110
111   return w;
112}
113
114function getObjHeight() {
115   var obj = arguments[0] ? arguments[0] : null;
116   var type = arguments[1] ? arguments[1] : "int";
117   if ($(obj).length == 0) { return 0 }
118
119   var h = 0;
120   h = getNum(obj.height(), type);
121   h += getNum(obj.css("padding-top"), type);
122   h += getNum(obj.css("padding-bottom"), type);
123   h += getNum(obj.css("border-top"), type);
124   h += getNum(obj.css("border-bottom"), type);
125   h += getNum(obj.css("margin-top"), type);
126   h += getNum(obj.css("margin-bottom"), type);
127
128   return h;
129}
130
131//video length to time //short
132function sTotimeLess(s) {
133   s = Math.floor(s);
134   var t = "";
135   if (s < 0) { return 0; }
136   var hour = Math.floor(s / 3600);
137   var min = Math.floor(s / 60) % 60;
138   var sec = s % 60;
139
140   if (hour > 0) { t = hour + ":"; }
141   if (hour > 0) {
142      if (min < 10) { t = t + "0"; }
143      t = t + min + ":";
144   } else {
145      if (min > 0) {
146         t = t + min + ":";
147      }
148   }
149
150   t = sec < 10 && t != "" ? t + "0" : t;
151   t = t + sec;
152   return t;
153}
154
155//video length to time
156function sTotime(s) {
157   s = Math.floor(s);
158   var t = "";
159   if (s < 0) { return 0; }
160   var hour = Math.floor(s / 3600);
161   var min = Math.floor(s / 60) % 60;
162   var sec = s % 60;
163
164   if (hour < 10) { t = t + "0"; }
165   t = t + hour + ":";
166
167   if (min < 10) { t = t + "0"; }
168   t = t + min + ":";
169
170   if (sec < 10) { t = t + "0"; }
171   t = t + sec;
172
173   return t;
174}
175
176function timeToSec(time) {
177   if (time == "") { return 0; }
178   time = String(time);
179   time = time.replace(" ", "");
180   time = time.replace(":", ":");
181   time = time.replace(".", ":");
182   time = time.replace(",", ":");
183   time = time.replace(",", ":");
184   timeA = time.split(":");
185   var h = 0;
186   var m = 0;
187   var s = 0;
188   if (timeA.length == 3) {
189      h = getNum(timeA[0]);
190      m = getNum(timeA[1]);
191      s = getNum(timeA[2]);
192   }
193   if (timeA.length == 2) {
194      m = getNum(timeA[0]);
195      s = getNum(timeA[1]);
196   }
197   if (timeA.length == 1) {
198      s = getNum(timeA[0]);
199   }
200
201   var sum = h * 3600 + m * 60 + s;
202   return sum;
203}
204
205function inArray(search, array) {
206   for (var i in array) {
207      if (array[i] == search) {
208         return true;
209      }
210   }
211   return false;
212}
213
214function getCurrentLang() {
215   var url = window.location.href;
216   var reg = new RegExp("/([\\S]{2})" + LANG_DIR_ADD + "/");
217   var langs = url.match(reg);
218   if (typeof (langs[1]) != undefined) {
219      return langs[1];
220   } else {
221      return "en";
222   }
223}
224
225function htmlToText(data) {
226   if (data == "") { return ""; }
227   data = data.replace("<", "&lt;");
228   data = data.replace(">", "&gt;");
229   data = data.replace('"', '&quot;');
230   return data;
231}
232
233function isPc() {
234   return $(document).width() > VW_MOBILE;
235}
236
237function isMobile() {
238   return $(document).width() < VW_MOBILE;
239}
240
241function isTouchDevice() {
242   return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
243}
244
245function isElementInViewport(element) {
246   var $element = $(element);
247   var windowTop = $(window).scrollTop() - 200;
248   var windowBottom = $(window).scrollTop() + $(window).height() + 200;
249   var elementTop = $element.offset().top;
250   var elementBottom = elementTop + $element.outerHeight();
251   return (elementTop >= windowTop && elementBottom <= windowBottom);
252}
253
254/////////////////////////////  
255//navGallery
256$(function () {
257   jQuery.fn.navGallery = function (options) {
258      var opts = $.extend({
259         style: "", 			          //single or blank,
260
261         btnLeft: "btn-nav-left",    //left button
262         btnRight: "btn-nav-right",  //right button
263         btnLRVisibility: "hide",    //show/hide, left right button visibility		
264         btnLRLessHide: "hide",      //show/hide, item less, hide left right button 
265
266         nav: "nav",                 //nav id
267         navBtns: "nav-btns", 	    //type buttons
268         navPoint: "nav-point",      //points 
269         
270         page: "1",	                //default num or page
271         items: "items",             //items 
272         range: "range",	          //range
273         itemCurrent: 1,
274
275         transform: "slide",		    //"slide","fade"		
276         autoSwitch: false,  
277         timeAnimation: 0,
278         loop: true,         
279         touch: true
280
281      }, options);
282
283
284      //
285      var obj = $(this);
286
287      //style single
288      var style = opts["style"];
289
290      //find nav button
291      var objNavBtns = obj.find("#" + opts["nav"]).find("#" + opts["navBtns"]);
292      if (objNavBtns.length == 0) {
293         objNavBtns = obj.parent().find("#" + opts["nav"]).find("#" + opts["navBtns"]);
294      }
295      if (objNavBtns.length == 0) {
296         objNavBtns = $("#" + opts["nav"]).find("#" + opts["navBtns"]);
297      }
298
299      var objBtnLeft  = obj.find("[id=" + opts["btnLeft"] + "]");
300      var objBtnRight = obj.find("[id=" + opts["btnRight"] + "]");
301      var btnLRVisibility = opts["btnLRVisibility"];
302      var objNavPoint = obj.find("[id=" + opts["navPoint"] + "]");
303      var objNavMore = obj.find("#nav-more");
304      var objRange  = obj.find("." + opts["range"]);
305      var objItems = objRange.find("." + opts["items"]);
306
307      var objCover = obj.find("#pics-cover"); //if have cover
308      var coverIsHide = true;
309
310      var rangeWidth = 0;
311      var itemsWidth = 0;     
312      var itemCurrent = opts["itemCurrent"]; 
313
314      var pageTotal = 0;   	//total page      
315      var pagePrev = 1;		   //prev page
316      var pageDefault = getNum(opts["page"]);
317      pageDefault = pageDefault < 1 ? 1 : pageDefault;
318      var pageCurrent = pageDefault;  	//current page
319
320      var timerNavHide = null;
321      var timerResetWidth = null;
322
323      var isSwitching = false;
324
325      var autoSwitchAllow = true;
326      var timeAutoSwitch = 3000;
327      var timerAutoSwitch = null;
328            
329
330      //default mobile 300,pc 400/1000
331      var timeAnimation = 400;
332      if (opts["transform"] == "fade") {
333         timeAnimation = opts["timeAnimation"] == 0 ? 400 : opts["timeAnimation"];
334      } else {
335         if (isMobile()) {
336            timeAnimation = opts["timeAnimation"] == 0 ? 300 : opts["timeAnimation"];
337         } else {
338            timeAnimation = opts["timeAnimation"] == 0 ? 1000 : opts["timeAnimation"];
339         }
340      }
341
342      var switchLoop = style == "single" ? false : opts["loop"];
343      var isSlideLoop = switchLoop && opts["transform"] == "slide";
344
345      //slide loop, first append, last append
346      var slideXdiff = 0;
347
348      //touch event
349      var touchAllow = style == "single" || opts["transform"] == 'fade' || isPc()? false : opts["touch"];      
350      var touchOffsetX = 0;
351      var touchInitialX = 0;
352      var touchStartX = 0;
353      var touchStartY = 0;
354      var touchDirection = null;
355
356      init();
357
358      function init() {
359         //
360         if (objItems.children().length < 2) {
361            if (opts["btnLRLessHide"] == "hide") {
362               objNavPoint.hide();
363               btnLRHide("left");
364               btnLRHide("right");
365               objNavMore.hide();
366            } else {
367               objNavPoint.show();
368               objBtnLeft.show();
369               objBtnRight.show();
370               objNavMore.show();
371            }
372            return;
373         }
374         
375         reset();
376         navBtnsPositionReset();
377         navPointInit();
378         navPointSet();      
379
380         //bind event
381         if (btnLRVisibility == "hide") {
382
383            btnLRHide("left");
384            btnLRHide("right");
385
386            obj.on("mouseover.navGallery", function () {
387               objBtnLeft.show();
388               objBtnRight.show();
389               autoSwitchAllow = false;
390               try { clearInterval(timerNavHide); } catch (e) { }
391            });
392
393            obj.on("mouseout.navGallery", function () {
394               timerNavHide = setTimeout(function () {
395                  btnLRHide("left");
396                  btnLRHide("right");
397                  autoSwitchAllow = true;
398                  autoSwitch();
399               }, 200);
400            });
401
402         }
403         
404         objNavPoint.on("click.navGallery", function () {
405            if(isMobile()){
406              autoSwitchAllow = true;
407            }
408         });
409
410         objBtnLeft.on("click.navGallery", function () {
411            btnLRclick($(this), 'btnLeft');
412         });
413
414         objBtnRight.on("click.navGallery", function () {
415            btnLRclick($(this), 'btnRight');
416         });
417
418
419         if (touchAllow) {
420            objItems.on('touchstart.navGallery', function (e) {
421               autoSwitchAllow = false;
422               if (isSwitching) {
423                  return;
424               }
425               touchDirection = null;
426               var touch = e.originalEvent.touches[0];
427               touchStartX = touch.pageX;
428               touchStartY = touch.pageY;
429               // Get current transform
430               touchOffsetX = getLeft();
431               touchInitialX = touch.pageX - touchOffsetX;
432               objItems.css({
433                  "transition-duration": 0 + "ms"
434               });
435            });
436
437            objItems.on('touchmove.navGallery', function (e) {
438               if (isSwitching) {
439                  return;
440               }
441
442               var touch = e.originalEvent.touches[0];
443               //allow up down
444               if(touchDirection == "up"){
445                  return;
446               }
447
448               //confirm touch Direction
449               if(Math.abs(touch.pageY - touchStartY)>Math.abs(touch.pageX - touchStartX)){
450                  touchDirection = "up";
451               }
452
453               autoSwitchAllow = false;
454
455               e.preventDefault();
456               touchOffsetX = touch.pageX - touchInitialX;
457
458               $(this).css('transform', 'translateX(' + touchOffsetX + 'px)');
459            });
460
461            objItems.on('touchend.navGallery', function (e) {
462               var touch = e.originalEvent.changedTouches[0];
463               var endX = touch.pageX;
464               var distanceMoved = endX - touchStartX;
465
466               autoSwitchAllow = true;
467
468               if (Math.abs(distanceMoved) > 30) {
469                  if (distanceMoved > 0) {
470                     btnLRclick(null, 'btnLeft');
471                  } else {
472                     btnLRclick(null, 'btnRight');
473                  }
474
475                  //return  
476               } else {
477                  btnLRclick();
478               }
479            });
480         }
481
482         
483         $(window).resize(function () {
484             var w = getNum(objRange.width());
485
486             if(w != rangeWidth){
487               try { clearTimeout(timerResetWidth); } catch (e) { }
488               timerResetWidth = setTimeout(function () { resetWidth("resize"); }, 1000);
489             }            
490         });         
491
492         //autoSwitch
493         if (opts["autoSwitch"]) {
494            autoSwitch();
495         }
496      }
497
498      function btnLRclick(eve, btn) {
499         if (isSwitching) { return; }
500         navPatch();
501
502         //for slide		
503         if (rangeWidth == 0) {
504            reset();
505         }
506
507         //for fade
508         pageCurrent = getCurrentPage();
509         pagePrev = pageCurrent; 
510
511         //
512         if (eve != null && $(eve).attr("class").indexOf("disable") > -1) {
513            return;
514         }
515         
516         //default 
517         if (btn == "btnLeft") {
518            pageCurrent--;
519            pageCurrent = pageCurrent < 1 ? pageTotal : pageCurrent;            
520         }
521
522         if (btn == "btnRight") {
523            pageCurrent++;
524            pageCurrent = pageCurrent > pageTotal ? 1 : pageCurrent;
525         }
526 	   		   
527         var index = pageCurrent - 1;
528         var left = -index * rangeWidth;
529
530         //single
531         if(btn == "btnLeft" && style == "single"){
532            left = getLeft();
533            left += rangeWidth;
534         }
535         if(btn == "btnRight" && style == "single"){
536            left = getLeft();
537            left -= rangeWidth;
538         }
539
540         hideCover();
541         move(left, "normal", btn);    
542         checkScrollLoading();     
543      }
544
545
546      function reset() {
547         pageCurrent = pageDefault;
548         pagePrev = pageDefault - 1;
549
550         objItems.children().css({ "visibility": "visible" });
551         objItems.css({ "transform": "translateX(0px)" });
552
553         //slide loop, add first and last
554         if (isSlideLoop) {
555            //clear temp
556            objItems.children().each(function () {
557               if ($(this).attr("class").indexOf("temp") > -1) {
558                  $(this).remove();
559               }
560            });
561            //add temp
562            var firstChild = objItems.children().first().clone(true);
563            firstChild.addClass("temp");
564            var lastChild = objItems.children().last().clone(true);
565            lastChild.addClass("temp");
566
567            objItems.append(firstChild);
568            objItems.prepend(lastChild);
569         }         
570
571         //reset cover, like about M, art work
572         if (objCover.length > 0) {
573            coverIsHide = false;
574            objCover.show();
575            objNavPoint.children().removeClass("current");
576            objNavBtns.children().removeClass("current");
577         }
578
579         resetWidth("reset");
580      }
581
582
583      function resetWidth(when) {
584         //range width  
585         rangeWidth = getNum(objRange.width());
586         if (rangeWidth == 0) {
587            return;
588         }
589
590         //reset items Width
591         itemsWidth = 0;
592         objItems.children().each(function () {
593            if ($(this).attr("class").indexOf("temp") > -1) {
594               return;
595            }
596            if (style == "single") {
597               itemsWidth += getObjWidth($(this));
598            } else {
599               itemsWidth += rangeWidth;
600            }
601         });
602
603         //count total pages
604         if (opts["transform"] == "slide") {
605            pageTotal = Math.ceil(itemsWidth / rangeWidth);
606         } else {
607            pageTotal = objItems.children().length;
608         }         
609         pageTotal  = Math.max(pageTotal ,0);
610
611
612         //more btns ,left right ,in line right
613         if (style == "single" && objNavMore.length > 0 && objNavMore.css("position") == "absolute") {
614            var navMoreWidth = getObjWidth(objNavMore);
615            rangeWidth = rangeWidth - navMoreWidth;
616         }
617
618         //if window resize ,single bar get pageCurrent again
619         if (when == "resize") {
620            pageCurrent = getCurrentPage();
621            navBtnsPositionReset();
622         }
623
624         //slide loop ,need patch
625         if (isSlideLoop) {
626            slideXdiff = -rangeWidth;
627         } else {
628            slideXdiff = 0;
629         }
630
631         //single, have current number, set position
632         if (when == "reset" && opts["transform"] == "slide" && style == "single" && itemCurrent > 1) {
633            var leftTemp = 0;
634            var max = itemCurrent - 1;
635
636            //get current item left
637            objItems.children().slice(0, max).each(function () {
638               leftTemp += getObjWidth($(this));
639            });
640
641            //mobile have left button
642            var diff = 0;
643            if (objRange.find("#btn-left-mobile").length > 0) {
644               diff = getObjWidth(objRange.find("#btn-left-mobile"));
645            }
646
647            //mobile scroll
648            if (objRange.css("overflow-x") == "scroll") {
649               objRange.scrollLeft(leftTemp + diff);
650
651            //pc translate  
652            } else {
653               leftTemp = -leftTemp;                   
654               leftTemp = Math.max(leftTemp, rangeWidth-itemsWidth);
655                        
656               objItems.css({ "transform": "translateX(" + leftTemp + "px)" });
657            }
658         }
659         
660         //slide: modify item x 
661         //fade: modify current layer	           
662         if(style != "single") {
663           var left = -(pageCurrent - 1) * rangeWidth;
664           move(left, "soon", "");
665         }
666
667         btnLRSet(); 
668      }
669
670
671      //auto switch
672      function autoSwitch() {
673         if (!opts["autoSwitch"]) {
674            return;
675         }
676
677         autoSwitchStop();
678         try {
679            timerAutoSwitch = setTimeout(function () {
680               if (!autoSwitchAllow || isSwitching) {
681                  return;
682               }
683
684               btnLRclick(null, "btnRight");
685            }, timeAutoSwitch);
686         } catch (e) { }
687      }
688
689      function autoSwitchStop() {
690         try { clearTimeout(timerAutoSwitch); } catch (e) { }
691      }
692
693
694
695      /*
696      if default num is not 1
697      show current item position left ,like schedule
698      */
699      function navBtnsPositionReset() {
700         //count btns width  
701         var btnsWidthTotal = 0;
702         objNavBtns.children().each(function () {
703            btnsWidthTotal += getObjWidth($(this));
704         });
705
706         var obBtnsParent = objNavBtns.parent();
707         //count range width  
708         var btnsRangeWidth = getObjWidth(obBtnsParent);
709
710         //btns left  
711         var btnsLeft = 0;
712         //get current item left
713         objNavBtns.children().slice(0, pageCurrent - 1).each(function () {
714            btnsLeft -= getObjWidth($(this));
715         });
716         
717         //confirm left
718         btnsLeft = Math.max(btnsLeft, btnsRangeWidth - btnsWidthTotal);
719         btnsLeft = Math.min(btnsLeft, 0);
720         
721         //mobile left scroll, in schedule
722         if (obBtnsParent.css("overflow-x") == "scroll") {
723            var diff = 0;
724            if (obBtnsParent.find("#btn-left-mobile").length > 0) {
725               diff = getObjWidth(obBtnsParent.find("#btn-left-mobile"));
726            }
727            obBtnsParent.scrollLeft(Math.abs(btnsLeft) + diff);
728            //pc     
729         } else {
730            objNavBtns.css({ "transform": "translateX(" + btnsLeft + "px)" });
731         }
732      }
733
734      function navPointInit() {
735         //show each point
736         objNavPoint.children().remove();
737         for (var i = 0; i < pageTotal; i++) {             
738            objNavPoint.append("<div></div>");
739         }
740
741         //on click  
742         objNavBtns.children().off("click.navGallery");
743         objNavPoint.children().off("click.navGallery");
744         objNavBtns.children().add(objNavPoint.children()).on("click.navGallery", function () {         
745            if (isSwitching) { return; }
746            //rangeWidth is 0, may be element hide, reset width
747            if (rangeWidth == 0) { reset(); }
748
749            var index = $(this).index();
750            var left = -index * rangeWidth;
751
752            pagePrev = pageCurrent;
753            pageCurrent = index + 1;
754            hideCover();
755            move(left, "normal", "");     
756            checkScrollLoading();       
757         });
758      }
759
760      function navPointSet() {
761         if (!coverIsHide) { return; }
762         var index = pageCurrent - 1;
763
764         objNavPoint.each(function () {
765            $(this).children().removeClass("current");
766         });
767         objNavPoint.each(function () {
768            $(this).children().eq(index).addClass("current");
769         });
770
771         objNavBtns.children().removeClass("current");
772         objNavBtns.children().eq(index).addClass("current");
773      }
774
775
776      function btnLRHide(btn) {
777         var obj = null;
778         if (btn == "left") {
779            obj = objBtnLeft;
780         } else {
781            obj = objBtnRight;
782         }
783         obj.each(function () {
784            //have display attribute, not hide
785            var display = $(this).attr("display");
786            if (!display) {
787               $(this).css("visibility", "visible").hide();
788            }
789         });
790      }
791
792      //nav left right button need always display
793      function btnLREnable(btn, val) {
794         var obj = null;
795         if (btn == "left") {
796            obj = objBtnLeft;
797         } else {
798            obj = objBtnRight;
799         }
800         obj.each(function () {
801            if (val == "enable") {
802               $(this).removeClass("btndisable");
803            } else {
804               $(this).addClass("btndisable");
805            }
806         });
807      }
808
809      //check and set btn left right status
810      function btnLRSet(left = 'auto') {
811         btnLREnable("left", "enable");
812         btnLREnable("right", "enable");
813
814         if (switchLoop) {
815            return;
816         }
817
818         //get left
819         if (left == 'auto') {
820            left = getLeft();
821         }
822
823         //
824         if (style == "single") {
825            if (left >= "0") {
826               btnLREnable("left", "disable");
827            }
828            if (left <= rangeWidth - itemsWidth) {
829               btnLREnable("right", "disable");
830            }
831         } else {
832            if (pageCurrent == "1") {
833               btnLREnable("left", "disable");
834            }
835            if (pageCurrent == pageTotal) {
836               btnLREnable("right", "disable");
837            }
838         }
839      }
840
841      /*
842      if navbar is not from x=0, other app changed the navbar position
843      need caculate item num id likd schedule date bar 
844      */
845      function getCurrentPage() {
846         var num = pageCurrent;
847         if (style == "single") {
848            var left = Math.abs(getLeft());
849            num = Math.ceil(left / rangeWidth) + 1;            
850         }
851         num = parseInt(num);
852         num = num <= 0 ? 1 : num;
853         return num;
854      }
855
856      function hideCover() {
857         coverIsHide = true;
858         objCover.fadeOut(300);
859      }
860
861      //get left from transform css   
862      function getLeft() {
863         var pos = objItems.css("transform");
864         var x = 0;
865         if (typeof (pos) != "undefined") {
866            pos = pos.replace(/[^0-9\.\-,]/g, '');
867            var vars = pos.split(",");
868            var x = getNum(vars[4]);
869         }
870         return x;
871      }
872
873      function confirmLeft(left) {         
874         left = Math.max(left, rangeWidth - itemsWidth);
875         left = Math.min(left, 0);         
876         left += slideXdiff;
877         return left;
878      }
879
880      function move(left, speed, eventFrom) {   
881
882         //mobile return
883         if (opts["transform"] == "slide" && objRange.css("overflow-x") == "scroll") {
884            return;
885         }               
886
887         left = confirmLeft(left);
888
889         navPointSet();
890         autoSwitch();
891         btnLRSet(left);   
892         
893         var time = 0;         
894
895         //slide
896         if(opts["transform"] == "slide") {            
897            isSwitching = true;
898            
899            if (eventFrom == "btnLeft" || eventFrom == "btnRight") {
900               time = timeAnimation;
901            } else {
902               time = Math.abs(pageCurrent - pagePrev) * timeAnimation / 1.5;
903               time = Math.max(time,timeAnimation);
904               time = Math.min(time,timeAnimation * 1.5);
905            }
906            time = speed == "soon" ? 0 : time;            
907
908            //slide loop, next is first
909            if (pagePrev == pageTotal && pageCurrent == 1 && eventFrom == "btnRight" && switchLoop) {
910
911               var leftTemp = -pageTotal * rangeWidth + slideXdiff;
912               objItems.css({
913                  "transform": "translateX(" + leftTemp + "px)",
914                  "transition-duration": time + "ms"
915               });
916               setTimeout(function () {
917                  objItems.css({
918                     "transform": "translateX(" + left + "px)",
919                     "transition-duration": 0 + "ms"
920                  });
921               }, time);
922
923               //slide loop, next is last   
924            } else if (pagePrev == 1 && pageCurrent == pageTotal && eventFrom == "btnLeft" && switchLoop) {
925
926               var leftTemp = 0;
927               objItems.css({
928                  "transform": "translateX(" + leftTemp + "px)",
929                  "transition-duration": time + "ms"
930               });
931               setTimeout(function () {
932                  objItems.css({
933                     "transform": "translateX(" + left + "px)",
934                     "transition-duration": 0 + "ms"
935                  });
936               }, time);
937
938               //slide normal    
939            } else {
940               
941               objItems.css({
942                  "transform": "translateX(" + left + "px)",
943                  "transition-duration": time + "ms"
944               });
945            }
946
947            setTimeout(function () {
948               isSwitching = false;
949            }, time);
950         }
951
952
953         //fade
954         if (opts["transform"] == "fade" && !isSwitching) {
955            if (pageCurrent == pagePrev) {
956               return;
957            }
958            time = speed == "soon" ? 0 : timeAnimation;
959            isSwitching = true;
960            var itemIndex = pageCurrent - 1;
961            var itemPrev = pagePrev - 1;
962
963            objItems.children().eq(itemPrev).fadeOut(time);
964            objItems.children().css({ "z-index": "100" });
965            objItems.children().eq(itemIndex).css({ "position": "absolute", "z-index": "200" });
966            objItems.children().eq(itemIndex).fadeIn(time, function () {
967               objItems.children().css({ "z-index": "100" });
968               objItems.children().each(function () {
969                  if ($(this).index() != itemIndex) {
970                     $(this).hide();
971                  }
972               });
973               objItems.children().eq(itemIndex).css({ "position": "static" });
974               isSwitching = false;
975               pagePrev = pageCurrent;
976            });
977         }
978
979      }
980
981
982
983      //patch for font loaded, because font size is diffent			
984      function navPatch() {
985         w = 0;
986         if (style == "single") {
987            objItems.children().each(function () {
988               w += getObjWidth($(this));
989            });
990         } else {
991            w = objItems.children().length * rangeWidth;
992         }
993
994         if (w != itemsWidth && w != 0) {
995            itemsWidth = w;
996         }
997      }
998
999      //scroll load image  				
1000      function checkScrollLoading() {
1001         var itemIndex = pageCurrent - 1;
1002         var obj = objItems.children().eq(itemIndex);
1003         var objScroll = obj.find(".scroll-loading");
1004         if (objScroll.length == 0) { return; }
1005         objScroll.each(function () {
1006            var tag = $(this)[0].nodeName;
1007            tag = tag.toLowerCase();
1008
1009            var url = $(this).attr("img-url");
1010            if (url != "") {
1011               if (tag == "img") {
1012                  $(this).attr("src", url);
1013               }
1014               if (tag == "div") {
1015                  $(this).css("background-image", "url(" + url + ")");
1016               }
1017            }
1018
1019            $(this).removeAttr("img-url");
1020            $(this).removeAttr("img-autoload");
1021            $(this).removeClass("scroll-loading");
1022         });
1023      }
1024
1025      function getNum() {
1026         var str = arguments[0] ? arguments[0] : "";
1027         var type = arguments[1] ? arguments[1] : "float";
1028         if (str == "") { return 0; }
1029
1030         var num = 0;
1031         if (type == "int") {
1032            num = parseInt(str);
1033         }
1034         if (type == "float") {
1035            num = parseFloat(str);
1036         }
1037
1038         num = isNaN(num) ? 0 : num;
1039         return num;
1040      }
1041
1042      function getObjWidth() {
1043         var obj = arguments[0] ? arguments[0] : null;
1044         var type = arguments[1] ? arguments[1] : "float";
1045         if ($(obj).length == 0) { return 0 }
1046         var w = 0;
1047         w = getNum(obj.width(), type);
1048         w += getNum(obj.css("padding-left"), type);
1049         w += getNum(obj.css("padding-right"), type);
1050         w += getNum(obj.css("border-left"), type);
1051         w += getNum(obj.css("border-right"), type);
1052         w += getNum(obj.css("margin-left"), type);
1053         w += getNum(obj.css("margin-right"), type);
1054
1055         return w;
1056      }
1057
1058   };
1059});
1060
1061//////////////////////////////
1062//main player
1063var youTubePlayerInited = false;
1064function onYouTubeIframeAPIReady() {
1065   youTubePlayerInited = true;
1066}
1067
1068var MainPlayer = MainPlayer || {};
1069MainPlayer = (function (options) {
1070   var opts = $.extend({
1071      playerBox: "playerbox",
1072   }, options);
1073
1074   var playerId = "player";
1075   var objYouTubePlayer = null;
1076   var objVideoPlayer = null;
1077   var counterTryAutoPlay;
1078   var counterTryYouTube;
1079   var timerYouTube = null;
1080   var timerAutoPlay = null;
1081   var playerInViewport = true;
1082   var objUpnext = $("#upnext");
1083
1084   var playerBoxId = opts["playerBox"];
1085   var playerBox = $("#"+playerBoxId);
1086   var playerBottomBtnsContainer = $("#player-btns");
1087
1088   setTimeout(playerResize, 10);
1089   setTimeout(playerResize, 1000);
1090   $(window).off("resize.player").on("resize.player",playerResize);
1091
1092   bottomBtnsInit();
1093
1094   //set player height    
1095   function playerResize() {
1096      var height = getNum(getObjWidth(playerBox) / 1.777);
1097      playerBox.height(height);
1098   }
1099
1100   function clearPlayer() {            
1101      try { objYouTubePlayer.destroy(); } catch (e) { }
1102      try { clearInterval(timerYouTube); } catch (e) { }      
1103      try { objVideoPlayer.dispose();  } catch (e) { }
1104
1105      objYouTubePlayer = null;
1106      objVideoPlayer = null;
1107      playerBox.children().remove();
1108      playerBox.html("");
1109      objUpnext.hide();
1110
1111   }
1112
1113   function showError() {
1114      playerBox.append("<div class=\"errorbox\">We are sorry, this video is not available.</div>");
1115   }
1116
1117   //options 
1118   function showPlayer(options) {
1119      var opts = $.extend({
1120         playerBox: "",
1121         poster: "",
1122         youTube: "",
1123         videoFile: "",
1124         sourceDefault: "video", //video,audio	  
1125         ignoreError: false
1126      }, options);
1127      var youTube = opts["youTube"];
1128      var videoFile = opts["videoFile"];
1129      var poster = opts["poster"];
1130      var sourceDefaultRes = "720p";
1131      var sourceDefault = opts["sourceDefault"];
1132      sourceDefault = sourceDefault == "video" || sourceDefault == "" ? sourceDefaultRes : sourceDefault;     
1133      
1134      bottomBtnsInit();
1135
1136      //ajax page, new playerbox
1137      if(opts['playerBox']!=''){         
1138         playerBoxId = opts["playerBox"];
1139         playerBox = $("#"+playerBoxId);
1140      } 
1141
1142      //start time	
1143      var start = 0;
1144      if (typeof (videoPlayerData["start"]) != "undefined" && videoPlayerData["start"]!="") {
1145         start = parseInt(videoPlayerData["start"]);
1146      }
1147      var url = window.location.search.substring(1);
1148      var vars = url.split("&");
1149      for (var i = 0; i < vars.length; i++) {
1150         var pair = vars[i].split("=");
1151         if (pair[0] == "start") {
1152            start = pair[1];
1153         }
1154      }
1155      start = start == "" ? 0 : start;
1156
1157      //volume pc default 50%
1158      var volume = getCookie("playerVolume");
1159      var timerSetVolume = null;
1160      if (isMobile()) {
1161         volume = 1;
1162      } else if (volume == "") {
1163         volume = 0.5;
1164      }      
1165
1166      //find resolutions for videojs
1167      var resolutions = new Array();
1168      if (typeof (videoFile) == "string" && videoFile != "") {
1169         var reg = new RegExp("<item>(.+?)<\/item>", "ig");
1170         var resArray = videoFile.match(reg);
1171         for (var i = 0; i < resArray.length; i++) {
1172            var resName = String(resArray[i]).match(/<resolution>(.+?)<\/resolution>/);
1173            var resUrl = String(resArray[i]).match(/<file_url>(.+?)<\/file_url>/);
1174            if (resUrl != null) {
1175               resolutions.push([resName[1], resUrl[1]]);
1176            }
1177         }
1178      } else if (typeof (videoFile) == "object") {
1179         resolutions = videoFile;
1180      }
1181
1182      //confirm have audio mp3
1183      var foundAudioRes = false;
1184      for (var i = 0; i < resolutions.length; i++) {
1185         if (resolutions[i][0] == "audio") {
1186            foundAudioRes = true;
1187         }
1188      }
1189
1190      //errors	
1191      if (resolutions.length == 0 && youTube == "" && opts['ignoreError'] == false) {
1192         showError(); 
1193         return;
1194      }
1195
1196      if (empty(youTube) && empty(videoFile) && opts['ignoreError'] == false) {
1197         showError(); 
1198         return;
1199      }
1200      
1201      //confirm player type	
1202      var playerType = "youTube";
1203      if (youTube == "") { playerType = "website"; }
1204      if (sourceDefault == "audio" && foundAudioRes) {
1205         playerType = "website";
1206      }
1207
1208      //ru youtube cant't use
1209      if(playerType == "youTube" && ipCountry == 'ru' && videoFile!=''){
1210         mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"] });
1211         return;
1212      }
1213
1214      //clear all player data	
1215      clearPlayer();
1216      playerResize();
1217      loadingShow("loading-player", "show");
1218
1219      //
1220      if(youTube.indexOf("http")>-1){
1221          if(youTube.indexOf("rel")==-1) {
1222             youTube += "&rel=0";
1223          }
1224          playerBox.append('<iframe width="100%" height="100%" src="'+youTube+'" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>');
1225          loadingShow("loading-player", "hide");
1226          return;
1227      } 
1228
1229      //some pages the video not at top   
1230      playerInViewport = isElementInViewport(playerBox);
1231      var autoPlayYouTube = playerInViewport ? 1 : 0;
1232      var autoVideoPlayer = playerInViewport ? "true" : "false";
1233
1234
1235      //youTube	
1236      if (playerType == "youTube") {
1237         playerBox.append("<div id=\"" + playerId + "\"></div>");
1238         //load youtube api
1239         if (!youtubeApiloaded) {
1240            youtubeApiloaded = true;
1241            var tag = document.createElement('script');
1242            tag.src = "https://www.youtube.com/iframe_api?v=" + Math.ceil(Math.random() * 100);
1243            var firstScriptTag = document.getElementsByTagName('script')[0];
1244            firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);            
1245         }
1246         
1247
1248         //wait youtube api loaded
1249
1250         counterTryYouTube = 30;
1251         timerYouTube = setInterval(function () {
1252            //time out,may be network error, use videojs player  
1253            if (counterTryYouTube <= 0) {
1254               clearInterval(timerYouTube);               
1255               mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"] });
1256            }
1257            //youtube api loaded     
1258            if (youTubePlayerInited) {
1259               clearInterval(timerYouTube);
1260               youTubePlayerinit();
1261               loadingShow("loading-player", "hide");
1262            }
1263            counterTryYouTube--;
1264         }, 200);
1265
1266         function youTubePlayerinit() {
1267            objYouTubePlayer = new YT.Player(playerId, {
1268               height: '100%',
1269               width: '100%',
1270               host: 'https://www.youtube.com',
1271               videoId: youTube,
1272               playerVars: { 'autoplay': autoPlayYouTube, 'rel': 0, 'start': start },
1273               events: {
1274                  'onReady': onYouTubeReady,
1275                  'onStateChange': onYouTubeStateChange,
1276                  'onError': onYouTubeError
1277               }
1278            });
1279         }
1280
1281         function onYouTubeError(event) {
1282            mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"] });
1283         }
1284         //player is ready to play  
1285         function onYouTubeReady(event) {
1286            playerAutoPlay();
1287
1288            //if duration is 0, use videojs player
1289            if (objYouTubePlayer.getDuration() == "0" && opts['ignoreError'] == false) {
1290               mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"] });
1291               return;
1292            }
1293            
1294            //can't play, use videojs player
1295            if (playerInViewport) {
1296               setTimeout(function () {                  
1297                  try {
1298                     if (objYouTubePlayer.getPlayerState() == "-1") {                       
1299                        //mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"] });
1300                     }
1301                  } catch (e) { }
1302               }, 10000);
1303            }
1304         }
1305
1306         //play finish upnext
1307         function onYouTubeStateChange(event) {            
1308            if (objYouTubePlayer.getPlayerState() == 0) {                
1309               try {                  
1310                  mainObjPlayList.upnext();
1311                  } catch (e) {                    
1312                  showReplay();   
1313               }
1314            }
1315         }
1316
1317         //change source label, in play page	  
1318         setTimeout(function () {
1319            try { resourceLabel("youTube"); } catch (e) { }
1320         }, 0);
1321
1322         videoPlayerData["sourceDefault"] = "video";
1323
1324      } else {
1325         //video player
1326         var codeVideoPlayer = $("<video id=\"" + playerId + "\" width=\"100%\" height=\"100%\" poster=\"" + poster + "\" class=\"video-js vjs-default-skin vjs-big-play-centered\" data-setup='{\"controls\": true, \"auto
1326play\": " + autoVideoPlayer + " }'>Your browser does not support HTML5 video.</video>");
1327         playerBox.append(codeVideoPlayer);
1328
1329         var sources = new Array();
1330         var sourceFoundDefault = false;
1331         for (var i = 0; i < resolutions.length; i++) {
1332            var videoSrc = resolutions[i][1].indexOf("192.168") > -1 ? "http://" + resolutions[i][1] : VSERVER + resolutions[i][1];
1333            var videoType = resolutions[i][1].indexOf("mp4") > -1 ? "video/mp4" : "";
1334            videoType = resolutions[i][1].indexOf("mp3") > -1 ? "audio/mp3" : "";
1335
1336            //labelName 
1337            var labelName = resolutions[i][0];
1338            if (typeof (vjsLang[resolutions[i][0]]) != "undefined") {
1339               labelName = vjsLang[resolutions[i][0]];
1340            }
1341            sources[i] = { src: videoSrc, type: videoType, label: labelName };
1342            //default source
1343            if (resolutions[i][0].toLowerCase() == sourceDefault.toLowerCase()) {
1344               sourceFoundDefault = true;
1345               sources[i]["selected"] = true;
1346            }
1347         }
1348
1349         //if not found custom defaut source ,try find 720p default 
1350         if (!sourceFoundDefault) {
1351            for (var i = 0; i < resolutions.length; i++) {
1352               if (resolutions[i][0].toLowerCase() == sourceDefaultRes.toLowerCase()) {
1353                  sourceDefault = sourceDefaultRes;
1354                  sources[i]["selected"] = true;
1355               }
1356            }
1357         }
1358
1359         var options = {
1360            sources: sources,
1361            controlBar: {
1362               children: [
1363                  'playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl',
1364                  'customControlSpacer', 'pictureInPictureToggle', 'qualitySelector', 'fullscreenToggle'
1365               ],
1366            },
1367            autoplay: true
1368         };
1369
1370         //load video js language words 
1371         if (typeof (vjsLang) != "undefined") {
1372            options["language"] = 'vjsLanguage';
1373         }
1374         
1375
1376         objVideoPlayer = videojs(playerId, options, function onPlayerReady() {
1377            this.volume(volume);
1378
1379            //try auto play    
1380            playerAutoPlay();
1381
1382            objVideoPlayer.currentTime(start);
1383
1384            objVideoPlayer.on("ended", function () {
1385               try {
1386               mainObjPlayList.upnext();
1387               } catch (e) {
1388                  showReplay();
1389               }
1390            });
1391
1392            //save user volume    
1393            objVideoPlayer.on('volumechange', function () {
1394               var level = this.volume();
1395               try { clearTimeout(timerSetVolume); } catch (e) { }
1396               timerSetVolume = setTimeout(setCookie("playerVolume", level, 30), 1000);
1397            });
1398
1399            objVideoPlayer.on('fullscreenchange', function () {
1400               $(".vjs-tech").addClass("fullscreen");
1401            });
1402
1403            objVideoPlayer.on('loadstart', function () {
1404               var videoType = objVideoPlayer.currentType();
1405               if (videoType.indexOf("video") > -1) {
1406                  try { resourceLabel("website"); } catch (e) { }
1407                  videoPlayerData["sourceDefault"] = "video";
1408               }
1409               if (videoType.indexOf("audio") > -1) {
1410                  try { resourceLabel("website-audio"); } catch (e) { }
1411                  videoPlayerData["sourceDefault"] = "audio";
1412               }
1413            });
1414
1415            //mobile:touch skip/fullscreen,modify loading style	   
1416            objVideoPlayer.mobileUi();
1417
1418            //video js hot keys,     
1419            objVideoPlayer.hotkeys();
1420
1421         });
1422
1423
1424         //try label change	 	 	
1425         if (sourceDefault == "audio") {
1426            try { resourceLabel("website-audio"); } catch (e) { }
1427            videoPlayerData["sourceDefault"] = "audio";
1428         } else {
1429            try { resourceLabel("website"); } catch (e) { }
1430            videoPlayerData["sourceDefault"] = "video";
1431         }
1432      }
1433      //video player end
1434
1435      //update counter
1436      $.post(processDataServer + 'handle.php', {
1437         type: "counter", id: videoPlayerData["vid"]
1438      });
1439
1440   }
1441
1442   function showReplay(){  
1443      objUpnext = $("#upnext");
1444                     
1445      if(objUpnext.length>0){ 
1446
1447         objUpnext.css({ "visibility": "visible" }).show();
1448         objUpnext.find('.title').hide();
1449         objUpnext.find('.stop').hide();
1450         objUpnext.find('.vbox').hide();
1451
1452         objBtnReplay = objUpnext.find("#btn-replay");   
1453  
1454         //replay	
1455         objBtnReplay.off("click.this").on("click.this", function () {
1456            objUpnext.css({ "visibility": "visible" }).hide();
1457            mainObjPlayer.replay();
1458         });
1459      }
1460   }
1461
1462
1463   //auto update video length
1464   function updateVideoLength(l) {
1465      if (typeof (videoPlayerData["videoLength"]) == "undefined") { return; }
1466      if (typeof (videoPlayerData["vid"]) == "undefined") { return; }
1467      if (videoPlayerData["videoLength"] != "" && videoPlayerData["videoLength"] != "0") { return; }
1468      if (l == "" || videoPlayerData["vid"] == "") { return; }
1469      var url = processDataServer + 'handle.php';
1470      $.post(url, { type: "videolength", id: videoPlayerData["vid"], video_length: l });
1471   }
1472
1473   //player
1474   function playerAutoPlay() {
1475      loadingShow("loading-player", "hide");
1476
1477      var videoLengthUpdated = false;
1478      try { clearInterval(timerAutoPlay); } catch (e) { }
1479
1480      counterTryAutoPlay = 5;
1481      var duration = 0, length = 0, current = 0;
1482
1483      timerAutoPlay = setInterval(function () {
1484         if (playerInViewport) {
1485            try { objVideoPlayer.play(); } catch (e) { };
1486            try { objYouTubePlayer.playVideo(); } catch (e) { };
1487         }
1488
1489         if (objVideoPlayer != null) {
1490            try { duration = getNum(objVideoPlayer.duration()); } catch (e) { }
1491            try { current = getNum(objVideoPlayer.currentTime()); } catch (e) { }
1492         } else {
1493            try { duration = getNum(objYouTubePlayer.getDuration()); } catch (e) { }
1494            try { current = getNum(objYouTubePlayer.getCurrentTime()); } catch (e) { }
1495         }
1496
1497         length = sTotime(duration);
1498
1499         if (duration > 0 && !videoLengthUpdated) {
1500            videoLengthUpdated = true;
1501            updateVideoLength(length);
1502         }
1503
1504         if (counterTryAutoPlay <= 0 || current > 0) {
1505            clearInterval(timerAutoPlay);
1506            return;
1507         }
1508         counterTryAutoPlay--;
1509      }, 1000);
1510   }
1511
1512   function playerStop() {
1513      try { objVideoPlayer.pause(); } catch (e) { };
1514   }
1515
1516   function replay() {
1517      try {
1518         objVideoPlayer.currentTime(0)
1519         objVideoPlayer.play();
1520      } catch (e) { }
1521
1522      try {
1523         objYouTubePlayer.playVideo();
1524         objYouTubePlayer.seekTo(1);
1525      } catch (e) { }
1526   }
1527
1528   function loadingShow(id, style) {
1529      if (style == "show") {
1530         $("#" + id).css({ "visibility": "visible" }).show();
1531      } else {
1532         $("#" + id).hide();
1533      }
1534   }
1535
1536   function getPlayerBoxObj(){
1537      return $("#"+playerBoxId);
1538   }
1539
1540
1541   
1542//resource label
1543function resourceLabel(label) {
1544  if(playerBottomBtnsContainer.length<0) { 
1545     return; 
1546  }
1547  var obj = playerBottomBtnsContainer.find("[id=btn-resource]");
1548  var labelWebsite = null;
1549  var labelYouTube = null;
1550  var labelAudio = null;
1551  label = label.toLowerCase();
1552
1553  obj.each(function () {
1554    var btnclass = $(this).attr("class");
1555    if (btnclass.indexOf("youtube") > -1) {
1556      labelYouTube = $(this);
1557    }
1558    if (btnclass.indexOf("website") > -1) {
1559      labelWebsite = $(this);
1560    }
1561    if (btnclass.indexOf("audio") > -1) {
1562      labelAudio = $(this);
1563    }
1564  });
1565  
1566  obj.removeClass("current");
1567
1568  if (label.indexOf("youtube") > -1) {
1569    labelYouTube.addClass("current");
1570  } else if (label.indexOf("audio") > -1) {
1571    labelAudio.addClass("current");
1572  } else {
1573    labelWebsite.addClass("current");
1574  }
1575}
1576
1577function bottomBtnsInit() {
1578  //for news, re init
1579  playerBottomBtnsContainer = $("#player-btns");
1580  if(playerBottomBtnsContainer.length<0) { 
1581     return; 
1582  }
1583
1584  playerBottomBtnsContainer.find("#btn-share").off("click.player").on("click.player", function () {
1585    dialogShow("dialog-share");
1586  });
1587
1588  playerBottomBtnsContainer.find("#btn-download").off("click.player").on("click.player", function () {
1589    dialogShow("dialogbox-download");
1590  });
1591
1592  playerBottomBtnsContainer.find("#btn-mobile").off("click.player").on("click.player", function () {
1593    dialogShow("mobile");
1594  });
1595
1596  //onclick close
1597  $("[id=btn-download-link").off("click.player").on("click.player", function () {
1598    dialogClose();
1599  });
1600
1601  //button note
1602  var timerHideButtonNote = null;
1603  var secondHideButtonNote = 5000;
1604  var objNote = playerBottomBtnsContainer.find("#btn-note");
1605  objNote.css({ "visibility": "visible" }).hide();
1606
1607  var objBottomBtns = playerBottomBtnsContainer.find(".btn");
1608  objBottomBtns.off("mouseover.player").on("mouseover.player", function () {
1609    var left = getNum($(this).offset().left);
1610    var note = $(this).attr("note");
1611
1612    //btn-theater note change
1613    if ($(this).attr("id") == "btn-theater") {
1614      if ($(this).attr("class").indexOf("ico-theater") > -1) {
1615        note = $(this).attr("note-theater");
1616      } else {
1617        note = $(this).attr("note-default-view");
1618      }
1619    }
1620
1621    if (typeof (note) == "undefined" || note == "undefined") {
1622      return;
1623    }
1624
1625    objNote.find("#btn-note-text").html(note);
1626
1627    var noteWidth = objNote.width() + getNum(objNote.css("padding-left")) * 2;
1628    var btnWidth = $(this).width() + getNum($(this).css("padding-left")) * 2;
1629
1630    if (noteWidth > btnWidth) {
1631      left = left - (noteWidth - btnWidth) / 2;
1632    } else {
1633      left = left + (btnWidth - noteWidth) / 2;
1634    }
1635    objNote.css({ "left": left });
1636    setTimeout(()=>{objNote.show()},1);
1637
1638    //for mobile hide note
1639    try { clearTimeout(timerHideButtonNote); } catch (e) { }
1640    timerHideButtonNote = setTimeout(function () { objNote.hide(); }, secondHideButtonNote);
1641
1642  });
1643
1644  objBottomBtns.off("mouseleave.player").on("mouseleave.player", function () {
1645    objNote.hide();
1646  });
1647
1648
1649  //change resource                     
1650  playerBottomBtnsContainer.find("[id=btn-resource]").off("click.player").on("click.player", function () {
1651    var btnclass = $(this).attr("class");
1652    if (btnclass.indexOf("youtube") > -1) {
1653      mainObjPlayer.showPlayer({ youTube: videoPlayerData["youTubeUrl"] });
1654    } else if (btnclass.indexOf("website") > -1) {
1655      mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"] });
1656    } else if (btnclass.indexOf("audio") > -1) {
1657      mainObjPlayer.showPlayer({ poster: videoPlayerData["videoPoster"], videoFile: videoPlayerData["videoFile"], sourceDefault: "audio" });
1658    }
1659  });
1660}
1661
1662
1663   return {
1664      showPlayer: showPlayer,
1665      clearPlayer: clearPlayer,
1666      replay: replay,
1667      getPlayerBoxObj:getPlayerBoxObj
1668   }
1669
1670});
1671
1672
1673////////////////////////////////
1674//main play list
1675var MainPlayList = MainPlayList || {};
1676MainPlayList = (function (options) {
1677
1678   var opts = $.extend({
1679      listId: 'playlist-loader',
1680      listGroupIds: "",    //id array new Array("list-today","list-related","list-latest")
1681      pageName: "normal",  //1.normal 2.v(for play page)
1682      listClickTo: "page", //1.page:ajax mode, 1.url:open news window
1683      showCurrent: false,  //1.ture ,search videoid in playlist and scroll list ,2.false 
1684      defautlGroup: "",     //group id, used in v.php, n.php
1685      init: true
1686   }, options);
1687
1688   var defautlGroup = opts["defautlGroup"];
1689   var playListGroupIds = opts["listGroupIds"];
1690   var playListGroupCurrent = null;
1691   playListGroupCurrent = defautlGroup != "" ? defautlGroup : playListGroupCurrent;
1692   var playListIndexCurrent = null;
1693   var playListIndexNext = 0;
1694   var playListDataId = null;
1695   
1696   var objPlayList = $("#"+opts["listId"]);
1697   var pageName = opts["pageName"];
1698   var showCurrent = opts["showCurrent"];
1699   var listClickTo = opts["listClickTo"];
1700
1701   //use for scroll to current,
1702   var objListBox = new Array();
1703   for (var i = 0; i < playListGroupIds.length; i++) {
1704      objListBox[playListGroupIds[i]] = null;
1705   }
1706
1707   if(opts["init"]){
1708      init();
1709   }
1710
1711   function init() {      
1712      var playlistHeight = getPlaylistHeight();
1713      for (var i = 0; i < playListGroupIds.length; i++) {
1714         if (objListBox[playListGroupIds[i]] == null) {
1715            objListBox[playListGroupIds[i]] = $("#" + playListGroupIds[i]).scrollList({ rangeHeight: playlistHeight, currentId: videoPlayerData["vid"] });
1716         }
1717      }
1718
1719      //for click  
1720      objPlayList.find("a").off("click.playlist").on("click.playlist", function () {
1721
1722         if($(this).attr("open-url")!=undefined){
1723            return;
1724         }
1725
1726         //ignore download link  
1727         var className = String($(this).attr("class"));
1728         if (className.indexOf("btn-download") > -1) { return; }
1729
1730         //clear upnext data  
1731         videoPlayerData["upnextVideoTitle"] = "";
1732
1733         //remove list today current, in home page	
1734         $("#list-today").find("a").removeClass("current-play");
1735
1736         upnextClose();
1737         //save live player, in home page
1738         saveLivePlayer();
1739         //confirm  playListIndexCurrent playListGroupCurrent 		
1740         var pobj = $(this).parent();
1741         for (var i = 0; i < 10; i++) {
1742            pobj = pobj.parent();
1743
1744            //1 find vbox	
1745            if (String(pobj.attr("class")).indexOf("vbox") > -1) {
1746               //count vboxes  
1747               var vboxes = pobj.parent().find(".vbox");
1748               for (var j = 0; j < vboxes.length; j++) {
1749                  if ($(vboxes[j]).attr("id") == pobj.attr("id")) {
1750                     playListIndexCurrent = j;
1751                  }
1752               }
1753            }
1754            //2 find list id	
1755            if (inArray(pobj.attr("id"), playListGroupIds)) {
1756               playListGroupCurrent = pobj.attr("id");
1757               break;
1758            }
1759         }
1760
1761         var thisClickTo = $(this).attr("clickto");
1762
1763         //home page	play in this page
1764         if ((String(thisClickTo) == "undefined" || String(thisClickTo) == "page") && listClickTo == "page") {
1765            //for home list tody	
1766            var id = "";
1767            if (playListGroupCurrent == "list-today") {
1768               id = $(this).attr("id");
1769               //remove list today current		      
1770               $("#list-today").find("a").removeClass("current-play");
1771               var tarp = $(this).parent();
1772               for (var i = 0; i < 10; i++) {
1773                  if (String(tarp.attr("class")).indexOf("item-t") > -1) {
1774                     tarp.find("a").addClass("current-play");
1775                     break;
1776                  }
1777                  tarp = tarp.parent();
1778               }
1779            }
1780
1781            playVideo({ id: id });
1782            return false;
1783         }
1784
1785      });
1786
1787      //click live, in home page
1788      $("#btn-home-live").on("click", function () { 
1789         showLivePlayer(); 
1790      });
1791
1792      updateListStyle();
1793      setTimeout(function () { updateListStyle(); }, 10);
1794      $(window).resize(function () { setTimeout(updateListStyle, 100); });
1795
1796      //for home page
1797      setTimeout(function () {
1798         CategoryView().init({ viewContainer: "playlist-loader", buttonContainer: "playlist-tabs", view: "list-box", action: "over" });
1799      }, 10);
1800
1801      //show current item    
1802      if (showCurrent) {
1803         findCurrent();
1804      }
1805   }
1806
1807
1808   //v.php need find current item, scroll to current
1809   function findCurrent() {
1810      var vboxes = $("#" + playListGroupCurrent).find(".vbox");
1811      for (var j = 0; j < vboxes.length; j++) {
1812         if ($(vboxes[j]).attr("id") == videoPlayerData["vid"]) {
1813            $("#" + playListGroupCurrent).find(".vbox").eq(j).addClass("vboxcurrent");;
1814            playListIndexCurrent = j;
1815         }
1816      }
1817      //scroll to current
1818      setTimeout(function () { objListBox[playListGroupCurrent].setCurrent(videoPlayerData["vid"]); }, 300);
1819   }
1820
1821   function updateListStyle() {
1822      if (isMobile()) {
1823         return;
1824      }
1825      var playListHeight = getPlaylistHeight();
1826      for (var i = 0; i < playListGroupIds.length; i++) {
1827         objListBox[playListGroupIds[i]].resetHeight(playListHeight);
1828      }
1829   }
1830
1831   function getPlaylistHeight() {
1832      var playerBoxObj = mainObjPlayer.getPlayerBoxObj();
1833      var playerHeight = getNum(getObjWidth(playerBoxObj) / 1.777);
1834      var tabsHeight = getObjHeight($("#playlist-tabs"));
1835      var listBarNewsHeight = getObjHeight($("#list-bar-news")); // for n.php
1836      var playListHeight = playerHeight - tabsHeight - getNum(objPlayList.css("padding-top")) - getNum(objPlayList.css("padding-bottom")) - listBarNewsHeight;
1837
1838      //for play page.v.php
1839      if (pageName == "v") {
1840         playListHeight = getObjHeight(playerBoxObj) + getObjHeight($("#player-btns")) - 1;
1841         playListHeight = playListHeight - getObjHeight($("#list-bar-play"));
1842      }    
1843   
1844      return playListHeight;
1845   }
1846
1847   //find play list next id
1848   function playListFindNext() {
1849
1850      var findIndex = 0;
1851      var listObj = $("#" + playListGroupCurrent);
1852      //find play list
1853      if ($(listObj).find(".vbox").length > 0) {
1854         playListIndexNext = playListIndexCurrent + 1;
1855         if (playListIndexNext >= $(listObj).find(".vbox").length) {
1856            playListIndexNext = 0;
1857         }
1858         findIndex = playListIndexNext;
1859      } else {
1860         //find related
1861         listObj = $("#related-content");
1862         if ($(listObj).find(".vbox").length == 0) {
1863            return;
1864         }
1865      }
1866
1867      var objVbox = $(listObj).find(".vbox").eq(findIndex);
1868      var poster = objVbox.find(".simagebox").css("background-image");
1869      var videoTitle = objVbox.find(".titles").find("a").html();
1870      var videoLength = objVbox.find(".length").html();
1871      var url = objVbox.find(".titles").find("a").attr("href");
1872      //if play page have view mode
1873      try { url = mainObjPlayPage.addPlayerModeVar(url); } catch (e) { }
1874
1875      videoPlayerData["upnextPoster"] = poster;
1876      videoPlayerData["upnextVideoTitle"] = videoTitle;
1877      videoPlayerData["upnextVideoLength"] = videoLength;
1878      videoPlayerData["upnextUrl"] = url;
1879   }
1880
1881
1882   function playVideo(options = {}) {
1883   
1884      var sourceDefault = "video";
1885      if (typeof (options["sourceDefault"]) != "undefined") {
1886         sourceDefault = options["sourceDefault"];
1887      }
1888      var objVbox = $("#" + playListGroupCurrent).find(".vbox").eq(playListIndexCurrent);
1889      var id = objVbox.attr("id");
1890      
1891      var videoTitle = null;
1892      //var poster = objVbox.attr("poster");  	
1893      var poster = null;
1894      var youTube = null;
1895      var videoFile = null;
1896      var pdata = null;
1897
1898      //for home page, today 
1899      if (typeof (options["id"]) != "undefined" && options["id"] != "") {
1900         id = options["id"];
1901      }
1902
1903      //comm list set vbox current
1904      objPlayList.find(".vbox").removeClass("vboxcurrent");
1905      objVbox.addClass("vboxcurrent");
1906
1907      //save id  
1908      if (id == null || id == "") { return; }
1909      playListDataId = id;
1910
1911      //load video data	
1912      loadingShow("loading-player", "show");
1913
1914      $.post("/code/video_load.php", { id: id }, function (data) {
1915
1916         var result = data.match(/<result>([^<]+)<\/result>/i);
1917         result = result == null ? "" : result[1];
1918         if (result == "success") {
1919            loadingShow("loading-player", "hide");
1920            videoTitle = getXml(data, "videotitle");
1921            poster = getXml(data, "poster");
1922            youTube = getXml(data, "youtube");
1923            videoFile = getXml(data, "videofile");
1924
1925            pdata = {
1926               poster: poster,
1927               youTube: youTube,
1928               videoFile: videoFile,
1929               sourceDefault: sourceDefault
1930            };
1931
1932            //global vars
1933            videoPlayerData["vid"] = getXml(data, "id");
1934            videoPlayerData["videoFile"] = getXml(data, "videofile");
1935            videoPlayerData["videoPoster"] = getXml(data, "poster");
1936            videoPlayerData["videoLength"] = getXml(data, "videolength");
1937            videoPlayerData["youTubeUrl"] = getXml(data, "youtube");
1938
1939            mainObjPlayer.showPlayer(pdata);
1940         }
1941      });
1942   }
1943
1944
1945   //save the live player  
1946   function saveLivePlayer() {
1947
1948   }
1949
1950   //click today show live	
1951   function showLivePlayer() {
1952      location.reload();
1953   }
1954
1955
1956   function loadingShow(id, style) {
1957      if (style == "show") {
1958         $("#" + id).css({ "visibility": "visible" }).show();
1959      } else {
1960         $("#" + id).hide();
1961      }
1962   }
1963
1964
1965   //player up next
1966   var upnextTimer;
1967   var upnextCtx;
1968   var upnextStart = 1.5;
1969   var upnextEnd = 3.5;
1970   var upnextTimeTotal = 10000;
1971   var upnextTimeStep = 100;
1972   var upnextTimeStepMobile = 1000;
1973   var upnextTimeCountMobile = 0;
1974   var upnextDrawing = upnextStart;
1975   var objUpnext;
1976   var objBtnStopUpNext;
1977   var objBtnReplay;
1978   var objUpnextTime;
1979   var upnextInited = false;
1980
1981   function upnextInit() {
1982      objUpnext = $("#upnext");
1983      objBtnStopUpNext = $("#btn-stop-upnext");
1984      objBtnReplay = $("#btn-replay");
1985      objUpnextTime = $("#upnext-time");
1986
1987      if (objUpnext.length == 0) { return; }
1988
1989      upnextCtx = document.getElementById("canvas-upnext").getContext("2d");
1990      objUpnext.css({ "visibility": "visible" }).hide();
1991
1992      //replay	
1993      objBtnReplay.on("click", function () {
1994         upnextClose();
1995         clearInterval(upnextTimer);
1996         mainObjPlayer.replay();
1997      });
1998
1999      //stop    
2000      objBtnStopUpNext.on("click", function () {
2001         clearInterval(upnextTimer);
2002         objUpnextTime.html("");
2003      });
2004
2005      //go
2006      $("#upnext-poster").on("click", function () {
2007         upnextGo();
2008      });
2009      $("#upnext-videotitle").on("click", function () {
2010         upnextGo();
2011      });
2012   }
2013
2014   function upnextDraw() {
2015      //for mobile	
2016      if (isMobile()) {
2017         upnextTimeCountMobile += upnextTimeStepMobile;
2018         if (upnextTimeCountMobile == upnextTimeTotal) {
2019            clearInterval(upnextTimer);
2020            upnextGo();
2021         }
2022
2023         var s = (upnextTimeTotal - upnextTimeCountMobile) / 1000;
2024         objUpnextTime.html(" - " + s + "s");
2025         return;
2026      }
2027
2028      //for pc	
2029      upnextDrawing = upnextDrawing + (upnextEnd - upnextStart) / (upnextTimeTotal / upnextTimeStep);
2030      upnextCtx.clearRect(0, 0, 100, 100);
2031      upnextCtx.beginPath();
2032      upnextCtx.lineWidth = 5;
2033      upnextCtx.strokeStyle = "#ffffff";
2034      upnextCtx.arc(30, 30, 28, upnextStart * Math.PI, upnextDrawing * Math.PI);
2035      upnextCtx.stroke();
2036      upnextCtx.closePath();
2037
2038      if (upnextDrawing >= upnextEnd) {
2039         clearInterval(upnextTimer);
2040         upnextGo();
2041      }
2042   }
2043
2044   function upnext() {
2045      if (!upnextInited) {
2046         upnextInit();
2047         upnextInited = true;
2048      }
2049
2050      playListFindNext();
2051      if (videoPlayerData["upnextVideoTitle"] == "") {
2052         return;
2053      }
2054      upnextDrawing = upnextStart;
2055
2056      try { clearInterval(upnextTimer); } catch (e) { }
2057
2058      if (isMobile()) {
2059         upnextTimeCountMobile = 0;
2060         upnextTimer = setInterval(upnextDraw, upnextTimeStepMobile);
2061      } else {
2062         upnextTimer = setInterval(upnextDraw, upnextTimeStep);
2063      }
2064
2065      if (videoPlayerData["upnextPoster"].indexOf("url") == -1) {
2066         videoPlayerData["upnextPoster"] = "url(" + videoPlayerData["upnextPoster"] + ")";
2067      }
2068
2069      $("#upnext-poster").css("background-image", videoPlayerData["upnextPoster"]);
2070      $("#upnext-videotitle").html(videoPlayerData["upnextVideoTitle"]);
2071      $("#upnext-videolength").html(videoPlayerData["upnextVideoLength"]);
2072
2073      objUpnext.fadeIn(200);
2074   }
2075
2076   function upnextGo() {
2077      if (listClickTo == "page") {
2078         playListIndexCurrent = playListIndexNext;
2079         playVideo({ sourceDefault: videoPlayerData["sourceDefault"] });
2080         upnextClose();
2081         // 
2082         var objVbox = $("#" + playListGroupCurrent).find(".vbox").eq(playListIndexCurrent);
2083         var id = objVbox.attr("id");
2084         objListBox[playListGroupCurrent].setCurrent(id);
2085
2086      } else {
2087         if (!empty(videoPlayerData["upnextUrl"])) {
2088            var url = videoPlayerData["upnextUrl"];
2089            if (videoPlayerData["sourceDefault"] == "audio") {
2090               if (url.indexOf("?") > -1) {
2091                  url = url + "&source=audio";
2092               } else {
2093                  url = url + "?source=audio";
2094               }
2095            }
2096            window.location.href = url;
2097         }
2098      }
2099   }
2100
2101   function upnextClose() {
2102      try { clearInterval(upnextTimer); } catch (e) { }
2103      try { objUpnext.fadeOut(200); } catch (e) { }
2104   }
2105
2106   return {
2107      init: init,
2108      upnext: upnext,
2109      playVideo: playVideo
2110   }
2111
2112});
2113
2114
2115////////////////////////////////
2116//language
2117var MainLang = MainLang || {};
2118MainLang = (function () {
2119
2120   var langDiagOpened = false;
2121   var objLangMobile = null;
2122   var objLangPc = null;
2123
2124   init();
2125
2126   function init() {
2127      objLangMobile = $("#menu-lang-mobile");
2128      objLangPc = $("#menu-lang-pc");
2129
2130      if (isMobile()) {
2131         objLangPc.remove();
2132      }
2133
2134      $("[id=btn-lang-diag]").click(function () {
2135         if (langDiagOpened) { return; }
2136         mainObjSearch.srchDiagClose();
2137         langDiagOpened = true;
2138         objLangMobile.css({ "visibility": "visible" });
2139         objLangMobile.css({ "right": "0px" });
2140         scrollDisable();
2141      });
2142
2143      $("#btn-close-lang-diagbox").click(function () {
2144         langDiagClose();
2145         scrollEnable();
2146      });
2147
2148
2149      //init LANGS_ARRAY array	
2150      var objLangs = $("#menu-lang-pc").find("a");
2151      if (objLangs.length < 1) {
2152         objLangs = $("#menu-lang-mobile").find("a");
2153      }
2154      $(objLangs).each(function () {
2155         LANGS_ARRAY.push("/" + $(this).attr("data") + LANG_DIR_ADD + "/");
2156      });
2157
2158      //language menu for lang change	 	 
2159      objLangMobile.add(objLangPc).find("a").each(function () {
2160         $(this).on("click", function () {
2161            var lang = "/" + $(this).attr("data") + LANG_DIR_ADD + "/";
2162            var url = window.location.href;
2163            for (var i = 0; i < LANGS_ARRAY.length; i++) {
2164               url = url.replace(LANGS_ARRAY[i], lang);
2165            }
2166            url = url.replace(/#.*/, '');
2167            window.location.href = url;
2168            return false;
2169         });
2170      });
2171   }
2172
2173   //language mobile
2174   function langDiagClose() {
2175      if (!langDiagOpened) { return; }
2176      langDiagOpened = false;
2177      objLangMobile.css({ "right": "-100vw" });
2178   }
2179
2180   return { langDiagClose: langDiagClose }
2181
2182});
2183
2184
2185////////////////////////////////
2186//search 
2187var MainSearch = MainSearch || {};
2188MainSearch = (function () {
2189
2190   var objNavSrchsDiag = $("#srch-diag");   
2191   var srchDiagOpened = false;   
2192   var objActiveInputBox = null;
2193   var qLast = "";
2194   var srchBarRequest = null;
2195   var loadingShow = false;
2196
2197   init();
2198
2199   function init() {
2200
2201      $("[id=btn-srch-diag-mobile]").off("click.srch").on("click.srch", function () {
2202         if (srchDiagOpened) { return; }
2203         mainObjLang.langDiagClose();
2204         srchDiagOpened = true;
2205         var h = getSrchDiagHeight();
2206         objNavSrchsDiag.css({ "visibility": "visible", "top": -h }).show();
2207         objNavSrchsDiag.animate({ "top": "0px" }, 300);
2208         srchKeywordsCloseAll();
2209         var obj = objNavSrchsDiag.find("#srch-keywords");
2210         if (obj.length > 0) {
2211            srchKeywordsGet(obj);
2212         }
2213         scrollDisable();
2214      });
2215
2216      $("[id=btn-srch-close]").off("click.srch").on("click.srch", function () {
2217         srchLoadingHide();
2218         scrollEnable();
2219         srchDiagClose();
2220      });
2221
2222      $("[id=srch-keywords]").off("keydown.srch").on("keydown.srch", function (eve) {
2223         //check key code 
2224         searchKeywordsListSelect($(eve.target), eve.keyCode);
2225      });
2226
2227      $("[id=srch-keywords]").each(function () {
2228         if ($(this).val() == "") {
2229            $(this).parent().find("[id=btn-srch-clear]").hide();
2230         } else {
2231            $(this).parent().find("[id=btn-srch-clear]").show();
2232            qLast = $(this).val();
2233         }
2234      });
2235
2236      $("[id=btn-srch-clear]").off("click.srch").on("click.srch", function () {
2237         var obj = $(this).parent().find("#srch-keywords");
2238         if (obj.length == 0) { return; }
2239
2240         obj.val("");
2241         $(this).parent().find("[id=btn-srch-clear]").hide();
2242         srchLoadingHide();
2243         srchKeywordsCloseAll();
2244
2245      });
2246
2247      $("[id=btn-srch-submit]").off("click.srch").on("click.srch", function () {
2248         srchSubmit($(this));
2249      });
2250
2251      $("[id=btn-srch-submit-extend]").off("click.srch").on("click.srch", function () {
2252
2253         var objHeaderThis = getHeaderObj($(this));
2254         var obj = objHeaderThis.find("[id=srchs]");
2255         var objNavmenu = objHeaderThis.find("li");
2256         var isExtend = objHeaderThis.find('.srchs-min');
2257
2258         //show search bar   
2259         if ($(isExtend).length>0) {                                                
2260            objNavmenu.css({ "transform": "scale(0.5)", "opacity": 0 });
2261            setTimeout(function () {
2262               objNavmenu.hide();
2263               obj.removeClass("srchs-min");
2264            }, 300);
2265            setTimeout(function () {
2266               objHeaderThis.find("[id=btn-srch-to-min]").fadeIn();
2267            }, 400);
2268         } else {
2269            srchSubmit($(this));
2270         }
2271      });
2272
2273      $("[id=btn-srch-to-min]").off("click.srch").on("click.srch", function () {
2274         
2275         var objHeaderThis = getHeaderObj($(this));
2276         var obj = objHeaderThis.find("[id=srchs]");
2277         var objNavmenu = objHeaderThis.find("li");
2278         obj.addClass("srchs-min");
2279         srchLoadingHide();
2280
2281         objHeaderThis.find("[id=btn-srch-to-min]").hide();
2282         setTimeout(function () {
2283            objNavmenu.show();
2284            objNavmenu.css({ "transform": "scale(1)", "opacity": 1 });
2285         }, 200);
2286         srchKeywordsCloseAll();
2287      });
2288
2289      //set search srange 
2290      $("[id=srch-srange-list]").find(".btn").off("click.srch").on("click.srch", function () {
2291         var code = $(this).attr("data");
2292         var name = $(this).text();
2293         setSrange(code, name);
2294      });
2295
2296      //set search langs   
2297      $("[id=srch-lang-list]").find("li").off("click.srch").on("click.srch", function () {
2298         var code = $(this).attr("data");
2299         var name = $(this).text();
2300         setLang(code, name);
2301      });
2302
2303      //confirm search input box, search page have 2 input box    
2304      $("[id=btn-srch-limit]").off("click.srch").on("click.srch", function () {
2305         objActiveInputBox = $(this).parent().parent();
2306      });
2307
2308      //key words list	
2309      srchKeywordsInit();
2310
2311      //click blank close
2312      $(document).off("click.srch touchmove.srch").on("click.srch touchmove.srch", (event)=>{ srchClickCheck(event);});
2313   }
2314
2315   //confirm which header, have 2
2316   function getHeaderObj(obj){
2317      return $(obj).closest('.header');
2318   }
2319
2320   var objSrchKeywordsListCurrent = null;
2321   function srchKeywordsInit() {
2322      $("[id=srch-keywords-list]").css({ "visibility": "visible" }).hide();
2323      $("[id=srch-keywords]").off("click.search").on("click.search", function () {
2324         var obj = $(this);
2325         var tar = srchFindObjNear(obj, "srch-keywords-list");
2326         if (tar != null) {
2327            if (!tar.is(objSrchKeywordsListCurrent)) {
2328               srchKeywordsClose(objSrchKeywordsListCurrent);
2329            }
2330            srchKeywordsGet(obj, 0);
2331         }
2332         //mobile scrool to top 	  
2333         if (isMobile()) {
2334            var srchsContainer = $(this).parent();
2335            for (var i = 0; i < 5; i++) {
2336               if (srchsContainer.attr("id") == "srchs-container") {
2337                  var top = $(this).parent().parent().offset().top - 10;
2338                  $("html,body").animate({ scrollTop: top }, 200);
2339                  break;
2340               } else {
2341                  srchsContainer = srchsContainer.parent();
2342               }
2343            }
2344         }
2345      });
2346
2347      $("[id=srch-keywords]").off("input").on("input", function () {
2348         if ($(this).val() == "") {
2349            $(this).parent().find("[id=btn-srch-clear]").hide();
2350         } else {
2351            $(this).parent().find("[id=btn-srch-clear]").show();
2352         }
2353         srchKeywordsGet($(this), 1000);
2354      });
2355   }
2356
2357   var timerSrchRequest = null;
2358   function srchKeywordsGet(obj, timerequest) {
2359      //obj is input box 	    
2360
2361      //confirm language    
2362      var lang = getCurrentLang();
2363      var slang = obj.parent().find("#srch-keywords").attr("slang");
2364      if (typeof (slang) == "undefined") {
2365         slang = "all";
2366      }
2367
2368      var url = "/code/search/keywords_load.php?v=" + Math.random();
2369      var keywords = obj.val();
2370      var objlist = srchFindObjNear(obj, "srch-keywords-list");
2371      if (objlist == null) { return; }
2372      var oblinks = objlist.find("#srch-keywords-links");
2373
2374      var srchtype = obj.parent().find("#srch-keywords").attr("srchtype");
2375      if (typeof (srchtype) == "undefined") {
2376         srchtype = "";
2377      }
2378      var srchCategory = obj.parent().find("#srch-keywords").attr("srchcategory");
2379      if (typeof (srchCategory) == "undefined") {
2380         srchCategory = "";
2381      }
2382
2383      if (keywords.length > 0 && keywords.length < 2) {
2384         return;
2385      }
2386
2387      if (keywords.length == 0) {
2388         timerequest = 0;
2389      }
2390
2391      if (timerSrchRequest != null) {
2392         clearTimeout(timerSrchRequest);
2393      }
2394
2395      timerSrchRequest = setTimeout(function () {
2396
2397         srchBarRequest = $.post(url, {
2398            lang: lang, slang: slang, q: keywords, type: srchtype, category: srchCategory
2399         }, function (data) {
2400            var result = data.match(/<a(.+)a>/i);
2401            if (result != null && !loadingShow) {
2402               oblinks.html(data);
2403               srchKeywordsShow(objlist, keywords);
2404            } else {
2405               oblinks.html("");
2406            }
2407         });
2408         timerSrchRequest = null;
2409      }, timerequest);
2410   }
2411
2412   function srchKeywordsShow(obj, keywords) {
2413      objSrchKeywordsListCurrent = obj;
2414      srchKeywordsBindMouseover();
2415      obj.show();
2416      obj.find("#srch-keywords-links").find("a").removeClass("active");
2417      srchKeywordsListKeyboardMoved = false;
2418      //count preset keywords    
2419      if (keywords == "") {
2420         obj.find("#srch-keywords-links").find("a").off("click.counter").on("click.counter", function () {
2421            countKeywords($(this).text());
2422         });
2423      }
2424   }
2425
2426   function srchKeywordsCloseAll() {
2427      $("[id=srch-keywords-list]").hide();
2428   }
2429
2430   function srchKeywordsClose(obj) {
2431      if (obj != null && obj.length > 0 && obj.attr("id") == "srch-keywords-list") {
2432         obj.hide();
2433      }
2434   }
2435
2436   function srchFindObjNear(obj, pid) {
2437      for (var i = 0; i < 5; i++) {
2438         var objFind = obj.find("#" + pid);
2439         if (objFind.length == 1) {
2440            return objFind;
2441         }
2442         obj = obj.parent();
2443      }
2444      return null;
2445   }
2446
2447   function srchKeywordsBindMouseover() {
2448      //on mouse over clear current
2449      $("[id=srch-keywords-list]").each(function () {
2450         $(this).find("a").off("mouseover.srch").on("mouseover.srch", function () {
2451            $(this).parent().find("a").removeClass("active");
2452            $(this).addClass("active");
2453         });
2454      });
2455   }
2456
2457   var srchKeywordsListKeyboardMoved = false;
2458   function searchKeywordsListSelect(tar, keyCode) {
2459      if (keyCode != "38" && keyCode != "40" && keyCode != "13") {
2460         srchKeywordsListKeyboardMoved = false;
2461         return;
2462      }
2463
2464      var objKeywordsList = srchFindObjNear(tar, "srch-keywords-list");
2465      if (objKeywordsList != null && objKeywordsList.is(":visible")) {
2466         var objKeywordsLinks = objKeywordsList.find("#srch-keywords-links");
2467
2468         if (objKeywordsLinks.children().length > 0) {
2469
2470            if (keyCode == "38" || keyCode == "40") {
2471               srchKeywordsListKeyboardMoved = true;
2472               var linkActive = objKeywordsLinks.find(".active");
2473               if (linkActive.length == 0) {
2474                  if (keyCode == "40") {
2475                     objKeywordsLinks.children(":first").addClass("active");
2476                  }
2477                  if (keyCode == "38") {
2478                     objKeywordsLinks.children(":last").addClass("active");
2479                  }
2480               } else {
2481                  var linkNext = null;
2482                  if (keyCode == "38") {
2483                     linkNext = linkActive.prev();
2484                  }
2485                  if (keyCode == "40") {
2486                     linkNext = linkActive.next();
2487                  }
2488
2489                  objKeywordsLinks.children().removeClass("active");
2490                  if (linkNext != null && linkNext.length > 0) {
2491                     linkNext.addClass("active");
2492                  } else {
2493                     if (keyCode == "40") {
2494                        objKeywordsLinks.children(":first").addClass("active");
2495                     }
2496                     if (keyCode == "38") {
2497                        objKeywordsLinks.children(":last").addClass("active");
2498                     }
2499                  }
2500               }
2501
2502            } else if (keyCode == "13") {
2503               var objlink = objKeywordsLinks.find(".active");
2504               if (objlink.length == 1 && srchKeywordsListKeyboardMoved) {
2505                  var linkAdr = objlink.attr("href");
2506                  if (linkAdr != undefined) {
2507                     window.location.href = linkAdr;
2508                  }
2509               } else {
2510                  srchSubmit(tar);
2511               }
2512            }
2513
2514         } else if (keyCode == "13") {
2515            srchSubmit(tar);
2516         }
2517         //no menu list		
2518      } else if (keyCode == "13") {
2519         srchSubmit(tar);
2520      }
2521   }
2522   //show search loading
2523   function srchLoadingShow(obj) {
2524      try { srchBarRequest.abort(); } catch (e) { }
2525      loadingShow = true;
2526
2527      if (obj == undefined) {
2528         obj = $("#srchs-container").find("#srch-keywords");
2529      }
2530      if (obj.val() == "") {
2531         return;
2532      }
2533      var objLoading = obj.parent().parent().find("[id=srch-loading]");
2534      if (objLoading.length > 0) {
2535         objLoading.css({ "visibility": "visible", "width": "100%", "opacity": "1" });
2536         objLoading.html('<div class="loading-dot"><div></div><div></div><div></div></div>');
2537      }
2538   }
2539   //hide search loading    
2540   function srchLoadingHide() {
2541      loadingShow = false;
2542      $("[id=srch-loading]").css({ "visibility": "hidden", "width": "0%", "opacity": "0" });
2543      $("[id=srch-loading]").html("");
2544   }
2545
2546   function srchSubmit(obj) {
2547      setTimeout(srchKeywordsCloseAll, 100);
2548
2549      //obj is input    
2550      if (obj.attr("id") != "srch-keywords") {
2551         obj = obj.parent().find("#srch-keywords");
2552      }
2553
2554      //google, same keywords, not query 
2555      var q = String(obj.val()).trim();
2556
2557      //too short return    
2558      var regex = /^[0-9a-zA-Z]{0,3}$/;
2559      if (regex.test(q)) {
2560         return;
2561      }
2562      if (String(q).length < 2) {
2563         return;
2564      }
2565
2566      if (typeof (obj.attr("bygoogle")) != "undefined" && q == qLast) {
2567         return;
2568      }
2569      qLast = q;
2570
2571      countKeywords(q);
2572
2573      //show loading
2574      srchLoadingShow(obj);
2575
2576      //srange by title or all    
2577      var srange = "";
2578      if (typeof (obj.attr("srange")) != "undefined" && obj.attr("srange") != "") {
2579         srange = "&srange=" + obj.attr("srange");
2580      }
2581
2582      //type and category
2583      var strSrchType = "";
2584      var srchtype = obj.attr("srchtype");
2585      if (typeof (srchtype) != "undefined" && srchtype != "") {
2586         strSrchType = "&type=" + srchtype;
2587      }
2588      var srchCategory = obj.attr("srchcategory");
2589      if (typeof (srchCategory) != "undefined" && srchCategory != "") {
2590         strSrchType += "&category=" + srchCategory;
2591      }
2592
2593      //language    
2594      var strSLang = "";
2595      var sLang = obj.attr("slang");
2596      if (typeof (sLang) != "undefined") {
2597         strSLang = "&slang=" + sLang;
2598      }
2599
2600      //confirm lang
2601      var urlRoot = window.location.href;
2602      var url = "";
2603      var urlSearchPage = "";
2604
2605      for (var i = 0; i < LANGS_ARRAY.length; i++) {
2606         var reg = new RegExp("(" + LANGS_ARRAY[i] + ").*", "gi");
2607         urlRoot = urlRoot.replace(reg, "$1");
2608      }
2609
2610      //some pages not have self lang,like meditation's, TR 
2611      if (typeof (SYS_LANG_DIR_DEFAULT) != "undefined") {
2612         urlRoot = SYS_LANG_DIR_DEFAULT;
2613      }
2614
2615
2616      if (typeof (obj.attr("bygoogle")) != "undefined") {
2617         setTimeout(srchDiagClose, 300);
2618         url = urlRoot + "search/?bygoogle#gsc.q=" + q;
2619         window.location.href = url;
2620         return;
2621      }
2622
2623      //by self   
2624      //url target,like cooking    
2625      var urlTarget = "search/";
2626      if (obj.attr("urltarget") != undefined) {
2627         urlTarget = obj.attr("urltarget");
2628      }
2629
2630      //default search page    
2631      url = urlRoot + urlTarget + "?q=" + q + srange + strSrchType + strSLang;
2632      urlSearchPage = urlRoot + urlTarget + "loadmore?q=" + q + srange + strSrchType + strSLang;
2633
2634      //cooking type is set in page
2635      if (urlTarget.indexOf("cooking") > -1) {
2636         url = urlRoot + urlTarget + "?q=" + q + srange + strSLang;
2637         urlSearchPage = "cooking_load.php?q=" + q + srange + strSLang;
2638      }
2639
2640      //channel type is set in page
2641      if (urlTarget.indexOf("channel") > -1) {
2642         var ta = $("#ta").val();
2643         url = urlRoot + urlTarget + "?q=" + q + srange + strSLang;
2644         urlSearchPage = urlRoot + "channel/loadmore?ta=" + ta + "&q=" + q + srange + strSLang;
2645      }
2646
2647      //in search page ,use ajax    
2648      if (obj.attr("pagename") == "search_page" && isPc()) {
2649         searchPage.checkLinkAction({ "obj": urlSearchPage, "urlHistory": url });
2650      } else if (obj.attr("pagename") == "channel_page") {
2651         channelPage.checkLinkAction({ "obj": urlSearchPage, "urlHistory": url });
2652      } else if (obj.attr("pagename") == "cooking_page") {
2653         cookingPage.checkLinkAction({ "obj": urlSearchPage, "urlHistory": url });
2654      } else {
2655         window.location.href = url;
2656      }
2657   }
2658
2659   function countKeywords(q) {
2660      if (String(q).trim() == "") {
2661         return;
2662      }
2663      $.post(processDataServer + 'handle.php', { type: "keywords", q: q });
2664   }
2665
2666   function getSrchDiagHeight() {
2667      return getNum(objNavSrchsDiag.height()) + getNum(objNavSrchsDiag.css("padding-top")) + getNum(objNavSrchsDiag.css("padding-bottom"));
2668   }
2669
2670   function srchClickCheck(event) {
2671      var obj = $(event.target);
2672
2673      if (obj.attr("id") == "srch-keywords-list-close") {
2674         srchKeywordsCloseAll();
2675         return;
2676      }
2677      for (i = 0; i < 5; i++) {
2678         if (String(obj.attr("class")).indexOf("srch") > -1) {
2679            return;
2680         }
2681         obj = obj.parent();
2682      }
2683
2684      srchKeywordsCloseAll();
2685   }
2686
2687   function srchDiagClose() {
2688      if (!srchDiagOpened) { return; }
2689      srchDiagOpened = false;
2690      var h = getSrchDiagHeight();
2691      objNavSrchsDiag.animate({ "top": -h }, 300, function () { $(this).hide(); });
2692      srchKeywordsCloseAll();
2693   }
2694
2695   function setLang(code, name) {
2696      if ($(objActiveInputBox).length > 0) {
2697         var objName = $(objActiveInputBox).find("#srch-lang-name");
2698         if (objName.length > 0) {
2699            objName.text(name);
2700         }
2701         var objKeywords = $(objActiveInputBox).find("#srch-keywords");
2702         objKeywords.attr("slang", code);
2703      }
2704   }
2705
2706   function setSrange(code, name) {
2707      if ($(objActiveInputBox).length > 0) {
2708         var objName = $(objActiveInputBox).find("#srch-srange-name");
2709         if (objName.length > 0) {
2710            objName.text(name);
2711         }
2712         var objKeywords = $(objActiveInputBox).find("#srch-keywords");
2713         objKeywords.attr("srange", code);
2714      }
2715   }
2716
2717   function setQlast(q) {
2718      qLast = q;
2719   }
2720
2721   return {
2722      init: init,
2723      srchDiagClose: srchDiagClose,
2724      srchKeywordsCloseAll, srchKeywordsCloseAll,
2725      srchLoadingShow, srchLoadingShow,
2726      srchLoadingHide, srchLoadingHide,
2727      setQlast, setQlast
2728   }
2729
2730});
2731
2732
2733////////////////////////////////
2734//Search By  
2735class SearchByGoogle {
2736   resultTextLast = "";
2737   lastTime = new Date().getTime();
2738
2739   constructor() {
2740      if (String(window.location.href).indexOf("bygoogle") < 0) {
2741         return;
2742      }
2743
2744      let thisClass = this;
2745      setInterval(function () {
2746         let resultText = $(".gs-title").text();
2747         if (thisClass.resultTextLast != resultText) {
2748            try {
2749               mainObjSearch.srchLoadingHide();
2750            } catch (e) { }
2751            thisClass.resultTextLast = resultText;
2752            thisClass.updateResult();
2753         }
2754      }, 500);
2755
2756      let hash = window.location.hash;
2757      let params = new URLSearchParams(hash.substring(1));
2758      let q = params.get('gsc.q');
2759      if (q != null) {
2760         mainObjSearch.setQlast(q);
2761         $("#srchs-container").find("[id=srch-keywords]").val(q);
2762         $("#srchs-container").find("[id=btn-srch-clear]").show();
2763         mainObjSearch.srchLoadingShow();
2764      } else {
2765         mainObjSearch.srchLoadingHide();
2766      }
2767   }
2768
2769   updateResult() {
2770      let currentTime = new Date().getTime();
2771      if (currentTime - this.lastTime < 1000) {
2772         return;
2773      }
2774      this.lastTime = currentTime;
2775
2776      let objs = $(".gsc-result");
2777      let ids = "";
2778      objs.each(function () {
2779         let url = $(this).find(".gs-visibleUrl-long:first").text();
2780         let reg = /(\S\S)1\/v\/(\d+)\.html/i;
2781         let match = url.match(reg);
2782         let id = match == null ? '' : match[2];
2783         let lang = match == null ? 'en' : match[1];
2784         if (id != "") {
2785            ids += ids == '' ? lang + '_' + id : ',' + lang + '_' + id;
2786         }
2787         $(this).attr("id", "sbox-" + lang + id);
2788         if (id == "") {
2789            $(this).find(".gsc-thumbnail").hide();
2790         }
2791      });
2792
2793      if (ids == "") {
2794         return;
2795      }
2796
2797      let thisClass = this;
2798      let data = new FormData();
2799      data.append('id', ids);
2800
2801      $.ajax({
2802         url: '/code/search/get_video_data.php',
2803         data: data,
2804         method: 'post',
2805         cache: false,
2806         processData: false,
2807         contentType: false,
2808         success: function (data) {
2809            thisClass.refreshVideoInfo(data);
2810            try {
2811               mainObjSearch.srchKeywordsCloseAll();
2812            } catch (e) { }
2813         },
2814         error: function (jqXHR, textStatus, errorThrown) {
2815         }
2816      });
2817
2818   }
2819
2820   refreshVideoInfo(data) {
2821      let match = data.match(/<n>(.*?)<\/n>/gi);
2822      match.forEach(function (item) {
2823         let find = item.match(/<id>(.*?)<\/id>/i);
2824         if (typeof (find[1]) != "undefined") {
2825            let id = find[1];
2826            let obj = $("#sbox-" + id);
2827            if (obj.length > 0) {
2828               find = item.match(/<title>(.*?)<\/title>/i);
2829               let title = find[1];
2830               obj.find("a.gs-title:first").text(title);
2831
2832               find = item.match(/<simage>(.*?)<\/simage>/i);
2833               let simage = find[1];
2834               obj.find(".gs-image").attr('src', simage);
2835            }
2836         }
2837      });
2838   }
2839
2840}
2841
2842////////////////////////////////
2843//nav menus
2844var MainNav = MainNav || {};
2845MainNav = (function () {
2846
2847   var objHeaderContainer = $("#header-container");
2848   var objHeaderMin = $("#header-min");
2849
2850   //pc,clone header, 2 header
2851   var navMenusId = 'navmenus';
2852   var navMenusContentsId = 'navmenus-contents';
2853
2854   var objNav = objHeaderContainer.find("[id=nav]");
2855   //clone header, refresh on headerInit(), have 2 in pc
2856   var objNavMenus = $("[id="+navMenusId+"]");
2857   var objNavMenusContents = objNavMenus.find("[id="+navMenusContentsId+"]");
2858
2859   var navMenusCloseTimer = null;
2860   var objNavMenuCurrent = null;
2861
2862   var objBtnNavMenu = objHeaderContainer.find("[id=btn-navmenu]");
2863   var objBtnNavMenuClose = $("[id=btn-navmenu-close]");
2864   var objBtnSubMenuClose = objHeaderContainer.find("[id=btn-submenu-close]");
2865   var objBtnBack = objHeaderContainer.find("[id=btn-back]");
2866   var timerUpdateHeaderStyle = null;
2867   var timerThirdMenu = null;
2868   var idThirdMenuShow = '';
2869
2870   init();
2871
2872   function init() { 
2873
2874      //search button
2875      $("[id=srchs]").on("mouseover", function () {
2876         navMenusClose();
2877      });
2878
2879      if(isPc()){
2880         objNavMenus.css({ "position": "absolute", "visibility": "visible" }).hide();
2881      }else{
2882         objNavMenus.css({ "position": "fixed", "visibility": "visible" }).hide();         
2883      }
2884
2885      //hide nav menu children
2886      objNavMenusContents.children().hide();
2887
2888      objNav.find("li").on("mouseover touchstart", function () {
2889         //close third menu
2890         closeThirdMenu();
2891
2892         var tarid = $(this).attr("tar");
2893         //confirm which header
2894         var objHeaderThis = getHeaderObj($(this));
2895         var ojbMenuTar = objHeaderThis.find("#" + tarid);
2896
2897         //have menu show			
2898         if (ojbMenuTar.length > 0) {            
2899            navMenusOpen({ obj: $(this) });
2900         } else {
2901            //no menu, close all menu                
2902            navMenusClose();
2903         }
2904      });
2905
2906      objNav.find("a").on("click", function () {
2907         if ($(this).attr("href") == "#") {
2908            return false;
2909         }
2910      });
2911
2912      //for pc
2913      if (isPc()) {
2914         objNav.add(objNavMenus).on("mouseleave", function () {
2915            if(isTouchDevice()){                          
2916               return; 
2917            } 
2918            navMenusCloseTimerStart();
2919         });
2920
2921         //touch close menu
2922         $(document).on('touchstart.nav', (event) => {
2923            const $target = $(event.target); 
2924            if ($target.closest('[id='+navMenusId+']').length > 0) { 
2925                return;
2926            } 
2927            navMenusCloseTimerStart();
2928        });
2929
2930         objNav.add(objNavMenus).on("mousemove", function () {
2931            navMenusCloseTimerClear();
2932         });
2933         
2934         objNav.add(objNavMenus).on("mousewheel", function () {
2935            navMenusCloseTimerClear();
2936         });
2937
2938         initThirdMenu();
2939
2940      }else{
2941      //mobile   
2942         objNavMenusContents.find("[id=btn-semenu-item]").on("click",function(){
2943            var tar = $(this).attr("tar");
2944            var objThirdMenu = $("#"+tar);  
2945
2946            if(objThirdMenu.length>0){
2947
2948               if(String($(this).find("#ico-thirdmenu").attr("class")).indexOf("opened")>-1){
2949                  objThirdMenu.slideUp();
2950                  $(this).find("#ico-thirdmenu").removeClass("opened");               
2951               }else{
2952                  objThirdMenu.slideDown();
2953                  $(this).find("#ico-thirdmenu").addClass("opened");
2954               }
2955               return false;
2956            }
2957            
2958         });
2959      }
2960
2961
2962      //for mobile
2963      objBtnNavMenu.on("click", mobileNavMenuOpen);
2964      objBtnNavMenuClose.on("click", mobileNavMenuClose);
2965
2966      objNavMenusContents.find("h3").on("click", mobileNavMenuExtend);
2967      objBtnBack.on("click", function () { history.back(-1); });
2968      objBtnSubMenuClose.on("click", mobileSubMenusClose);
2969
2970      $(window).on("scroll", function () {
2971         try { clearTimeout(timerUpdateHeaderStyle); } catch (e) { }
2972         timerUpdateHeaderStyle = setTimeout(function () { updateHeaderStyle(); }, 100);
2973      });
2974
2975      setTimeout(headerInit, 1000);
2976   }
2977
2978   //confirm which header, have 2
2979   function getHeaderObj(obj){
2980      return $(obj).closest('.header');
2981   }
2982
2983
2984   function initThirdMenu(){
2985      objNavMenus.find(".thirdmenu").on("mouseover",function(){
2986         try{            
2987            clearTimeout(timerThirdMenu);
2988         }catch(e){}
2989      });
2990
2991      objNavMenus.find("[id=btn-close-thirdmenu]").on("click",function(){
2992         closeThirdMenu();
2993      });
2994
2995      objNavMenus.find("[id=ico-thirdmenu]").on("click",function(){
2996         return false;
2997      });      
2998      
2999
3000      $("[id=btn-semenu-item]").on("mouseover",function(){
3001         try{
3002          clearTimeout(timerThirdMenu);
3003         }catch(e){}
3004                  
3005                  
3006         timerThirdMenu = setTimeout(()=>{
3007
3008         var tar = $(this).attr("tar");
3009
3010         if(idThirdMenuShow == tar){
3011            return;
3012         }         
3013
3014         //hide all
3015         closeThirdMenu();
3016
3017         idThirdMenuShow = tar;
3018
3019         var objHeaderThis = getHeaderObj($(this));
3020         var objThirdMenu = objHeaderThis.find("#"+tar);
3021
3022         if(objThirdMenu.length==0){            
3023            return;
3024         }
3025
3026         var objNavMenusThis = $(this).closest('#'+navMenusId);
3027         var leftParent = objNavMenusThis.offset().left;
3028         var topParent  = objNavMenusThis.offset().top;         
3029         var leftBtn = $(this).offset().left + $(this).outerWidth();
3030         var topBtn  = $(this).offset().top;
3031                  
3032         objThirdMenu.show();
3033  
3034         var menuWidth  = objThirdMenu.outerWidth();
3035         var menuHeight = objThirdMenu.outerHeight();                  
3036
3037         var topMenu = topBtn - topParent - menuHeight/2 + ($(this).outerHeight()/2);
3038         var leftMenu = leftBtn - leftParent - 5;
3039         if(leftBtn + menuWidth > $(document).width()){
3040            leftMenu = leftMenu - (leftBtn + menuWidth - $(document).width());
3041            topMenu = topBtn - topParent + $(this).outerHeight();
3042            $(this).find("#ico-thirdmenu").addClass("opened2");
3043         }else{
3044            $(this).find("#ico-thirdmenu").addClass("opened1");
3045         }
3046
3047         objThirdMenu.css({"left":leftMenu,"top":topMenu});
3048         objThirdMenu.addClass("thirdmenu-animation1");
3049      },300);
3050
3051      });
3052   }
3053
3054   //close 2 nav thirdmenus
3055   function closeThirdMenu(){    
3056      if (isPc()) {
3057         objNavMenus.find(".thirdmenu").fadeOut();
3058         objNavMenus.find(".thirdmenu").removeClass("thirdmenu-animation1");
3059      }else{
3060         objNavMenus.find(".thirdmenu").slideUp(); 
3061      }
3062
3063      idThirdMenuShow = '';
3064      objNavMenus.find("[id=ico-thirdmenu").removeClass("opened1");
3065      objNavMenus.find("[id=ico-thirdmenu").removeClass("opened2");
3066      objNavMenus.find("[id=ico-thirdmenu").removeClass("opened");
3067   }
3068
3069
3070   //pc open menu     
3071   function navMenusOpen(options) {
3072      var objHeaderThis = null;
3073      var obj = "";
3074      //new menu   
3075      if (typeof (options["obj"]) != "undefined") {
3076         obj = options["obj"];
3077         objNavMenuCurrent = obj;
3078         objHeaderThis = getHeaderObj(obj);
3079
3080         //show tar menu list   
3081         var tarid = obj.attr("tar");
3082         
3083         var ojbMenuTar = objHeaderThis.find("#" + tarid);
3084         objHeaderThis.find('#'+navMenusContentsId).children().hide();
3085         ojbMenuTar.show();
3086         //refresh list position    
3087      } else {
3088         obj = objNavMenuCurrent;
3089      }
3090
3091
3092      //set position,left,top 
3093      var objNavMenusThis = objHeaderThis.find('#'+navMenusId);	
3094      
3095      objNavMenusThis.css({ "left": 0, "top": 0 });
3096      var vw = $(document).width();
3097      var menuWidth = getObjWidth(objNavMenusThis);
3098      var x = obj.offset().left - (menuWidth - obj.width()) / 2;
3099      x = x + menuWidth > vw ? vw - menuWidth - 20 : x;
3100      x = x < 0 ? 0 : x;
3101  			
3102
3103      var y = obj.offset().top;
3104      y = y + obj.height();
3105
3106      //position fixed
3107      if(objHeaderThis.attr("id").indexOf('header-min')>-1){
3108         y = y - $(document).scrollTop();
3109      }
3110      y = y + 10;
3111
3112      //show menu list       
3113      objNavMenusThis.css({ "left": x, "top": y });
3114      objNavMenusThis.stop().fadeIn(200);
3115      objNavMenusThis.show();
3116      objNavMenusThis.css({'opacity':1});
3117   }
3118
3119   function navMenusClose() {      
3120      idThirdMenuShow = '';
3121      objNavMenus.stop().fadeOut(200);
3122   }
3123
3124   //on mouse out, hide in 0.3s     
3125   function navMenusCloseTimerStart() {
3126      navMenusCloseTimerClear();
3127      navMenusCloseTimer = setTimeout(navMenusClose, 300);
3128   }
3129
3130   //on mouse move, stop hide timer
3131   function navMenusCloseTimerClear() {
3132      try {
3133         clearTimeout(navMenusCloseTimer);
3134      } catch (e) { }
3135   }
3136
3137
3138   //mobile, click menu, extend submenus
3139   function mobileNavMenuExtend() {
3140      var obj = $(this).parent().find(".submenus");
3141      //if is link , no menu
3142      if (obj.index() == -1) { return; }
3143
3144      //is extended, close this menu		
3145      if (String(obj.parent().attr("class")).indexOf("opened")>-1) {
3146         obj.slideUp();
3147         $(this).parent().removeClass("opened");
3148         return false;
3149      }
3150
3151      //open this menu		
3152      obj.slideDown();
3153      $(this).parent().addClass("opened");
3154
3155      return false;
3156   }
3157
3158   //click menu button    
3159   function mobileNavMenuOpen() {
3160      mainObjLang.langDiagClose();
3161      objNavMenusContents.children().show();
3162      objNavMenus.css({ "visibility": "visible" }).show();
3163      objNavMenus.css({ "right": "0px" });
3164      //scrollDisable
3165      document.documentElement.style.overflow = 'hidden';
3166   }
3167
3168   //    
3169   function mobileNavMenuClose() {
3170      objNavMenus.css({ "right": "-100vw" });
3171      closeThirdMenu();
3172      objNavMenusContents.find(".submenu-content").slideUp();      
3173      objNavMenusContents.children().removeClass("opened");
3174      //scrollEnable
3175      document.documentElement.style.overflow = 'auto';
3176   }
3177
3178
3179   function mobileSubMenusClose() {
3180      var objParent = $(this).parent().parent();
3181      objParent.css({ "right": "-100vw" });
3182   }
3183
3184
3185   //last top scroll    
3186   var windowScrollTopLast = 0;
3187   //allow change scroll    
3188   var headerWillChangeTop = 1000;
3189   var headerIsChanging = false;
3190   var hideTopAdd = 10;
3191
3192   //udpate header style, scroll page show mini header    
3193   function updateHeaderStyle() {
3194      var windowScrollTop = $(document).scrollTop();
3195
3196      //show bar      
3197      if (mainHeaderStatus["visibility"] == "hidden") {
3198         if (windowScrollTop > headerWillChangeTop && windowScrollTop < windowScrollTopLast - hideTopAdd) {
3199            if (!headerIsChanging) {
3200               
3201               objHeaderMin.show();
3202               objHeaderMin.removeClass("header-hide");
3203               objHeaderMin.css({ "opacity": "1" });               
3204               objHeaderMin.css({ "top": 0 });
3205               mainHeaderStatus["visibility"] = "visible";
3206               headerIsChanging = true;
3207               setTimeout(function () { headerIsChanging = false; }, 300);
3208            }
3209         }
3210      }
3211
3212      //hide bar
3213      if (mainHeaderStatus["visibility"] == "visible") {
3214         if ((windowScrollTop > headerWillChangeTop && windowScrollTop > windowScrollTopLast + hideTopAdd) || windowScrollTop < headerWillChangeTop) {
3215            if (!headerIsChanging) {
3216               
3217               var headerTop = getObjHeight(objHeaderMin) + hideTopAdd;
3218               objHeaderMin.show();
3219               objHeaderMin.addClass("header-hide");
3220               objHeaderMin.css({ "opacity": "0" });               
3221               objHeaderMin.css({ "top": -headerTop });               
3222               mainHeaderStatus["visibility"] = "hidden";
3223               headerIsChanging = true;
3224               setTimeout(function () { headerIsChanging = false; }, 300);
3225            }
3226         }
3227      }
3228
3229      windowScrollTopLast = windowScrollTop;
3230   }
3231
3232   //set header height    
3233   function headerInit() {            
3234      mainHeaderStatus["visibility"] = "hidden";
3235      objHeaderMin.append($("#header").children().clone(true));      
3236      objHeaderMin.addClass("header-hide");
3237      objHeaderMin.css({ "opacity": "0" });    
3238      var headerTop = getObjHeight(objHeaderMin) + hideTopAdd;           
3239      objHeaderMin.css({ "top": -headerTop });     
3240      objHeaderMin.hide();
3241
3242      //refresh objs, have 2
3243      objNavMenus = $("[id="+navMenusId+"]");
3244      objNavMenusContents = objNavMenus.find("[id="+navMenusContentsId+"]");
3245   }
3246
3247   //hide
3248   function hide() {
3249      objHeaderMin.addClass("header-hide");
3250      var headerTop = getObjHeight(objHeaderMin) + hideTopAdd;
3251      objHeaderMin.css({ "top": -headerTop });
3252      objHeaderMin.css({ "opacity": "1" });
3253      mainHeaderStatus["visibility"] = "hidden";
3254
3255      headerIsChanging = true;      
3256      setTimeout(function () { headerIsChanging = false; }, 300);
3257   }
3258
3259   return {
3260      hide: hide,
3261      updateHeaderStyle: updateHeaderStyle
3262   }
3263
3264});
3265
3266
3267////////////////////////////////	
3268//liked 
3269function likeInit() {
3270   $("[id=btn-like]").off("click");
3271   $("[id=btn-like]").on("click", function () {
3272      var num = $(this).find("#likenum").html();
3273      var type = null;
3274      if ($(this).attr("class").indexOf("likeok") > -1) {
3275         $(this).removeClass("likeok");
3276         num = getNum(num, "int") - 1;
3277         num = num < 0 ? 0 : num;
3278         type = "unlike";
3279      } else {
3280         $(this).addClass("likeok");
3281         num = getNum(num, "int") + 1;
3282         type = "like";
3283      }
3284      $(this).find("#likenum").html(num);
3285      var id = $(this).attr("data");
3286      var url = processDataServer + 'handle.php';
3287      $.post(url, { id: id, type: type });
3288   });
3289}
3290
3291////////////////////////////////
3292
3293var DownloadBtnDialog = DownloadBtnDialog || {};
3294DownloadBtnDialog = (function (options) {
3295   var opts = $.extend({
3296   }, options);
3297
3298   //download video, button event	
3299   function init() {
3300      $("[id=btn-download-video]").off("click.download").on("click.download", function () {
3301         var id = $(this).attr("data");
3302         showDialog(id);
3303      });
3304      btnLinkInit();
3305   }
3306
3307   function showDialog(id) {
3308      var objContents = $("#contents-download-video");
3309      objContents.addClass("contents-bkloading");
3310      objContents.html("");
3311      dialogShow("download");
3312
3313      $.post("/code/video_downloadlink.php", { id: id }, function (data) {
3314         objContents.html(data);
3315         objContents.removeClass("contents-bkloading");
3316         objContents.find("a").off("click").on("click", function () {
3317            count($(this), id);
3318            dialogClose();
3319            return false;
3320         });
3321      });
3322   }
3323
3324   //counter
3325   function count(obj, id) {
3326      var urlDownload = obj.attr("href");
3327      var resolutionFound = urlDownload.match(/(700k.mp4|2m.mp4|6m.mp4|1080p.mp4|max.mp4|mp3|photo)/i);
3328      var resolutionType = resolutionFound == null ? "" : resolutionFound[1];
3329
3330      $.post(processDataServer + 'handle.php', { id: id, type: "counter", resolution_type: resolutionType });
3331      window.open(urlDownload, "_blank");
3332   }
3333
3334   //btn link
3335   function btnLinkInit() {
3336      $("[id=btn-vdownload],[id=btn-download-link]").off("click.download").on("click.download", function () {
3337         var id = $(this).attr("data");
3338         count($(this), id);
3339         return false;
3340      });
3341   }
3342
3343   return { init: init, showDialog: showDialog }
3344
3345});
3346
3347
3348
3349////////////////////////////////	
3350//update counter
3351function updateCounter() {
3352   var objIds = $("[id=counter-num]");
3353   var objLikeNums = $("[id=btn-like]");
3354
3355   var ids = "";
3356   if (typeof (videoPlayerData["vid"]) != "undefined") {
3357      ids = videoPlayerData["vid"];
3358   }
3359
3360   objIds.each(function () {
3361      var id1 = $(this).attr("class");
3362      id1 = id1.replace("counter-", "");
3363      ids += ids == "" ? id1 : "," + id1;
3364   });
3365
3366   var purl = processDataServer + "handle.php";
3367
3368   if (ids == "") { return; }
3369
3370   $.post(purl, { type: "getcounter", id: ids }, function (data) {
3371
3372      var result = data.match(/<result>([^<]+)<\/result>/i);
3373      result = result == null ? "" : result[1];
3374      if (result == "success") {
3375         var items = data.match(/<n>(.+?)<\/n>/ig);
3376         if (items == null || items == "" || items.length == 0) { return; }
3377         for (var i = 0; i < items.length; i++) {
3378            var id = "", num = "", numLiked;
3379            var idArray = items[i].match(/<id>(.+?)<\/id>/i);
3380            var numArray = items[i].match(/<num>(.+?)<\/num>/i);
3381            var numArrayLiked = items[i].match(/<liked>(.+?)<\/liked>/i);
3382
3383            if (typeof (idArray[1]) == "undefined" || typeof (numArray[1]) == "undefined" || typeof (numArrayLiked[1]) == "undefined") {
3384               continue;
3385            }
3386            id = idArray[1];
3387            num = numArray[1];
3388            numLiked = numArrayLiked[1];
3389
3390            //update view counter
3391            $(".counter-" + id).html(num);
3392            $(".counter-" + id).removeAttr("id");
3393
3394            //update like	
3395            objLikeNums.each(function () {
3396               if ($(this).attr("data") == id) {
3397                  $(this).find("#likenum").html(numLiked);
3398               }
3399            });
3400         }
3401      }
3402   });
3403
3404}
3405
3406////////////////////////////////	
3407//other btns
3408function mainBtnsInit() {
3409   var objBtnTop = $("#btn-top");
3410   var btnTopShowHeight = 500;
3411
3412   objBtnTop.css({ "visibility": "visible" }).hide();
3413   $(document).off("scroll.btnTop").on("scroll.btnTop", function (e) {
3414      var topScroll = $(document).scrollTop();
3415      if (topScroll > btnTopShowHeight && !objBtnTop.is(":visible")) {
3416         objBtnTop.fadeIn(200);
3417      }
3418      if (topScroll < btnTopShowHeight && objBtnTop.is(":visible")) {
3419         objBtnTop.fadeOut(200);
3420      }
3421   });
3422
3423   objBtnTop.off("click.top touchstart.top").on("click.top touchstart.top", function () {
3424      $("html,body").animate({ scrollTop: 0 }, 0);
3425   });
3426
3427   //mobile more btn	
3428   $("[id=list-more]").off("click.listmore").on("click.listmore", function () {
3429      var obj = $(this).parent();
3430      obj.css({ "height": "auto", "max-height": "none" });
3431      $(this).hide();
3432   });
3433
3434   //mobile view more btn //new
3435   $("[id=view-more-btn]").each(function () {
3436      var objBtn = $(this);
3437      var objOuter = $(this).parent().find(".view-more-outer");
3438      if (objOuter.length == 0) {
3439         return;
3440      }
3441      var totalHeight = 0;
3442      objOuter.children().each(function () {
3443         totalHeight += $(this).outerHeight();
3444      });
3445
3446      if (totalHeight < objOuter.outerHeight()) {
3447         objBtn.hide();
3448         objOuter.css({ "height": "auto", "max-height": "none", "mask": "none", "-webkit-mask": "none" });
3449      }
3450
3451      objBtn.off("click.vidwmore").on("click.vidwmore", function () {
3452         var obj = $(this).parent().find(".view-more-outer");
3453         if (obj.length > 0) {
3454            objBtn.hide();
3455            objOuter.css({ "height": "auto", "max-height": "none", "mask": "none", "-webkit-mask": "none" });
3456         }
3457      });
3458
3459   });
3460
3461   //apps	
3462   $("[id=btn-download-app]").off("click").on("click", function () { dialogShow("download-app"); return false; });
3463}
3464
3465
3466
3467////////////////////////////////
3468function checkScrollLoading(obj) {
3469   var objs = obj.find(".scroll-loading");
3470   if (objs.length == 0) {
3471      return;
3472   }
3473   objs.each(function () {
3474      var tag = $(this)[0].nodeName;
3475      tag = tag.toLowerCase();
3476      var url = $(this).attr("img-url");
3477      if (url != "") {
3478         if (tag == "img") {
3479            $(this).attr("src", url);
3480         }
3481         if (tag == "div") {
3482            $(this).css("background-image", "url(" + url + ")");
3483         }
3484      }
3485   });
3486}
3487
3488////////////////////////////////
3489//scroll loading img and background
3490
3491var MainScrollLoading = (function (options) {
3492  var opts = $.extend({
3493    loadmethod: "manual" // manual: class="scroll-loading", auto: all image
3494  }, options);
3495
3496
3497  var loadmethod = opts["loadmethod"];
3498  var objs = null;
3499  var windowHeight = $(window).height();
3500  
3501  if (loadmethod == "auto") {      
3502      objs = $("*");
3503  } else {
3504      objs = $(".scroll-loading");
3505  }
3506
3507  init();
3508 
3509  function init() {
3510    var objsData = [];
3511
3512    objs.each(function (i, el) {
3513      var $el = $(el);
3514
3515      if (isPc() && typeof ($el.attr("img-autoload")) != "undefined" && $el.attr("img-autoload") == "false") {
3516          return;
3517      }
3518      
3519      var y = $el.offset().top;
3520      var imgurl = "";
3521
3522      if (loadmethod == "auto") {
3523        if (y > windowHeight) {
3524          var tag = el.nodeName.toLowerCase();
3525          if (tag == "img") {
3526            imgurl = $el.attr("src");
3527            $el.attr("img-url", imgurl).attr("src", "");
3528          } else {
3529            //background img , only use 1 back img    
3530            var regex = new RegExp("url", "g");
3531            var resultFound = String($(objs[i]).css("backgroundImage")).match(regex);
3532            var countBack = !resultFound ? 0 : resultFound.length;
3533            if (countBack == 1) {
3534                imgurl = $(objs[i]).css("backgroundImage");
3535                $el.css("backgroundImage", "none").attr("img-url", imgurl);
3536            }
3537          }
3538        }
3539      } else {
3540          imgurl = $el.attr("img-url");
3541      }
3542
3543      if (imgurl) {         
3544         objsData.push(el);
3545      }
3546    });
3547    
3548    objs = $(objsData);
3549
3550  }
3551
3552  const observer = new IntersectionObserver(entries => {
3553      entries.forEach(entry => {
3554        if (entry.isIntersecting) {
3555          loadElement($(entry.target));
3556          observer.unobserve(entry.target);
3557        }
3558      });
3559    }, { rootMargin: "100px" });
3560
3561  objs.each(function () {
3562     observer.observe(this);
3563  });
3564
3565
3566  function loadElement($el) {
3567
3568    var tag = $el[0].nodeName.toLowerCase();
3569    var url = $el.attr("img-url");
3570
3571    //may be other funs loaded
3572    if (!url) { return; }
3573
3574    var v = Math.round(Math.random() * 100);
3575    if (String(url).indexOf("url") === -1) {
3576        url = url + "?v=" + v;
3577    } else {
3578        url = url.replace('")', '?v=' + v + '")');
3579    }
3580 
3581
3582    if (tag == "img") {
3583      $el.attr("src", url);
3584    } else {
3585      if (url.indexOf("url") === -1) {
3586        url = "url(" + url + ")";
3587      }
3588      $el.css("backgroundImage", url);
3589    }
3590
3591    $el.removeAttr("img-url")
3592       .removeClass("scroll-loading");
3593  }
3594
3595
3596});
3597
3598////////////////////////////////
3599//window size change
3600var WindowReSize = WindowReSize || {};
3601WindowReSize = (function () {
3602   var beforeWidth = $(document).width();
3603   var timerResize = null;
3604
3605   $(window).resize(windowChange);
3606
3607   function windowChange() {
3608      try {
3609         clearTimeout(timerResize);
3610      } catch (e) { }
3611      timerResize = setTimeout(windowConfirm, 1000);
3612   }
3613
3614   function windowConfirm() {
3615      var windowWidth = $(document).width();
3616      var url = window.location.href;
3617
3618      //not reload on embed page 
3619      if (url.indexOf("embed") > -1) {
3620         return;
3621      }
3622
3623      if ((beforeWidth > VW_MOBILE && windowWidth < VW_MOBILE) || (beforeWidth < VW_MOBILE && windowWidth > VW_MOBILE)) {
3624         location.reload();
3625      }
3626      beforeWidth = $(document).width();
3627   }
3628});
3629
3630////////////////////////////////
3631//float menus
3632var FloatMenus = FloatMenus || {};
3633FloatMenus = (function (options) {
3634   var opts = $.extend({
3635      menus: "float-menus",
3636      content: "float-menus-contents",
3637      btnMenu: "btn-float-menu",
3638      btnClose: "btn-menuclose",
3639      boxArrow: "float-menus-boxarrow",
3640   }, options);
3641
3642   //float-menus
3643   var menuTarId = "";
3644   var objMenus = $("#" + opts["menus"]);
3645   var objMenusContent = objMenus.find("#" + opts["content"]);
3646   var timerClose = null;
3647
3648   init();
3649   function init() {
3650      menuTarId = "";
3651      objMenus.css({ "visibility": "visible" }).hide();
3652      objMenusContent.children().hide();
3653
3654      $("[id=" + opts["btnMenu"] + "]").each(function () {
3655
3656         var event = $(this).attr("event");
3657         if (event == "over") {
3658            $(this).off("mouseover.floatMenu").on("mouseover.floatMenu", function () {
3659               menusCloseCancel();
3660               menusOpen($(this));
3661            });
3662
3663            $(this).off("mouseleave.floatMenu").on("mouseleave.floatMenu", function () {
3664               if(isTouchDevice()){ 
3665                  return; 
3666               }    
3667               menusCloseMouseOut();
3668            });
3669
3670            var tarid = $(this).attr("tar");
3671            var objMenuTar = objMenusContent.find("#" + tarid);
3672            objMenuTar.off("mouseover.floatMenu").on("mouseover.floatMenu", function () {
3673               menusCloseCancel();
3674            });
3675            objMenuTar.off("mouseleave.floatMenu").on("mouseleave.floatMenu", function () {
3676               if(isTouchDevice()){ 
3677                  return; 
3678               }    
3679               menusCloseMouseOut();
3680            });            
3681
3682         } else {
3683            $(this).off("click.floatMenu").on("click.floatMenu", function () {
3684               menusOpen($(this));
3685               if ($(this).attr("href") == "#") {
3686                  return false;
3687               }
3688            });
3689         }
3690      });
3691
3692      objMenus.find("[id=" + opts["btnClose"] + "]").off("click.closeFloatMenu").on("click.closeFloatMenu", function () {
3693         menusClose();
3694      });
3695
3696      //click blank close
3697      $(document).off("touchmove."+opts['menus']+" click."+opts['menus']).on("touchmove."+opts['menus']+" click."+opts['menus'], (event)=>{ menusClickCheck(event);});
3698
3699   }
3700
3701   function menusClickCheck(event) {  
3702      if (!objMenus.is(":visible")) {         
3703         return;
3704      }
3705
3706      //touch move return
3707      if(event.type=="touchmove" && $(event.target).closest(objMenus).length > 0){
3708         return;
3709      }
3710
3711      var obj = $(event.target);
3712
3713      for (i = 0; i < 15; i++) {
3714         if (obj.attr("id") == opts["btnMenu"] || obj.attr("id") == opts["menus"]) {
3715            return;
3716         }
3717         
3718         if (typeof (obj.attr("onclickclose")) != "undefined") {
3719            menusClose();
3720            return;
3721         }
3722         obj = obj.parent();
3723      }
3724
3725      menusClose();
3726   }
3727
3728   function menusOpen(obj) {
3729      if (String(obj.attr("class")).indexOf("disable") > -1) {
3730         return;
3731      }
3732
3733      var tarid = obj.attr("tar");
3734      var event = obj.attr("event");
3735      var diffy = obj.attr("diffy");
3736      if (typeof (diffy) == "undefined") {
3737         diffy = 0;
3738      } else {
3739         diffy = parseInt(diffy);
3740      }
3741
3742      if (tarid == menuTarId && event != "over" && objMenus.is(":visible")) {
3743         menusClose();
3744         return;
3745      } else {
3746         menuTarId = tarid;
3747      }
3748
3749      var objMenuTar = objMenusContent.find("#" + tarid);
3750      if (objMenuTar.length == 0) { return; }
3751
3752      //show obj menu	
3753      objMenusContent.children().hide();
3754      objMenuTar.show();
3755
3756      //move boxarrow
3757      var vw = $(document).width();
3758      var menuWidth = objMenus.width() + getNum(objMenus.css("padding-left")) + getNum(objMenus.css("padding-right"));
3759      var objWidth = obj.width() + getNum(obj.css("padding-left")) + getNum(obj.css("padding-right"));
3760      var x = 0;
3761      if (isPc()) {
3762         x = obj.offset().left - (menuWidth - objWidth) / 2;
3763         x = x + menuWidth > vw ? vw - menuWidth : x;
3764         x = x < 0 ? 0 : x;
3765      }
3766
3767      var objBoxArrow = objMenus.find("#" + opts["boxArrow"]);
3768      var boxArrowLeft = obj.offset().left + objWidth / 2 - x;
3769      objBoxArrow.css({ "left": boxArrowLeft });
3770
3771      var y = 0;
3772      if (isPc()) {
3773         y = obj.offset().top + document.body.scrollTop + document.documentElement.scrollTop;
3774         y = y - $(document).scrollTop() + getObjHeight(obj) + diffy;
3775      }
3776
3777      objMenus.css({ "left": x, "top": y }).fadeIn(200);
3778
3779      if (isMobile()) {
3780          scrollDisable();
3781      }
3782   }
3783
3784   function menusCloseMouseOut() {
3785      if(isPc()){
3786        timerClose = setTimeout(menusClose, 300);
3787      }
3788   }
3789   function menusCloseCancel() {
3790      try { clearTimeout(timerClose); } catch (e) { }
3791   }
3792
3793   function menusClose() {
3794      menuTarId = "";
3795      objMenus.fadeOut(200);      
3796      if (isMobile()) {
3797         scrollEnable();
3798      }
3799   }
3800
3801});
3802
3803////////////////////////////////
3804//category view, use tabs label
3805var CategoryView = CategoryView || {};
3806CategoryView = (function () {
3807   //init({viewContainer:"id",buttonContainer:"id",view:"class",button:"class",action:"over/click"});	
3808   function init(options) {
3809      var action = options["action"];
3810      var viewContainer = options["viewContainer"];
3811      var buttonContainer = options["buttonContainer"];
3812
3813      var objViews = null;
3814      var objButtons = null;
3815
3816      if (typeof (options["view"]) == "undefined") {
3817         objViews = $("#" + viewContainer).children();
3818      } else {
3819         objViews = $("#" + viewContainer).find("." + options["view"]);
3820      }
3821
3822      if (typeof (options["button"]) == "undefined") {
3823         objButtons = $("#" + buttonContainer).children();
3824      } else {
3825         objViews = $("#" + buttonContainer).find("." + options["button"]);
3826      }
3827
3828      if (action == "click") {
3829         action = "click";
3830      } else {
3831         action = "mouseover";
3832      }
3833
3834      objViews.each(function () {
3835         if (isPc()) {
3836            $(this).css({ "position": "relative", "visibility": "visible" }).hide();
3837         }
3838      });
3839
3840      objViews.eq(0).show();
3841      objButtons.removeClass("current");
3842      objButtons.eq(0).addClass("current");
3843      objButtons.on(action, function () {
3844         objButtons.removeClass("current");
3845         var id = $(this).attr("data");
3846         if (typeof (id) == "undefined" || id == "undefined" || id == "") { return; }
3847         $(this).addClass("current");
3848         objViews.hide();
3849         $("#" + id).show();
3850         //check slimg	
3851         checkScrollLoading($("#" + id));
3852         return false;
3853      });
3854   }
3855
3856   return { init: init }
3857});
3858
3859////////////////////////////////
3860//share box
3861var ShareDialog = ShareDialog || {};
3862ShareDialog = (function () {
3863   //for embed copy
3864   var objDialogShare = $("#dialog-share");
3865   var objEmbed = $("#share-embed-code");
3866   var objUrlPage = $("#share-url");
3867
3868   objEmbed.add(objUrlPage).on("click", function () {
3869      $(this).select();
3870   });
3871   $("#btn-share-copy-embed").on("click touchstart", function () {
3872      objEmbed.select();
3873      document.execCommand('copy', false, null);
3874   });
3875   $("#btn-share-copy-url").on("click touchstart", function () {
3876      objUrlPage.select();
3877      document.execCommand('copy', false, null);
3878   });
3879
3880   //for embed start time	
3881   var objStartTime = $("#share-start-time");
3882   $(objStartTime, objDialogShare).on("keydown keyup mouseout change", function () {
3883      var urlPageVal = objUrlPage.val();
3884      var embedCode = objEmbed.val();
3885
3886      var time = $(this).val();
3887      time = String(time).replace(".", ":");
3888      time = String(time).replace(":", ":");
3889      var timeArray = String(time).split(":");
3890
3891      switch (timeArray.length) {
3892         case 0: time = "";
3893            break;
3894         case 1: time = getNum(timeArray[0]);
3895            break;
3896         case 2: time = getNum(timeArray[0]) * 60 + getNum(timeArray[1]);
3897            break;
3898         case 3: time = getNum(timeArray[0]) * 60 * 60 + getNum(timeArray[1]) * 60 + getNum(timeArray[2]);
3899            break;
3900      }
3901
3902      //embed
3903      var embedCodeNew = "";
3904      if (embedCode.indexOf("start") > -1) {
3905         var reg = new RegExp("start=([^&\"]+)", "i");
3906         embedCodeNew = embedCode.replace(reg, 'start=' + time);
3907      } else if (embedCode.indexOf("?") > -1) {
3908         embedCodeNew = embedCode.replace('" frameborder', '&start=' + time + '" frameborder');
3909      } else {
3910         embedCodeNew = embedCode.replace('" frameborder', '?start=' + time + '" frameborder');
3911      }
3912      embedCodeNew = embedCodeNew.replace('&start=0', '');
3913      embedCodeNew = embedCodeNew.replace('start=0', '');
3914      embedCodeNew = embedCodeNew.replace('?"', '"');
3915      objEmbed.val(embedCodeNew);
3916
3917      //url
3918      var urlPageValNew = "";
3919      if (urlPageVal.indexOf("start") > -1) {
3920         var reg = new RegExp("start=([^&\"]+)", "i");
3921         urlPageValNew = urlPageVal.replace(reg, 'start=' + time);
3922      } else if (urlPageVal.indexOf("?") > -1) {
3923         urlPageValNew = urlPageVal + '&start=' + time;
3924      } else {
3925         urlPageValNew = urlPageVal + '?start=' + time;
3926      }
3927      urlPageValNew = urlPageValNew.replace('&start=0', '');
3928      urlPageValNew = urlPageValNew.replace('start=0', '');
3929      urlPageValNew = urlPageValNew.replace(/\?$/g, '');
3930
3931      objUrlPage.val(urlPageValNew);
3932
3933   });
3934
3935   $("#btn-share-items").on("mouseover click press", function () {
3936      $("#btn-share-items").attr("data-a2a-url", objUrlPage.val());
3937   });
3938
3939   //min share btn
3940   $("[id=btn-share-mini]").off("click.share").on("click.share", function () {
3941      shareClick($(this));
3942   });
3943
3944   function shareClick(obj) {
3945      var shareLang = obj.attr("data-share-lang");
3946      var shareTitle = obj.attr("data-share-title");
3947      var shareId = obj.attr("data-share-id");
3948
3949      var shareUrl = "https://suprememastertv.com/" + shareLang + LANG_DIR_ADD + "/v/" + shareId + ".html";
3950      
3951      if (String(obj.attr("data-share-url")) == "current") {
3952         shareUrl = window.location;
3953      }else if (String(obj.attr("data-share-url")) != "undefined") {
3954         shareUrl = obj.attr("data-share-url");
3955      }
3956      
3957      var objShareUrl = $("#share-url");      
3958      objShareUrl.val(shareUrl);
3959      $("#btn-share-items").attr("data-a2a-url", shareUrl);
3960      $("#btn-share-items").attr("data-a2a-title", shareTitle);
3961
3962      //find url time
3963      startTime = '0:00';
3964      var urlParams = new URLSearchParams(window.location.search);
3965      var start = urlParams.get('start');
3966      start = start !== null ? Number(start) : '';
3967      if(start!=''){
3968         startTime = sTotimeLess(start);
3969         startTime = String(start).length==2 && start<60?"0:"+start:start;
3970      }
3971
3972      //start time
3973      $("#share-start-time").val(startTime);
3974
3975      var objEmbedCode = $("#share-embed-code");
3976      var embedCode = '<iframe width="560" height="315" src="';
3977      embedCode += 'https://suprememastertv.com/embed/' + shareId;
3978      if(start!=''){
3979         embedCode += '?start='+start;
3980      }
3981      embedCode += '" frameborder="0" allowfullscreen></iframe>';
3982      objEmbedCode.val(embedCode);
3983
3984      dialogShow("dialog-share");
3985   }
3986
3987   function share() {
3988      var tar = event.currentTarget;
3989      shareClick($(tar));
3990   }
3991
3992   return { share: share }
3993
3994});
3995
3996////////////////////////////////
3997//AddToAny share url confirm
3998function onShareAddToAny(shareData) {
3999   var objDialogShare = $("#dialog-share");
4000   var newUrl = $("#btn-share-items").attr("data-a2a-url");
4001   var newTitle = $("#btn-share-items").attr("data-a2a-title");
4002
4003   if (objDialogShare.length == 1 && objDialogShare.is(":visible") && newUrl != "undefined" && newUrl.trim() != "") {
4004      shareUrl = newUrl;
4005      shareTitle = newTitle;
4006   } else {
4007      shareUrl = shareData.url;
4008      shareTitle = shareData.title;
4009   }
4010
4011   return {
4012      url: shareUrl,
4013      title: shareTitle
4014   };
4015}
4016
4017var a2a_config = a2a_config || {};
4018a2a_config.callbacks = a2a_config.callbacks || [];
4019a2a_config.callbacks.push({
4020   share: onShareAddToAny,
4021});
4022
4023
4024$(function () {
4025   mainObjNav = MainNav();
4026   mainObjLang = MainLang();
4027   mainObjSearch = MainSearch();
4028   mainObjPlayer = MainPlayer();
4029
4030   likeInit();
4031   updateCounter();
4032   DownloadBtnDialog().init();
4033   mainBtnsInit();
4034   WindowReSize();
4035
4036   FloatMenus({ menus: "float-menus-srchs", btnMenu: "btn-srch-limit" });   
4037
4038   searchByGoogle = new SearchByGoogle();
4039   if(isPc()){ $("#header").append($("#navmenus")); }
4040});

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.