PageSourceSearch

https://northborosvethospital.com/wp-content/themes/pet/fw/js/core.init.js

js northborosvethospital.com collected 2026-10-09 23:04:06 UTC 48,301 bytes, 1,430 lines download raw bytes

1/* global jQuery:false */
2/* global THEMEREX_GLOBALS:false */
3
4jQuery(document).ready(function() {
5	"use strict";
6	THEMEREX_GLOBALS['theme_init_counter'] = 0;
7	themerex_init_actions();
8});
9
10
11
12// Theme init actions
13function themerex_init_actions() {
14	"use strict";
15
16	if (THEMEREX_GLOBALS['vc_edit_mode'] && jQuery('.vc_empty-placeholder').length==0 && THEMEREX_GLOBALS['theme_init_counter']++ < 30) {
17		setTimeout(themerex_init_actions, 200);
18		return;
19	}
20
21	themerex_ready_actions();
22	themerex_resize_actions();
23	themerex_scroll_actions();
24
25	// Resize handlers
26	jQuery(window).resize(function() {
27		"use strict";
28		themerex_resize_actions();
29	});
30
31	// Scroll handlers
32	jQuery(window).scroll(function() {
33		"use strict";
34		themerex_scroll_actions();
35	});
36}
37
38
39
40// Theme first load actions
41//==============================================
42function themerex_ready_actions() {
43	"use strict";
44
45	// Call skin specific action (if exists)
46    //----------------------------------------------
47	if (window.themerex_skin_ready_actions) themerex_skin_ready_actions();
48
49
50	// Widgets decoration
51    //----------------------------------------------
52
53	// Decorate nested lists in widgets and side panels
54	jQuery('.widget ul > li').each(function() {
55		if (jQuery(this).find('ul').length > 0) {
56			jQuery(this).addClass('has_children');
57		}
58	});
59
60
61	// Archive widget decoration
62	jQuery('.widget_archive a').each(function() {
63		var val = jQuery(this).html().split(' ');
64		if (val.length > 1) {
65			val[val.length-1] = '<span>' + val[val.length-1] + '</span>';
66			jQuery(this).html(val.join(' '))
67		}
68	});
69
70	
71	// Calendar handlers - change months
72	jQuery('.widget_calendar').on('click', '.month_prev a, .month_next a', function(e) {
73		"use strict";
74		var calendar = jQuery(this).parents('.wp-calendar');
75		var m = jQuery(this).data('month');
76		var y = jQuery(this).data('year');
77		var pt = jQuery(this).data('type');
78		jQuery.post(THEMEREX_GLOBALS['ajax_url'], {
79			action: 'calendar_change_month',
80			nonce: THEMEREX_GLOBALS['ajax_nonce'],
81			month: m,
82			year: y,
83			post_type: pt
84		}).done(function(response) {
85			var rez = JSON.parse(response);
86			if (rez.error === '') {
87				calendar.parent().fadeOut(200, function() {
88					jQuery(this).find('.wp-calendar').remove();
89					jQuery(this).append(rez.data).fadeIn(200);
90				});
91			}
92		});
93		e.preventDefault();
94		return false;
95	});
96
97
98
99	// Media setup
100    //----------------------------------------------
101
102	// Video background init
103	jQuery('.video_background').each(function() {
104		var youtube = jQuery(this).data('youtube-code');
105		if (youtube) {
106			jQuery(this).tubular({videoId: youtube});
107		}
108	});
109
110
111
112	// Menu
113    //----------------------------------------------
114
115	// Clone side menu for responsive
116	if (jQuery('ul#menu_side').length > 0) {
117		jQuery('ul#menu_side').clone().removeAttr('id').removeClass('menu_side_nav').addClass('menu_side_responsive').insertAfter('ul#menu_side');
118	}
119
120	// Clone main menu for responsive
121	if (jQuery('ul#menu_main').length > 0) {
122		var menu_responsive = jQuery('ul#menu_main').clone().removeAttr('id').removeClass('menu_main_nav').addClass('menu_main_responsive');	//.insertAfter('ul#menu_main');
123		jQuery('ul#menu_main').parent().parent().append(menu_responsive);
124	}
125	
126	// Responsive menu button
127	jQuery('.menu_main_responsive_button, .sidebar_outer_menu_responsive_button').click(function(e){
128		"use strict";
129		jQuery(jQuery(this).hasClass('menu_main_responsive_button') ? '.menu_main_responsive' : '.menu_side_responsive').slideToggle();
130		e.preventDefault();
131		return false;
132	});
133	
134	// Side menu widgets button
135	jQuery('.sidebar_outer_widgets_button').click(function(e){
136		"use strict";
137		jQuery('.sidebar_outer_widgets').slideToggle();
138		e.preventDefault();
139		return false;
140	});
141
142	// Submenu click handler for the responsive menu
143	jQuery('.menu_main_responsive li a, .menu_side_responsive li a').click(function(e) {
144		"use strict";
145		var is_menu_main = jQuery(this).parents('.menu_main_responsive').length > 0;
146		if ((!is_menu_main || jQuery('body').hasClass('responsive_menu')) && jQuery(this).parent().hasClass('menu-item-has-children')) {
147			if (jQuery(this).siblings('ul:visible').length > 0)
148				jQuery(this).siblings('ul').slideUp().parent().removeClass('opened');
149			else
150				jQuery(this).siblings('ul').slideDown().parent().addClass('opened');
151		}
152		if (jQuery(this).attr('href')=='#' || ((!is_menu_main || jQuery('body').hasClass('responsive_menu')) && jQuery(this).parent().hasClass('menu-item-has-children'))) {
153			e.preventDefault();
154			return false;
155		}
156	});
157	
158	// Init superfish menus
159	themerex_init_sfmenu('ul#menu_main, ul#menu_user, ul#menu_side');
160
161	// Slide effect for main menu
162	if (THEMEREX_GLOBALS['menu_slider']) {
163		jQuery('#menu_main').spasticNav({
164			color: THEMEREX_GLOBALS['accent2_color']
165		});
166	}
167
168	// Show table of contents for the current page
169	if (THEMEREX_GLOBALS['toc_menu'] != 'no') {
170		themerex_build_page_toc();
171	}
172
173	// One page mode for menu links (scroll to anchor)
174	jQuery('#toc, ul#menu_main li, ul#menu_user li, ul#menu_side li, ul#menu_footer li').on('click', 'a', function(e) {
175		"use strict";
176		var href = jQuery(this).attr('href');
177		if (href===undefined) return;
178		var pos = href.indexOf('#');
179		if (pos < 0 || href.length == 1) return;
180		if (jQuery(href.substr(pos)).length > 0) {
181			var loc = window.location.href;
182			var pos2 = loc.indexOf('#');
183			if (pos2 > 0) loc = loc.substring(0, pos2);
184			var now = pos==0;
185			if (!now) now = loc == href.substring(0, pos);
186			if (now) {
187				themerex_document_animate_to(href.substr(pos));
188				themerex_document_set_location(pos==0 ? loc + href : href);
189				e.preventDefault();
190				return false;
191			}
192		}
193	});
194	
195	
196	// Store height of the top panel
197	THEMEREX_GLOBALS['top_panel_height'] = 0;	//Math.max(0, jQuery('.top_panel_wrap').height());
198
199
200	// Pagination
201    //----------------------------------------------
202
203	// Page navigation (style slider)
204	jQuery('.pager_cur').click(function(e) {
205		"use strict";
206		jQuery('.pager_slider').slideDown(300, function() {
207			themerex_init_shortcodes(jQuery('.pager_slider').eq(0));
208		});
209		e.preventDefault();
210		return false;
211	});
212
213
214	// View More button
215	jQuery('#viewmore_link').click(function(e) {
216		"use strict";
217		if (!THEMEREX_GLOBALS['viewmore_busy'] && !jQuery(this).hasClass('viewmore_empty')) {
218			jQuery(this).parent().addClass('loading');
219			THEMEREX_GLOBALS['viewmore_busy'] = true;
220			jQuery.post(THEMEREX_GLOBALS['ajax_url'], {
221				action: 'view_more_posts',
222				nonce: THEMEREX_GLOBALS['ajax_nonce'],
223				page: THEMEREX_GLOBALS['viewmore_page']+1,
224				data: THEMEREX_GLOBALS['viewmore_data'],
225				vars: THEMEREX_GLOBALS['viewmore_vars']
226			}).done(function(response) {
227				"use strict";
228				var rez = JSON.parse(response);
229				jQuery('#viewmore_link').parent().removeClass('loading');
230				THEMEREX_GLOBALS['viewmore_busy'] = false;
231				if (rez.error === '') {
232					var posts_container = jQuery('.content').eq(0);
233					if (posts_container.find('.isotope_wrap').length > 0) posts_container = posts_container.find('.isotope_wrap').eq(0);
234					if (posts_container.hasClass('isotope_wrap')) {
235						posts_container.data('last-width', 0).append(rez.data);
236						THEMEREX_GLOBALS['isotope_init_counter'] = 0;
237						themerex_init_appended_isotope(posts_container, rez.filters);
238					} else
239						jQuery('#viewmore').before(rez.data);
240
241					THEMEREX_GLOBALS['viewmore_page']++;
242					if (rez.no_more_data==1) {
243						jQuery('#viewmore_link').addClass('viewmore_empty').parent().hide();
244					}
245
246					themerex_init_post_formats();
247					themerex_init_shortcodes(posts_container);
248					themerex_scroll_actions();
249				}
250			});
251		}
252		e.preventDefault();
253		return false;
254	});
255
256
257	// Woocommerce
258    //----------------------------------------------
259
260	// Change display mode
261	jQuery('.woocommerce .mode_buttons a,.woocommerce-page .mode_buttons a').click(function(e) {
262		"use strict";
263		var mode = jQuery(this).hasClass('woocommerce_thumbs') ? 'thumbs' : 'list';
264		jQuery.cookie('themerex_shop_mode', mode, {expires: 365, path: '/'});
265		jQuery(this).siblings('input').val(mode).parents('form').get(0).submit();
266		e.preventDefault();
267		return false;
268	});
269	// Added to cart
270	jQuery('body').bind('added_to_cart', function() {
271		"use strict";
272		// Update amount on the cart button
273		var total = jQuery('.menu_user_cart .total .amount').text()
274		if (total != undefined) {
275			jQuery('.cart_button .cart_total').text(total);
276		}
277	});
278	// Show cart 
279	jQuery('.top_panel_middle .top_panel_cart_button').click(function(e) {
280		"use strict";
281		jQuery(this).siblings('.sidebar_cart').slideToggle();
282		e.preventDefault();
283		return false;
284	});
285
286	// Popup login and register windows
287    //----------------------------------------------
288	jQuery('.popup_link').addClass('inited').click(function(e){
289		var popup = jQuery(jQuery(this).attr('href'));
290		if (popup.length === 1) {
291			themerex_hide_popup(jQuery(popup.hasClass('popup_login') ? '.popup_registration' : '.popup_login' ));
292			themerex_toggle_popup(popup);
293		}
294		e.preventDefault();
295		return false;
296	});
297	jQuery('.popup_wrap .popup_close').click(function(e){
298		var popup = jQuery(this).parent();
299		if (popup.length === 1) {
300			themerex_hide_popup(popup);
301		}
302		e.preventDefault();
303		return false;
304	});
305
306
307	// Forms validation
308    //----------------------------------------------
309
310	// Login form
311	jQuery('.popup_form.login_form').submit(function(e){
312		"use strict";
313		var rez = themerex_login_validate(jQuery(this));
314		if (!rez)
315			e.preventDefault();
316		return rez;
317	});
318	
319	// Registration form
320	jQuery('.popup_form.registration_form').submit(function(e){
321		"use strict";
322		var rez = themerex_registration_validate(jQuery(this));
323		if (!rez)
324			e.preventDefault();
325		return rez;
326	});
327
328	// Comment form
329	jQuery("form#commentform").submit(function(e) {
330		"use strict";
331		var rez = themerex_comments_validate(jQuery(this));
332		if (!rez)
333			e.preventDefault();
334		return rez;
335	});
336
337
338
339	// Bookmarks
340    //----------------------------------------------
341
342	// Add bookmark
343	jQuery('.bookmarks_add').click(function(e) {
344		"use strict";
345		var title = window.document.title.split('|')[0];
346		var url = window.location.href;
347		var list = jQuery.cookie('themerex_bookmarks');
348		var exists = false;
349		if (list) {
350			list = JSON.parse(list);
351			for (var i=0; i<list.length; i++) {
352				if (list[i].url == url) {
353					exists = true;
354					break;
355				}
356			}
357		} else
358			list = new Array();
359		if (!exists) {
360			var message_popup = themerex_message_dialog('<label for="bookmark_title">'+THEMEREX_GLOBALS['strings']['bookmark_title']+'</label><br><input type="text" id="bookmark_title" name="bookmark_title" value="'+title+'">', THEMEREX_GLOBALS['strings']['bookmark_add'], null,
361				function(btn, popup) {
362					"use strict";
363					if (btn != 1) return;
364					title = message_popup.find('#bookmark_title').val();
365					list.push({title: title, url: url});
366					jQuery('.bookmarks_list').append('<li><a href="'+url+'" class="bookmarks_item">'+title+'<span class="bookmarks_delete icon-cancel" title="'+THEMEREX_GLOBALS['strings']['bookmark_del']+'"></span></a></li>');
367					jQuery.cookie('themerex_bookmarks', JSON.stringify(list), {expires: 365, path: '/'});
368					setTimeout(function () {themerex_message_success(THEMEREX_GLOBALS['strings']['bookmark_added'], THEMEREX_GLOBALS['strings']['bookmark_add']);}, THEMEREX_GLOBALS['message_timeout']/4);
369				});
370		} else
371			themerex_message_warning(THEMEREX_GLOBALS['strings']['bookmark_exists'], THEMEREX_GLOBALS['strings']['bookmark_add']);
372		e.preventDefault();
373		return false;
374	});
375
376	// Delete bookmark
377	jQuery('.bookmarks_list').on('click', '.bookmarks_delete', function(e) {
378		"use strict";
379		var idx = jQuery(this).parent().index();
380		var list = jQuery.cookie('themerex_bookmarks');
381		if (list) {
382			list = JSON.parse(list);
383			list.splice(idx, 1);
384			jQuery.cookie('themerex_bookmarks', JSON.stringify(list), {expires: 365, path: '/'});
385		}
386		jQuery(this).parent().remove();
387		e.preventDefault();
388		return false;
389	});
390
391
392
393	// Other settings
394    //------------------------------------
395
396	// Scroll to top button
397	jQuery('.scroll_to_top').click(function(e) {
398		"use strict";
399		jQuery('html,body').animate({
400			scrollTop: 0
401		}, 'slow');
402		e.preventDefault();
403		return false;
404	});
405
406    // Show system message
407	themerex_show_system_message();
408
409	// Init post format specific scripts
410	themerex_init_post_formats();
411
412	// Init shortcodes scripts
413	themerex_init_shortcodes(jQuery('body').eq(0));
414
415	// Init hidden elements (if exists)
416	if (window.themerex_init_hidden_elements) themerex_init_hidden_elements(jQuery('body').eq(0));
417	
418} //end ready
419
420
421
422
423// Scroll actions
424//==============================================
425
426// Do actions when page scrolled
427function themerex_scroll_actions() {
428	"use strict";
429
430	var scroll_offset = jQuery(window).scrollTop();
431	var scroll_to_top_button = jQuery('.scroll_to_top');
432	var adminbar_height = Math.max(0, jQuery('#wpadminbar').height());
433
434	if (THEMEREX_GLOBALS['top_panel_height'] == 0)	THEMEREX_GLOBALS['top_panel_height'] = jQuery('.top_panel_wrap').height();
435
436	// Call skin specific action (if exists)
437    //----------------------------------------------
438	if (window.themerex_skin_scroll_actions) themerex_skin_scroll_actions();
439
440
441	// Scroll to top button show/hide
442	if (scroll_offset > THEMEREX_GLOBALS['top_panel_height'])
443		scroll_to_top_button.addClass('show');
444	else
445		scroll_to_top_button.removeClass('show');
446	
447	// Fix/unfix top panel
448	if (!jQuery('body').hasClass('responsive_menu') && THEMEREX_GLOBALS['menu_fixed']) {
449		var slider_height = 0;
450		if (jQuery('.top_panel_below .slider_wrap').length > 0) {
451			slider_height = jQuery('.top_panel_below .slider_wrap').height();
452			if (slider_height < 10) {
453				slider_height = jQuery('.slider_wrap').hasClass('.slider_fullscreen') ? jQuery(window).height() : THEMEREX_GLOBALS['slider_height'];
454			}
455		}
456		if (scroll_offset <= slider_height + THEMEREX_GLOBALS['top_panel_height']) {
457			if (jQuery('body').hasClass('top_panel_fixed')) {
458				jQuery('body').removeClass('top_panel_fixed');
459			}
460		} else if (scroll_offset > slider_height + THEMEREX_GLOBALS['top_panel_height']) {
461			if (!jQuery('body').hasClass('top_panel_fixed')) {
462				jQuery('.top_panel_fixed_wrap').height(THEMEREX_GLOBALS['top_panel_height']);
463				jQuery('.top_panel_wrap').css('marginTop', '-150px').animate({'marginTop': 0}, 500);
464				jQuery('body').addClass('top_panel_fixed');
465			}
466		}
467	}
468
469	// TOC current items
470	jQuery('#toc .toc_item').each(function() {
471		"use strict";
472		var id = jQuery(this).find('a').attr('href');
473		var pos = id.indexOf('#');
474		if (pos < 0 || id.length == 1) return;
475		var loc = window.location.href;
476		var pos2 = loc.indexOf('#');
477		if (pos2 > 0) loc = loc.substring(0, pos2);
478		var now = pos==0;
479		if (!now) now = loc == href.substring(0, pos);
480		if (!now) return;
481		var off = jQuery(id).offset().top;
482		var id_next  = jQuery(this).next().find('a').attr('href');
483		var off_next = id_next ? jQuery(id_next).offset().top : 1000000;
484		if (off < scroll_offset + jQuery(window).height()*0.8 && scroll_offset + THEMEREX_GLOBALS['top_panel_height'] < off_next)
485			jQuery(this).addClass('current');
486		else
487			jQuery(this).removeClass('current');
488	});
489	
490	// Infinite pagination
491	themerex_infinite_scroll()
492	
493	// Parallax scroll
494	themerex_parallax_scroll();
495	
496	// Scroll actions for shortcodes
497	themerex_animation_shortcodes();
498}
499
500
501// Infinite Scroll
502function themerex_infinite_scroll() {
503	"use strict";
504	if (THEMEREX_GLOBALS['viewmore_busy']) return;
505	var infinite = jQuery('#viewmore.pagination_infinite');
506	if (infinite.length > 0) {
507		var viewmore = infinite.find('#viewmore_link:not(.viewmore_empty)');
508		if (viewmore.length > 0) {
509			if (jQuery(window).scrollTop() + jQuery(window).height() + 100 >= infinite.offset().top) {
510				viewmore.eq(0).trigger('click');
511			}
512		}
513	}
514}
515
516// Parallax scroll
517function themerex_parallax_scroll(){
518	jQuery('.sc_parallax').each(function(){
519		var windowHeight = jQuery(window).height();
520		var scrollTops = jQuery(window).scrollTop();
521		var offsetPrx = Math.max(jQuery(this).offset().top, windowHeight);
522		if ( offsetPrx <= scrollTops + windowHeight ) {
523			var speed  = Number(jQuery(this).data('parallax-speed'));
524			var xpos   = jQuery(this).data('parallax-x-pos');  
525			var ypos   = Math.round((offsetPrx - scrollTops - windowHeight) * speed + (speed < 0 ? windowHeight*speed : 0));
526			jQuery(this).find('.sc_parallax_content').css('backgroundPosition', xpos+' '+ypos+'px');
527			// Uncomment next line if you want parallax video (else - video position is static)
528			jQuery(this).find('div.sc_video_bg').css('top', ypos+'px');
529		} 
530	});
531}
532
533
534
535
536
537// Resize actions
538//==============================================
539
540// Do actions when page scrolled
541function themerex_resize_actions() {
542	"use strict";
543
544	// Call skin specific action (if exists)
545    //----------------------------------------------
546	if (window.themerex_skin_resize_actions) themerex_skin_resize_actions();
547	themerex_responsive_menu();
548	themerex_video_dimensions();
549	themerex_resize_video_background();
550	themerex_resize_fullscreen_slider();
551}
552
553
554// Check window size and do responsive menu
555function themerex_responsive_menu() {
556	if (themerex_is_responsive_need(THEMEREX_GLOBALS['menu_responsive'])) {
557		if (!jQuery('body').hasClass('responsive_menu')) {
558			jQuery('body').removeClass('top_panel_fixed').addClass('responsive_menu');
559			if (jQuery('body').hasClass('menu_relayout'))
560				jQuery('body').removeClass('menu_relayout');
561			if (jQuery('ul.menu_main_nav').hasClass('inited')) {
562				jQuery('ul.menu_main_nav').removeClass('inited').superfish('destroy');
563			}
564			if (jQuery('ul.menu_side_nav').hasClass('inited')) {
565				jQuery('ul.menu_side_nav').removeClass('inited').superfish('destroy');
566			}
567		}
568	} else {
569		if (jQuery('body').hasClass('responsive_menu')) {
570			jQuery('body').removeClass('responsive_menu');
571			jQuery('.menu_main_responsive').hide();
572			jQuery('.menu_side_responsive').hide();
573			themerex_init_sfmenu('ul.menu_main_nav,ul.menu_side_nav');
574			jQuery('.menu_main_nav_area').show();
575		}
576		if (themerex_is_responsive_need(THEMEREX_GLOBALS['menu_relayout']))
577			jQuery('body').addClass('menu_relayout');
578		else if (jQuery('body').hasClass('menu_relayout'))
579			jQuery('body').removeClass('menu_relayout');
580	}
581	if (!jQuery('.top_panel_wrap').hasClass('menu_show')) jQuery('.top_panel_wrap').addClass('menu_show');
582}
583
584
585// Check if responsive menu need
586function themerex_is_responsive_need(max_width) {
587	"use strict";
588	var rez = false;
589	if (max_width > 0) {
590		var w = window.innerWidth;
591		if (w == undefined) {
592			w = jQuery(window).width()+(jQuery(window).height() < jQuery(document).height() || jQuery(window).scrollTop() > 0 ? 16 : 0);
593		}
594		rez = max_width > w;
595	}
596	return rez;
597}
598
599
600
601// Fit video frames to document width
602function themerex_video_dimensions() {
603	jQuery('.sc_video_frame').each(function() {
604		"use strict";
605		var frame  = jQuery(this).eq(0);
606		var player = frame.parent();
607		var ratio = (frame.data('ratio') ? frame.data('ratio').split(':') : (frame.find('[data-ratio]').length>0 ? frame.find('[data-ratio]').data('ratio').split(':') : [16,9]));
608		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
609		var w_attr = frame.data('width');
610		var h_attr = frame.data('height');
611		if (!w_attr || !h_attr) {
612			return;
613		}
614		var percent = (''+w_attr).substr(-1)=='%';
615		w_attr = parseInt(w_attr);
616		h_attr = parseInt(h_attr);
617		var w_real = Math.min(percent ? 10000 : w_attr, frame.parents('div,article').width()), //player.width();
618			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
619		if (parseInt(frame.attr('data-last-width'))==w_real) return;
620		if (percent) {
621			frame.height(h_real);
622		} else {
623			frame.css({'width': w_real+'px', 'height': h_real+'px'});
624		}
625		frame.attr('data-last-width', w_real);
626	});
627	jQuery('video.sc_video,video.wp-video-shortcode').each(function() {
628		"use strict";
629		var video = jQuery(this).eq(0);
630		var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
631		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
632		var mejs_cont = video.parents('.mejs-video');
633		var frame = video.parents('.sc_video_frame');
634		var w_attr = frame.length>0 ? frame.data('width') : video.data('width');
635		var h_attr = frame.length>0 ? frame.data('height') : video.data('height');
636		if (!w_attr || !h_attr) {
637			w_attr = video.attr('width');
638			h_attr = video.attr('height');
639			if (!w_attr || !h_attr) return;
640			video.data({'width': w_attr, 'height': h_attr});
641		}
642		var percent = (''+w_attr).substr(-1)=='%';
643		w_attr = parseInt(w_attr);
644		h_attr = parseInt(h_attr);
645		var w_real = Math.round(mejs_cont.length > 0 ? Math.min(percent ? 10000 : w_attr, mejs_cont.parents('div,article').width()) : video.width()),
646			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
647		if (parseInt(video.attr('data-last-width'))==w_real) return;
648		if (mejs_cont.length > 0 && mejs) {
649			themerex_set_mejs_player_dimensions(video, w_real, h_real);
650		}
651		if (percent) {
652			video.height(h_real);
653		} else {
654			video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'});
655		}
656		video.attr('data-last-width', w_real);
657	});
658	jQuery('video.sc_video_bg').each(function() {
659		"use strict";
660		var video = jQuery(this).eq(0);
661		var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
662		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
663		var mejs_cont = video.parents('.mejs-video');
664		var container = mejs_cont.length>0 ? mejs_cont.parent() : video.parent();
665		var w = container.width();
666		var h = container.height();
667		var w1 = Math.ceil(h*ratio);
668		var h1 = Math.ceil(w/ratio);
669		if (video.parents('.sc_parallax').length > 0) {
670			var windowHeight = jQuery(window).height();
671			var speed = Number(video.parents('.sc_parallax').data('parallax-speed'));
672			var h_add = Math.ceil(Math.abs((windowHeight-h)*speed));
673			if (h1 < h + h_add) {
674				h1 = h + h_add;
675				w1 = Math.ceil(h1 * ratio);
676			}
677		}
678		if (h1 < h) {
679			h1 = h;
680			w1 = Math.ceil(h1 * ratio);
681		}
682		if (w1 < w) { 
683			w1 = w;
684			h1 = Math.ceil(w1 / ratio);
685		}
686		var l = Math.round((w1-w)/2);
687		var t = Math.round((h1-h)/2);
688		if (parseInt(video.attr('data-last-width'))==w1) return;
689		if (mejs_cont.length > 0) {
690			themerex_set_mejs_player_dimensions(video, w1, h1);
691			mejs_cont.css({
692				//'left': -l+'px',
693				'top': -t+'px'
694			});
695		} else
696			video.css({
697				//'left': -l+'px',
698				'top': -t+'px'
699			});
700		video.attr({'width': w1, 'height': h1, 'data-last-width':w1}).css({'width':w1+'px', 'height':h1+'px'});
701		if (video.css('opacity')==0) video.animate({'opacity': 1}, 3000);
702	});
703	jQuery('iframe').each(function() {
704		"use strict";
705		var iframe = jQuery(this).eq(0);
706		var ratio = (iframe.data('ratio')!=undefined ? iframe.data('ratio').split(':') : (iframe.find('[data-ratio]').length>0 ? iframe.find('[data-ratio]').data('ratio').split(':') : [16,9]));
707		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
708		var w_attr = iframe.attr('width');
709		var h_attr = iframe.attr('height');
710		var frame = iframe.parents('.sc_video_frame');
711		if (frame.length > 0) {
712			w_attr = frame.data('width');
713			h_attr = frame.data('height');
714		}
715		if (!w_attr || !h_attr) {
716			return;
717		}
718		var percent = (''+w_attr).substr(-1)=='%';
719		w_attr = parseInt(w_attr);
720		h_attr = parseInt(h_attr);
721		var w_real = frame.length > 0 ? frame.width() : iframe.width(),
722			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
723		if (parseInt(iframe.attr('data-last-width'))==w_real) return;
724		iframe.css({'width': w_real+'px', 'height': h_real+'px'});
725	});
726}
727
728// Resize fullscreen video background
729function themerex_resize_video_background() {
730	var bg = jQuery('.video_bg');
731	if (bg.length < 1) 
732		return;
733	if (THEMEREX_GLOBALS['media_elements_enabled'] && bg.find('.mejs-video').length == 0)  {
734		setTimeout(themerex_resize_video_background, 100);
735		return;
736	}
737	var video = bg.find('video');
738	var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
739	ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
740	var w = bg.width();
741	var h = bg.height();
742	var w1 = Math.ceil(h*ratio);
743	var h1 = Math.ceil(w/ratio);
744	if (h1 < h) {
745		h1 = h;
746		w1 = Math.ceil(h1 * ratio);
747	}
748	if (w1 < w) { 
749		w1 = w;
750		h1 = Math.ceil(w1 / ratio);
751	}
752	var l = Math.round((w1-w)/2);
753	var t = Math.round((h1-h)/2);
754	if (bg.find('.mejs-container').length > 0) {
755		themerex_set_mejs_player_dimensions(bg.find('video'), w1, h1);
756		bg.find('.mejs-container').css({'left': -l+'px', 'top': -t+'px'});
757	} else
758		bg.find('video').css({'left': -l+'px', 'top': -t+'px'});
759	bg.find('video').attr({'width': w1, 'height': h1}).css({'width':w1+'px', 'height':h1+'px'});
760}
761
762// Set Media Elements player dimensions
763function themerex_set_mejs_player_dimensions(video, w, h) {
764	if (mejs) {
765		for (var pl in mejs.players) {
766			if (mejs.players[pl].media.src == video.attr('src')) {
767				if (mejs.players[pl].media.setVideoSize) {
768					mejs.players[pl].media.setVideoSize(w, h);
769				}
770				mejs.players[pl].setPlayerSize(w, h);
771				mejs.players[pl].setControlsSize();
772				//var mejs_cont = video.parents('.mejs-video');
773				//mejs_cont.css({'width': w+'px', 'height': h+'px'}).find('.mejs-layers > div, .mejs-overlay, .mejs-poster').css({'width': w, 'height': h});
774			}
775		}
776	}
777}
778
779// Resize Fullscreen Slider
780function themerex_resize_fullscreen_slider() {
781	var slider_wrap = jQuery('.slider_wrap.slider_fullscreen');
782	if (slider_wrap.length < 1) 
783		return;
784	var slider = slider_wrap.find('.sc_slider_swiper');
785	if (slider.length < 1) 
786		return;
787	var h = jQuery(window).height() - jQuery('#wpadminbar').height() - (jQuery('body').hasClass('top_panel_above') && !jQuery('body').hasClass('.top_panel_fixed') ? jQuery('.top_panel_wrap').height() : 0);
788	slider.height(h);
789}
790
791
792
793
794
795// Navigation
796//==============================================
797
798// Init Superfish menu
799function themerex_init_sfmenu(selector) {
800	jQuery(selector).show().each(function() {
801		if (themerex_is_responsive_need() && (jQuery(this).attr('id')=='menu_main' || jQuery(this).attr('id')=='menu_side')) return;
802		jQuery(this).addClass('inited').superfish({
803			delay: 200,
804			animation: {
805				opacity: 'show'
806			},
807			animationOut: {
808				opacity: 'hide'
809			},
810            speed: 		THEMEREX_GLOBALS['css_animation'] ? 100 : (THEMEREX_GLOBALS['menu_slider'] ? 300 : 200),
811			speedOut:	THEMEREX_GLOBALS['css_animation'] ? 500 : (THEMEREX_GLOBALS['menu_slider'] ? 300 : 200),
812			autoArrows: false,
813			dropShadows: false,
814			onBeforeShow: function(ul) {
815				if (jQuery(this).parents("ul").length > 1){
816					var w = jQuery(window).width();  
817					var par_offset = jQuery(this).parents("ul").offset().left;
818					var par_width  = jQuery(this).parents("ul").outerWidth();
819					var ul_width   = jQuery(this).outerWidth();
820					if (par_offset+par_width+ul_width > w-20 && par_offset-ul_width > 0)
821						jQuery(this).addClass('submenu_left');
822					else
823						jQuery(this).removeClass('submenu_left');
824				}
825				if (THEMEREX_GLOBALS['css_animation']) {
826					jQuery(this).removeClass('animated fast '+THEMEREX_GLOBALS['menu_animation_out']);
827					jQuery(this).addClass('animated fast '+THEMEREX_GLOBALS['menu_animation_in']);
828				}
829			},
830			onBeforeHide: function(ul) {
831				if (THEMEREX_GLOBALS['css_animation']) {
832					jQuery(this).removeClass('animated fast '+THEMEREX_GLOBALS['menu_animation_in']);
833					jQuery(this).addClass('animated fast '+THEMEREX_GLOBALS['menu_animation_out']);
834				}
835			}
836		});
837	});
838}
839
840
841// Build page TOC from the tag's id
842function themerex_build_page_toc() {
843	"use strict";
844	var toc = '', toc_count = 0;
845	jQuery('[id^="toc_"],.sc_anchor').each(function(idx) {
846		"use strict";
847		var obj = jQuery(this);
848		var id = obj.attr('id');
849		var url = obj.data('url');
850		var icon = obj.data('icon');
851		if (!icon) icon = 'icon-circle-dot';
852		var title = obj.attr('title');
853		var description = obj.data('description');
854		var separator = obj.data('separator');
855		toc_count++;
856		toc += '<div class="toc_item'+(separator=='yes' ? ' toc_separator' : '')+'">'
857			+(description ? '<div class="toc_description">'+description+'</div>' : '')
858			+'<a href="'+(url ? url : '#'+id)+'" class="toc_icon'+(title ? ' with_title' : '')+' '+icon+'">'+(title ? '<span class="toc_title">'+title+'</span>' : '')+'</a>'
859			+'</div>';
860	});
861	if (toc_count > (THEMEREX_GLOBALS['toc_menu_home'] ? 1 : 0) + (THEMEREX_GLOBALS['toc_menu_top'] ? 1 : 0)) {
862		if (jQuery('#toc').length > 0)
863			jQuery('#toc .toc_inner').html(toc);
864		else
865			jQuery('body').append('<div id="toc" class="toc_'+THEMEREX_GLOBALS['toc_menu']+'"><div class="toc_inner">'+toc+'</div></div>');
866	}
867}
868
869
870
871
872
873
874
875
876// Isotope
877//=====================================================
878
879// First init isotope containers
880function themerex_init_isotope() {
881	"use strict";
882
883	var all_images_complete = true;
884
885	// Check if all images in isotope wrapper are loaded
886	jQuery('.isotope_wrap:not(.inited)').each(function () {
887		"use strict";
888		all_images_complete = all_images_complete && themerex_check_images_complete(jQuery(this));
889	});
890	// Wait for images loading
891	if (!all_images_complete && THEMEREX_GLOBALS['isotope_init_counter']++ < 30) {
892		setTimeout(themerex_init_isotope, 200);
893		return;
894	}
895
896	// Isotope filters handler
897	jQuery('.isotope_filters:not(.inited)').addClass('inited').on('click', 'a', function(e) {
898		"use strict";
899		jQuery(this).parents('.isotope_filters').find('a').removeClass('active');
900		jQuery(this).addClass('active');
901	
902		var selector = jQuery(this).data('filter');
903		jQuery(this).parents('.isotope_filters').siblings('.isotope_wrap').eq(0).isotope({
904			filter: selector
905		});
906
907		if (selector == '*')
908			jQuery('#viewmore_link').fadeIn();
909		else
910			jQuery('#viewmore_link').fadeOut();
911
912		e.preventDefault();
913		return false;
914	});
915
916	// Init isotope script
917	jQuery('.isotope_wrap:not(.inited)').each(function() {
918		"use strict";
919
920		var isotope_container = jQuery(this);
921
922		// Init shortcodes
923		themerex_init_shortcodes(isotope_container);
924
925		// If in scroll container - no init isotope
926		if (isotope_container.parents('.sc_scroll').length > 0) {
927			isotope_container.addClass('inited').find('.isotope_item').animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); });
928			return;
929		}
930		
931		// Init isotope with timeout
932		setTimeout(function() {
933			isotope_container.addClass('inited').isotope({
934				itemSelector: '.isotope_item',
935				animationOptions: {
936					duration: 750,
937					easing: 'linear',
938					queue: false
939				}
940			});
941	
942			// Show elements
943			isotope_container.find('.isotope_item').animate({opacity: 1}, 200, function () { 
944				jQuery(this).addClass('isotope_item_show'); 
945			});
946			
947		}, 500);
948
949	});		
950}
951
952function themerex_init_appended_isotope(posts_container, filters) {
953	"use strict";
954	
955	if (posts_container.parents('.sc_scroll_horizontal').length > 0) return;
956	
957	if (!themerex_check_images_complete(posts_container) && THEMEREX_GLOBALS['isotope_init_counter']++ < 30) {
958		setTimeout(function() { themerex_init_appended_isotope(posts_container, filters); }, 200);
959		return;
960	}
961	// Add filters
962	var flt = posts_container.siblings('.isotope_filter');
963	for (var i in filters) {
964		if (flt.find('a[data-filter=".flt_'+i+'"]').length == 0) {
965			flt.append('<a href="#" class="isotope_filters_button" data-filter=".flt_'+i+'">'+filters[i]+'</a>');
966		}
967	}
968	// Init shortcodes in added elements
969	themerex_init_shortcodes(posts_container);
970	// Get added elements
971	var elems = posts_container.find('.isotope_item:not(.isotope_item_show)');
972	// Notify isotope about added elements with timeout
973	setTimeout(function() {
974		posts_container.isotope('appended', elems);
975		// Show appended elements
976		elems.animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); });
977	}, 500);
978}
979
980
981
982// Post formats init
983//=====================================================
984
985function themerex_init_post_formats() {
986	"use strict";
987
988	// MediaElement init
989	themerex_init_media_elements(jQuery('body'));
990	
991	// Isotope first init
992	if (jQuery('.isotope_wrap:not(.inited)').length > 0) {
993		THEMEREX_GLOBALS['isotope_init_counter'] = 0;
994		themerex_init_isotope();
995	}
996
997	// Hover Effect 'Dir'
998	if (jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').length > 0) {
999		jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').each(function() {
1000			jQuery(this).addClass('inited').hoverdir();
1001		});
1002	}
1003
1004	// Popup init
1005	if (THEMEREX_GLOBALS['popup_engine'] == 'pretty') {
1006		jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'prettyPhoto[slideshow]');
1007		var images = jQuery("a[rel*='prettyPhoto']:not(.inited):not([data-rel*='pretty']):not([rel*='magnific']):not([data-rel*='magnific'])").addClass('inited');
1008		try {
1009			images.prettyPhoto({
1010				social_tools: '',
1011				theme: 'facebook',
1012				deeplinking: false
1013			});
1014		} catch (e) {};
1015	} else if (THEMEREX_GLOBALS['popup_engine']=='magnific') {
1016		jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'magnific');
1017		var images = jQuery("a[rel*='magnific']:not(.inited):not(.prettyphoto):not([rel*='pretty']):not([data-rel*='pretty'])").addClass('inited');
1018		try {
1019			images.magnificPopup({
1020				type: 'image',
1021				mainClass: 'mfp-img-mobile',
1022				closeOnContentClick: true,
1023				closeBtnInside: true,
1024				fixedContentPos: true,
1025				midClick: true,
1026				//removalDelay: 500, 
1027				preloader: true,
1028				tLoading: THEMEREX_GLOBALS['strings']['magnific_loading'],
1029				gallery:{
1030					enabled: true
1031				},
1032				image: {
1033					tError: THEMEREX_GLOBALS['strings']['magnific_error'],
1034					verticalFit: true
1035				}
1036			});
1037		} catch (e) {};
1038	}
1039
1040
1041	// Add hover icon to products thumbnails
1042	jQuery(".post_item_product .product .images a.woocommerce-main-image:not(.hover_icon)").addClass('hover_icon hover_icon_view');
1043
1044
1045	// Likes counter
1046	if (jQuery('.post_counters_likes:not(.inited)').length > 0) {
1047		jQuery('.post_counters_likes:not(.inited)')
1048			.addClass('inited')
1049			.click(function(e) {
1050				var button = jQuery(this);
1051				var inc = button.hasClass('enabled') ? 1 : -1;
1052				var post_id = button.data('postid');
1053				var likes = Number(button.data('likes'))+inc;
1054				var cookie_likes = themerex_get_cookie('themerex_likes');
1055				if (cookie_likes === undefined || cookie_likes===null) cookie_likes = '';
1056				jQuery.post(THEMEREX_GLOBALS['ajax_url'], {
1057					action: 'post_counter',
1058					nonce: THEMEREX_GLOBALS['ajax_nonce'],
1059					post_id: post_id,
1060					likes: likes
1061				}).done(function(response) {
1062					var rez = JSON.parse(response);
1063					if (rez.error === '') {
1064						if (inc == 1) {
1065							var title = button.data('title-dislike');
1066							button.removeClass('enabled').addClass('disabled');
1067							cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + ',';
1068						} else {
1069							var title = button.data('title-like');
1070							button.removeClass('disabled').addClass('enabled');
1071							cookie_likes = cookie_likes.replace(','+post_id+',', ',');
1072						}
1073						button.data('likes', likes).attr('title', title).find('.post_counters_number').html(likes);
1074						themerex_set_cookie('themerex_likes', cookie_likes, 365);
1075					} else {
1076						themerex_message_warning(THEMEREX_GLOBALS['strings']['error_like']);
1077					}
1078				});
1079				e.preventDefault();
1080				return false;
1081			});
1082	}
1083
1084	// Add video on thumb click
1085	if (jQuery('.sc_video_play_button:not(.inited)').length > 0) {
1086		jQuery('.sc_video_play_button:not(.inited)').each(function() {
1087			"use strict";
1088			jQuery(this)
1089				.addClass('inited')
1090				.animate({opacity: 1}, 1000)
1091				.click(function (e) {
1092					"use strict";
1093					if (!jQuery(this).hasClass('sc_video_play_button')) return;
1094					var video = jQuery(this).removeClass('sc_video_play_button hover_icon_play').data('video');
1095					if (video!=='') {
1096						jQuery(this).empty().html(video);
1097						themerex_video_dimensions();
1098						var video_tag = jQuery(this).find('video');
1099						var w = video_tag.width();
1100						var h = video_tag.height();
1101						themerex_init_media_elements(jQuery(this));
1102						// Restore WxH attributes, because Chrome broke it!
1103						jQuery(this).find('video').css({'width':w, 'height': h}).attr({'width':w, 'height': h});
1104					}
1105					e.preventDefault();
1106					return false;
1107				});
1108		});
1109	}
1110
1111	// Tribe Events buttons
1112	jQuery('a.tribe-events-read-more,.tribe-events-button,.tribe-events-nav-previous a,.tribe-events-nav-next a,.tribe-events-widget-link a,.tribe-events-viewmore a').addClass('sc_button sc_button_style_filled');
1113}
1114
1115
1116function themerex_init_media_elements(cont) {
1117	if (THEMEREX_GLOBALS['media_elements_enabled'] && cont.find('audio,video').length > 0) {
1118		if (window.mejs) {
1119			window.mejs.MepDefaults.enableAutosize = false;
1120			window.mejs.MediaElementDefaults.enableAutosize = false;
1121			cont.find('audio:not(.wp-audio-shortcode),video:not(.wp-video-shortcode)').each(function() {
1122				if (jQuery(this).parents('.mejs-mediaelement').length == 0) {
1123					var media_tag = jQuery(this);
1124					var settings = {
1125						enableAutosize: true,
1126						videoWidth: -1,		// if set, overrides <video width>
1127						videoHeight: -1,	// if set, overrides <video height>
1128						audioWidth: '100%',	// width of audio player
1129						audioHeight: 30,	// height of audio player
1130						success: function(mejs) {
1131							var autoplay, loop;
1132							if ( 'flash' === mejs.pluginType ) {
1133								autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
1134								loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
1135								autoplay && mejs.addEventListener( 'canplay', function () {
1136									mejs.play();
1137								}, false );
1138								loop && mejs.addEventListener( 'ended', function () {
1139									mejs.play();
1140								}, false );
1141							}
1142							media_tag.parents('.sc_audio,.sc_video').addClass('inited sc_show');
1143						}
1144					};
1145					jQuery(this).mediaelementplayer(settings);
1146				}
1147			});
1148		} else
1149			setTimeout(function() { themerex_init_media_elements(cont); }, 400);
1150	}
1151}
1152
1153
1154
1155
1156
1157
1158// Popups and system messages
1159//==============================================
1160
1161// Show system message (bubble from previous page)
1162function themerex_show_system_message() {
1163	if (THEMEREX_GLOBALS['system_message']['message']) {
1164		if (THEMEREX_GLOBALS['system_message']['status'] == 'success')
1165			themerex_message_success(THEMEREX_GLOBALS['system_message']['message'], THEMEREX_GLOBALS['system_message']['header']);
1166		else if (THEMEREX_GLOBALS['system_message']['status'] == 'info')
1167			themerex_message_info(THEMEREX_GLOBALS['system_message']['message'], THEMEREX_GLOBALS['system_message']['header']);
1168		else if (THEMEREX_GLOBALS['system_message']['status'] == 'error' || THEMEREX_GLOBALS['system_message']['status'] == 'warning')
1169			themerex_message_warning(THEMEREX_GLOBALS['system_message']['message'], THEMEREX_GLOBALS['system_message']['header']);
1170	}
1171}
1172
1173// Toggle popups
1174function themerex_toggle_popup(popup) {
1175	if (popup.css('display')!='none')
1176		themerex_hide_popup(popup);
1177	else
1178		themerex_show_popup(popup);
1179}
1180
1181// Show popups
1182function themerex_show_popup(popup) {
1183	if (popup.css('display')=='none') {
1184		if (THEMEREX_GLOBALS['css_animation'])
1185			popup.show().removeClass('animated fast '+THEMEREX_GLOBALS['menu_animation_out']).addClass('animated fast '+THEMEREX_GLOBALS['menu_animation_in']);
1186		else
1187			popup.slideDown();
1188	}
1189}
1190
1191// Hide popups
1192function themerex_hide_popup(popup) {
1193	if (popup.css('display')!='none') {
1194		if (THEMEREX_GLOBALS['css_animation'])
1195			popup.removeClass('animated fast '+THEMEREX_GLOBALS['menu_animation_in']).addClass('animated fast '+THEMEREX_GLOBALS['menu_animation_out']).delay(500).hide();
1196		else
1197			popup.fadeOut();
1198	}
1199}
1200
1201
1202
1203
1204// Forms validation
1205//-------------------------------------------------------
1206
1207
1208// Comments form
1209function themerex_comments_validate(form) {
1210	"use strict";
1211	form.find('input').removeClass('error_fields_class');
1212	var error = themerex_form_validate(form, {
1213		error_message_text: THEMEREX_GLOBALS['strings']['error_global'],	// Global error message text (if don't write in checked field)
1214		error_message_show: true,									// Display or not error message
1215		error_message_time: 4000,									// Error message display time
1216		error_message_class: 'sc_infobox sc_infobox_style_error',	// Class appended to error message block
1217		error_fields_class: 'error_fields_class',					// Class appended to error fields
1218		exit_after_first_error: false,								// Cancel validation and exit after first error
1219		rules: [
1220			{
1221				field: 'author',
1222				min_length: { value: 1, message: THEMEREX_GLOBALS['strings']['name_empty']},
1223				max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['name_long']}
1224			},
1225			{
1226				field: 'email',
1227				min_length: { value: 7, message: THEMEREX_GLOBALS['strings']['email_empty']},
1228				max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['email_long']},
1229				mask: { value: THEMEREX_GLOBALS['email_mask'], message: THEMEREX_GLOBALS['strings']['email_not_val
1229id']}
1230			},
1231			{
1232				field: 'comment',
1233				min_length: { value: 1, message: THEMEREX_GLOBALS['strings']['text_empty'] },
1234				max_length: { value: THEMEREX_GLOBALS['comments_maxlength'], message: THEMEREX_GLOBALS['strings']['text_long']}
1235			}
1236		]
1237	});
1238	return !error;
1239}
1240
1241
1242// Login form
1243function themerex_login_validate(form) {
1244	"use strict";
1245	form.find('input').removeClass('error_fields_class');
1246	var error = themerex_form_validate(form, {
1247		error_message_show: true,
1248		error_message_time: 4000,
1249		error_message_class: 'sc_infobox sc_infobox_style_error',
1250		error_fields_class: 'error_fields_class',
1251		exit_after_first_error: true,
1252		rules: [
1253			{
1254				field: "log",
1255				min_length: { value: 1, message: THEMEREX_GLOBALS['strings']['login_empty'] },
1256				max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['login_long'] }
1257			},
1258			{
1259				field: "pwd",
1260				min_length: { value: 4, message: THEMEREX_GLOBALS['strings']['password_empty'] },
1261				max_length: { value: 30, message: THEMEREX_GLOBALS['strings']['password_long'] }
1262			}
1263		]
1264	});
1265	if (!error) {
1266		jQuery.post(THEMEREX_GLOBALS['ajax_url'], {
1267			action: 'login_user',
1268			nonce: THEMEREX_GLOBALS['ajax_nonce'],
1269			remember: form.find('#rememberme').val(),
1270			user_log: form.find('#log').val(),
1271			user_pwd: form.find('#password').val()
1272		}).done(function(response) {
1273			var rez = JSON.parse(response);
1274			var result_box = form.find('.result');
1275			if (result_box.length==0) result_box = form.siblings('.result');
1276			if (result_box.length==0) result_box = form.after('<div class="result"></div>').next('.result');
1277			result_box.toggleClass('sc_infobox_style_error', false).toggleClass('sc_infobox_style_success', false);
1278			if (rez.error === '') {
1279				result_box.addClass('sc_infobox sc_infobox_style_success').html(THEMEREX_GLOBALS['strings']['login_success']);
1280				setTimeout(function() { 
1281					location.reload(); 
1282					}, 3000);
1283			} else {
1284				result_box.addClass('sc_infobox sc_infobox_style_error').html(THEMEREX_GLOBALS['strings']['login_failed'] + '<br>' + rez.error);
1285			}
1286			result_box.fadeIn().delay(3000).fadeOut();
1287		});
1288	}
1289	return false;
1290}
1291
1292
1293// Registration form 
1294function themerex_registration_validate(form) {
1295	"use strict";
1296	form.find('input').removeClass('error_fields_class');
1297	var error = themerex_form_validate(form, {
1298		error_message_show: true,
1299		error_message_time: 4000,
1300		error_message_class: "sc_infobox sc_infobox_style_error",
1301		error_fields_class: "error_fields_class",
1302		exit_after_first_error: true,
1303		rules: [
1304			{
1305				field: "registration_username",
1306				min_length: { value: 1, message: THEMEREX_GLOBALS['strings']['login_empty'] },
1307				max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['login_long'] }
1308			},
1309			{
1310				field: "registration_email",
1311				min_length: { value: 7, message: THEMEREX_GLOBALS['strings']['email_empty'] },
1312				max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['email_long'] },
1313				mask: { value: THEMEREX_GLOBALS['email_mask'], message: THEMEREX_GLOBALS['strings']['email_not_valid'] }
1314			},
1315			{
1316				field: "registration_pwd",
1317				min_length: { value: 4, message: THEMEREX_GLOBALS['strings']['password_empty'] },
1318				max_length: { value: 30, message: THEMEREX_GLOBALS['strings']['password_long'] }
1319			},
1320			{
1321				field: "registration_pwd2",
1322				equal_to: { value: 'registration_pwd', message: THEMEREX_GLOBALS['strings']['password_not_equal'] }
1323			}
1324		]
1325	});
1326	if (!error) {
1327		jQuery.post(THEMEREX_GLOBALS['ajax_url'], {
1328			action: 'registration_user',
1329			nonce: THEMEREX_GLOBALS['ajax_nonce'],
1330			user_name: 	form.find('#registration_username').val(),
1331			user_email: form.find('#registration_email').val(),
1332			user_pwd: 	form.find('#registration_pwd').val(),
1333		}).done(function(response) {
1334			var rez = JSON.parse(response);
1335			var result_box = form.find('.result');
1336			if (result_box.length==0) result_box = form.siblings('.result');
1337			if (result_box.length==0) result_box = form.after('<div class="result"></div>').next('.result');
1338			result_box.toggleClass('sc_infobox_style_error', false).toggleClass('sc_infobox_style_success', false);
1339			if (rez.error === '') {
1340				result_box.addClass('sc_infobox sc_infobox_style_success').html(THEMEREX_GLOBALS['strings']['registration_success']);
1341				setTimeout(function() { 
1342					jQuery('.popup_login_link').trigger('click'); 
1343					}, 3000);
1344			} else {
1345				result_box.addClass('sc_infobox sc_infobox_style_error').html(THEMEREX_GLOBALS['strings']['registration_failed'] + ' ' + rez.error);
1346			}
1347			result_box.fadeIn().delay(3000).fadeOut();
1348		});
1349	}
1350	return false;
1351}
1352
1353
1354
1355// Add placeholders to WP booking calendar
1356if (jQuery('#slot_reservation').length > 0) {
1357    var $cont = jQuery('#form_container_all > div');
1358    var $i = 0;
1359    $cont.each(function () {
1360        if ($i < 3)
1361            jQuery(this).find('input').attr('placeholder', jQuery(this).find('div').text());
1362        if ($i == 3)
1363            jQuery(this).find('textarea').attr('placeholder', jQuery(this).find('div').text());
1364        $i++;
1365    });
1366}
1367
1368
1369
1370// Contact form handlers
1371function themerex_contact_form_validate(form){
1372	"use strict";
1373	var url = form.attr('action');
1374	if (url == '') return false;
1375	form.find('input').removeClass('error_fields_class');
1376	var error = false;
1377	var form_custom = form.data('formtype')=='custom';
1378	if (!form_custom) {
1379		error = themerex_form_validate(form, {
1380			error_message_show: true,
1381			error_message_time: 4000,
1382			error_message_class: "sc_infobox sc_infobox_style_error",
1383			error_fields_class: "error_fields_class",
1384			exit_after_first_error: false,
1385			rules: [
1386				{
1387					field: "username",
1388					min_length: { value: 1,	 message: THEMEREX_GLOBALS['strings']['name_empty'] },
1389					max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['name_long'] }
1390				},
1391				{
1392					field: "email",
1393					min_length: { value: 7,	 message: THEMEREX_GLOBALS['strings']['email_empty'] },
1394					max_length: { value: 60, message: THEMEREX_GLOBALS['strings']['email_long'] },
1395					mask: { value: THEMEREX_GLOBALS['email_mask'], message: THEMEREX_GLOBALS['strings']['email_not_valid'] }
1396				},
1397				{
1398					field: "subject",
1399					min_length: { value: 1,	 message: THEMEREX_GLOBALS['strings']['subject_empty'] },
1400					max_length: { value: 100, message: THEMEREX_GLOBALS['strings']['subject_long'] }
1401				},
1402				{
1403					field: "message",
1404					min_length: { value: 1,  message: THEMEREX_GLOBALS['strings']['text_empty'] },
1405					max_length: { value: THEMEREX_GLOBALS['contacts_maxlength'], message: THEMEREX_GLOBALS['strings']['text_long'] }
1406				}
1407			]
1408		});
1409	}
1410	if (!error && url!='#') {
1411		jQuery.post(url, {
1412			action: "send_contact_form",
1413			nonce: THEMEREX_GLOBALS['ajax_nonce'],
1414			type: form_custom ? 'custom' : 'contact',
1415			data: form.serialize()
1416		}).done(function(response) {
1417			"use strict";
1418			var rez = JSON.parse(response);
1419			var result = form.find(".result").toggleClass("sc_infobox_style_error", false).toggleClass("sc_infobox_style_success", false);
1420			if (rez.error === '') {
1421				form.get(0).reset();
1422				result.addClass("sc_infobox_style_success").html(THEMEREX_GLOBALS['strings']['send_complete']);
1423			} else {
1424				result.addClass("sc_infobox_style_error").html(THEMEREX_GLOBALS['strings']['send_error'] + ' ' + rez.error);
1425			}
1426			result.fadeIn().delay(3000).fadeOut();
1427		});
1428	}
1429	return !error;
1430}

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.