PageSourceSearch

https://www.sariaya.gov.ph/wp-content/themes/citygov/fw/js/core.init.js

js sariaya.gov.ph collected 2026-10-02 17:01:26 UTC 62,110 bytes, 1,786 lines download raw bytes

1/* global jQuery:false */
2/* global CITYGOV_STORAGE:false */
3
4jQuery(document).ready(function() {
5	"use strict";
6	CITYGOV_STORAGE['theme_init_counter'] = 0;
7	citygov_init_actions();
8});
9
10jQuery(window).on('beforeunload', function() {
11	"use strict";
12	// Show preloader
13    if (jQuery.browser && !jQuery.browser.safari) jQuery('#page_preloader').css({display: 'block', opacity: 0}).animate({opacity:0.8}, 300);
14});
15
16
17// Theme init actions
18function citygov_init_actions() {
19	"use strict";
20
21	if (CITYGOV_STORAGE['vc_edit_mode'] && jQuery('.vc_empty-placeholder').length==0 && CITYGOV_STORAGE['theme_init_counter']++ < 30) {
22		setTimeout(citygov_init_actions, 200);
23		return;
24	}
25	
26	// Hide preloader
27//	jQuery('body.preloader>.outer_wrap,body.preloader>.body_wrap,body.preloader>.citygov_profiler').animate({opacity:1}, 'slow');	//.css({opacity:1});
28	jQuery('#page_preloader').animate({opacity:0}, 500, function() { jQuery(this).css({display: 'none'}); });
29
30	// Check for Retina display
31	if (citygov_is_retina()) {
32		citygov_set_cookie('citygov_retina', 1, 365);
33	}
34
35	citygov_ready_actions();
36	citygov_resize_actions();
37	citygov_scroll_actions();
38
39	// Resize handlers
40	jQuery(window).resize(function() {
41		"use strict";
42		citygov_resize_actions();
43		citygov_scroll_actions()
44	});
45
46	// Scroll handlers
47	jQuery(window).scroll(function() {
48		"use strict";
49		citygov_scroll_actions();
50	});
51}
52
53
54
55// Theme first load actions
56//==============================================
57function citygov_ready_actions() {
58	"use strict";
59
60	// Call skin specific action (if exists)
61    //----------------------------------------------
62	if (window.citygov_skin_ready_actions) citygov_skin_ready_actions();
63
64	// Call theme specific action (if exists)
65    //----------------------------------------------
66	if (window.citygov_theme_ready_actions) citygov_theme_ready_actions();
67
68
69	// Widgets decoration
70    //----------------------------------------------
71
72	// Decorate nested lists in widgets and side panels
73	jQuery('.widget ul > li').each(function() {
74		if (jQuery(this).find('ul').length > 0) {
75			jQuery(this).addClass('has_children');
76		}
77	});
78
79
80	// Archive widget decoration
81	jQuery('.widget_archive a').each(function() {
82		var val = jQuery(this).html().split(' ');
83		if (val.length > 1) {
84			val[val.length-1] = '<span>' + val[val.length-1] + '</span>';
85			jQuery(this).html(val.join(' '))
86		}
87	});
88
89	
90	// Calendar handlers - change months
91	jQuery('.widget_calendar').on('click', '.month_prev a, .month_next a', function(e) {
92		"use strict";
93		var calendar = jQuery(this).parents('.wp-calendar');
94		var m = jQuery(this).data('month');
95		var y = jQuery(this).data('year');
96		var pt = jQuery(this).data('type');
97		jQuery.post(CITYGOV_STORAGE['ajax_url'], {
98			action: 'calendar_change_month',
99			nonce: CITYGOV_STORAGE['ajax_nonce'],
100			month: m,
101			year: y,
102			post_type: pt
103		}).done(function(response) {
104			var rez = {};
105			try {
106				rez = JSON.parse(response);
107			} catch (e) {
108				rez = { error: CITYGOV_STORAGE['ajax_error'] };
109				console.log(response);
110			}
111			if (rez.error === '') {
112				calendar.parent().fadeOut(200, function() {
113					jQuery(this).find('.wp-calendar').remove();
114					jQuery(this).append(rez.data).fadeIn(200);
115				});
116			}
117		});
118		e.preventDefault();
119		return false;
120	});
121
122
123
124	// Media setup
125    //----------------------------------------------
126
127	// Video background init
128	jQuery('.video_background').each(function() {
129		var youtube = jQuery(this).data('youtube-code');
130		if (youtube) {
131			jQuery(this).tubular({videoId: youtube});
132		}
133	});
134
135
136
137	// Menu
138    //----------------------------------------------
139
140	// Prepare menus
141	if (CITYGOV_STORAGE['menu_cache']) citygov_prepare_menus();
142
143	// Clone side menu for responsive
144	if (jQuery('ul#menu_side').length > 0) {
145		jQuery('ul#menu_side').clone().removeAttr('id').removeClass('menu_side_nav').addClass('menu_side_responsive').insertAfter('ul#menu_side');
146		citygov_show_current_menu_item(jQuery('.menu_side_responsive'), jQuery('.sidebar_outer_menu_responsive_button'));
147	}
148
149	// Clone main menu for responsive
150	if (jQuery('.menu_main_nav_area ul#menu_main').length > 0) {
151		var menu_responsive = jQuery('.menu_main_nav_area ul#menu_main').clone().removeAttr('id').removeClass('menu_main_nav').addClass('menu_main_responsive');	//.insertAfter('ul#menu_main');
152		jQuery('.menu_main_nav_area ul#menu_main').parent().parent().append(menu_responsive);
153		citygov_show_current_menu_item(jQuery('.menu_main_responsive'), jQuery('.top_panel_style_1 .menu_main_responsive_button, .top_panel_style_2 .menu_main_responsive_button'));
154	}
155	
156	// Responsive menu button
157	jQuery('.menu_main_responsive_button, .sidebar_outer_menu_responsive_button').on('click', function(e){
158		"use strict";
159		if (jQuery(this).hasClass('menu_main_responsive_button'))
160			jQuery('.menu_main_responsive').slideToggle();
161		else {
162			jQuery(this).toggleClass('icon-down').toggleClass('icon-up');
163			jQuery('.menu_side_responsive').slideToggle();
164		}
165		e.preventDefault();
166		return false;
167	});
168	
169	// Push menu button
170	jQuery('.menu_pushy_button').on('click', function(e){
171		"use strict";
172		jQuery('body').addClass('pushy-active').css('overflow', 'hidden');
173		jQuery('.site-overlay').fadeIn('fast');
174		e.preventDefault();
175		return false;
176	});
177	jQuery('.pushy .close-pushy,.site-overlay').on('click', function(e){
178		jQuery('body').removeClass('pushy-active').css('overflow', 'visible');
179		jQuery('.site-overlay').fadeOut('fast');
180		e.preventDefault();
181		return false;
182	});
183	
184	// Side menu widgets button
185	jQuery('.sidebar_outer_widgets_button').on('click', function(e){
186		"use strict";
187		jQuery('.sidebar_outer_widgets').slideToggle();
188		e.preventDefault();
189		return false;
190	});
191
192	// Add arrows in responsive menu
193	jQuery('.menu_main_responsive .menu-item-has-children > a, .menu_side_responsive .menu-item-has-children > a, .menu_pushy_nav_area .menu-item-has-children > a, body:not(.woocommerce) .sidebar .widget_product_categories ul.product-categories .has_children > a').prepend('<span class="open_child_menu"></span>');
194
195	// Submenu click handler for the responsive menu
196	jQuery('.menu_main_responsive, .menu_side_responsive, .menu_pushy_nav_area, body:not(.woocommerce) .sidebar .widget_product_categories').on('click', 'li a,li a .open_child_menu, ul.product-categories.plain li a .open_child_menu', function(e) {
197		"use strict";
198		var is_menu_main = jQuery(this).parents('.menu_main_responsive').length > 0;
199		var $a = jQuery(this).hasClass('open_child_menu') ? jQuery(this).parent() : jQuery(this);
200		if ((!is_menu_main || jQuery('body').hasClass('responsive_menu')) && ($a.parent().hasClass('menu-item-has-children') || $a.parent().hasClass('has_children'))) {
201			if ($a.siblings('ul:visible').length > 0)
202				$a.siblings('ul').slideUp().parent().removeClass('opened');
203			else {
204				jQuery(this).parents('li').siblings('li').find('ul:visible').slideUp().parent().removeClass('opened');
205				$a.siblings('ul').slideDown().parent().addClass('opened');
206			}
207		}
208		// Ignore link for parent menu items
209//		if (jQuery(this).attr('href')=='#' || ((!is_menu_main || jQuery('body').hasClass('responsive_menu')) && jQuery(this).parent().hasClass('menu-item-has-children'))) {
210		if (jQuery(this).hasClass('open_child_menu') || $a.attr('href')=='#') {
211			e.preventDefault();
212			return false;
213		}
214	});
215	
216	// Init superfish menus
217	citygov_init_sfmenu('.menu_main_nav_area ul#menu_main, ul#menu_user, ul#menu_side, body:not(.woocommerce) .sidebar .widget_product_categories ul.product-categories');
218
219	// Slide effect for main menu
220	if (CITYGOV_STORAGE['menu_slider']) {
221		jQuery('#menu_main').spasticNav({
222			color: CITYGOV_STORAGE['accent2_color']
223		});
224	}
225
226	// Show table of contents for the current page
227	if (CITYGOV_STORAGE['toc_menu'] != 'no') {
228		citygov_build_page_toc();
229	}
230
231	// One page mode for menu links (scroll to anchor)
232	jQuery('#toc, ul#menu_main li, ul#menu_user li, ul#menu_side li, ul#menu_footer li, ul#menu_pushy li').on('click', 'a', function(e) {
233		"use strict";
234		var href = jQuery(this).attr('href');
235		if (href===undefined) return;
236		var pos = href.indexOf('#');
237		if (pos < 0 || href.length == 1) return;
238		if (jQuery(href.substr(pos)).length > 0) {
239			var loc = window.location.href;
240			var pos2 = loc.indexOf('#');
241			if (pos2 > 0) loc = loc.substring(0, pos2);
242			var now = pos==0;
243			if (!now) now = loc == href.substring(0, pos);
244			if (now) {
245				citygov_document_animate_to(href.substr(pos));
246				citygov_document_set_location(pos==0 ? loc + href : href);
247				e.preventDefault();
248				return false;
249			}
250		}
251	});
252	
253	
254	// Store height of the top and side panels
255	CITYGOV_STORAGE['top_panel_height'] = 0;	//Math.max(0, jQuery('.top_panel_wrap').height());
256	CITYGOV_STORAGE['side_panel_height'] = 0;
257
258
259	// Pagination
260    //----------------------------------------------
261
262	// Page navigation (style slider)
263	jQuery('.pager_cur').on('click', function(e) {
264		"use strict";
265		jQuery('.pager_slider').slideDown(300, function() {
266			citygov_init_shortcodes(jQuery('.pager_slider').eq(0));
267		});
268		e.preventDefault();
269		return false;
270	});
271
272
273	// View More button
274	jQuery('#viewmore_link').on('click', function(e) {
275		"use strict";
276		if (!CITYGOV_STORAGE['viewmore_busy'] && !jQuery(this).hasClass('viewmore_empty')) {
277			jQuery(this).parent().addClass('loading');
278			CITYGOV_STORAGE['viewmore_busy'] = true;
279			jQuery.post(CITYGOV_STORAGE['ajax_url'], {
280				action: 'view_more_posts',
281				nonce: CITYGOV_STORAGE['ajax_nonce'],
282				page: CITYGOV_STORAGE['viewmore_page']+1,
283				data: CITYGOV_STORAGE['viewmore_data'],
284				vars: CITYGOV_STORAGE['viewmore_vars']
285			}).done(function(response) {
286				"use strict";
287				var rez = {};
288				try {
289					rez = JSON.parse(response);
290				} catch (e) {
291					rez = { error: CITYGOV_STORAGE['ajax_error'] };
292					console.log(response);
293				}
294				jQuery('#viewmore_link').parent().removeClass('loading');
295				CITYGOV_STORAGE['viewmore_busy'] = false;
296				if (rez.error === '') {
297					var posts_container = jQuery('.content').eq(0);
298					if (posts_container.find('.isotope_wrap').length > 0) posts_container = posts_container.find('.isotope_wrap').eq(0);
299					if (posts_container.hasClass('isotope_wrap')) {
300						posts_container.data('last-width', 0).append(rez.data);
301						CITYGOV_STORAGE['isotope_init_counter'] = 0;
302						citygov_init_appended_isotope(posts_container, rez.filters);
303					} else
304						jQuery('#viewmore').before(rez.data);
305
306					CITYGOV_STORAGE['viewmore_page']++;
307					if (rez.no_more_data==1) {
308						jQuery('#viewmore_link').addClass('viewmore_empty').parent().hide();
309					}
310
311					citygov_init_post_formats();
312					citygov_init_shortcodes(posts_container);
313					citygov_scroll_actions();
314				}
315			});
316		}
317		e.preventDefault();
318		return false;
319	});
320
321
322	// WooCommerce
323    //----------------------------------------------
324
325	// Change display mode
326	jQuery('.woocommerce,.woocommerce-page').on('click', '.mode_buttons a', function(e) {
327		"use strict";
328		var mode = jQuery(this).hasClass('woocommerce_thumbs') ? 'thumbs' : 'list';
329		jQuery.cookie('citygov_shop_mode', mode, {expires: 365, path: '/'});
330		jQuery(this).siblings('input').val(mode).parents('form').get(0).submit();
331		e.preventDefault();
332		return false;
333	});
334	// Added to cart
335	jQuery('body').bind('added_to_cart', function() {
336		"use strict";
337		// Update amount on the cart button
338		var total = jQuery('.menu_user_cart .total .amount').text();
339		if (total != undefined) {
340			jQuery('.top_panel_cart_button .cart_summa').text(total);
341		}
342		// Update count items on the cart button
343		var cnt = 0;
344		jQuery('.menu_user_cart .cart_list li').each(function() {
345			var q = jQuery(this).find('.quantity').html().split(' ', 2);
346			if (!isNaN(q[0]))
347				cnt += Number(q[0]);
348		});
349		var items = jQuery('.top_panel_cart_button .cart_items').text().split(' ');
350		items[0] = cnt;
351		jQuery('.top_panel_cart_button .cart_items').text(items[0]+' '+items[1]);
352		// Update data-attr on button
353		jQuery('.top_panel_cart_button').data({
354			'items': cnt ? cnt : 0,
355			'summa': total ? total : 0
356		});
357	});
358	// Show cart 
359	jQuery('.top_panel_middle .top_panel_cart_button').on('click', function(e) {
360		"use strict";
361		jQuery(this).siblings('.sidebar_cart').slideToggle();
362		e.preventDefault();
363		return false;
364	});
365	// Add buttons to quantity
366	jQuery('.woocommerce div.quantity,.woocommerce-page div.quantity').append('<span class="q_inc"></span><span class="q_dec"></span>');
367	jQuery('.woocommerce div.quantity').on('click', '>span', function(e) {
368		"use strict";
369		var f = jQuery(this).siblings('input');
370		if (jQuery(this).hasClass('q_inc')) {
371			f.val(Math.max(0, parseInt(f.val()))+1);
372		} else {
373			f.val(Math.max(1, Math.max(0, parseInt(f.val()))-1));
374		}
375		e.preventDefault();
376		return false;
377	});
378	// Add stretch behaviour to WooC tabs area
379	jQuery('.single-product .woocommerce-tabs')
380		.addClass('trx-stretch-width scheme_light')
381		.after('<div class="trx-stretch-width-original"></div>');
382	citygov_stretch_width();
383
384	// Popup login and register windows
385    //----------------------------------------------
386	jQuery('.popup_link').addClass('inited').on('click', function(e){
387		var popup = jQuery(jQuery(this).attr('href'));
388		if (popup.length === 1) {
389			citygov_hide_popup(jQuery(popup.hasClass('popup_login') ? '.popup_registration' : '.popup_login' ));
390			citygov_toggle_popup(popup);
391		}
392		e.preventDefault();
393		return false;
394	});
395	jQuery('.popup_wrap').on('click', '.popup_close', function(e){
396		var popup = jQuery(this).parent();
397		if (popup.length === 1) {
398			citygov_hide_popup(popup);
399		}
400		e.preventDefault();
401		return false;
402	});
403
404
405	// Forms validation
406    //----------------------------------------------
407
408	// Login form
409	jQuery('.popup_form.login_form').submit(function(e){
410		"use strict";
411		var rez = citygov_login_validate(jQuery(this));
412		if (!rez)
413			e.preventDefault();
414		return rez;
415	});
416	
417	// Registration form
418	jQuery('.popup_form.registration_form').submit(function(e){
419		"use strict";
420		var rez = citygov_registration_validate(jQuery(this));
421		if (!rez)
422			e.preventDefault();
423		return rez;
424	});
425
426	// Comment form
427	jQuery("form#commentform").submit(function(e) {
428		"use strict";
429		var rez = citygov_comments_validate(jQuery(this));
430		if (!rez)
431			e.preventDefault();
432		return rez;
433	});
434
435
436
437	// Bookmarks
438    //----------------------------------------------
439
440	// Add bookmark
441	jQuery('.bookmarks_add').on('click', function(e) {
442		"use strict";
443		var title = window.document.title.split('|')[0];
444		var url = window.location.href;
445		var list = jQuery.cookie('citygov_bookmarks');
446		var exists = false;
447		if (list) {
448			try {
449				list = JSON.parse(list);
450			} catch (e) {}
451			if (list.length) {
452				for (var i=0; i<list.length; i++) {
453					if (list[i].url == url) {
454						exists = true;
455						break;
456					}
457				}
458			}
459		} else
460			list = new Array();
461		if (!exists) {
462			var message_popup = citygov_message_dialog('<label for="bookmark_title">'+CITYGOV_STORAGE['strings']['bookmark_title']+'</label><br><input type="text" id="bookmark_title" name="bookmark_title" value="'+title+'">', CITYGOV_STORAGE['strings']['bookmark_add'], null,
463				function(btn, popup) {
464					"use strict";
465					if (btn != 1) return;
466					title = message_popup.find('#bookmark_title').val();
467					list.push({title: title, url: url});
468					jQuery('.bookmarks_list').append('<li><a href="'+url+'" class="bookmarks_item">'+title+'<span class="bookmarks_delete icon-cancel" title="'+CITYGOV_STORAGE['strings']['bookmark_del']+'"></span></a></li>');
469					jQuery.cookie('citygov_bookmarks', JSON.stringify(list), {expires: 365, path: '/'});
470					setTimeout(function () {citygov_message_success(CITYGOV_STORAGE['strings']['bookmark_added'], CITYGOV_STORAGE['strings']['bookmark_add']);}, CITYGOV_STORAGE['message_timeout']/4);
471				});
472		} else
473			citygov_message_warning(CITYGOV_STORAGE['strings']['bookmark_exists'], CITYGOV_STORAGE['strings']['bookmark_add']);
474		e.preventDefault();
475		return false;
476	});
477
478	// Delete bookmark
479	jQuery('.bookmarks_list').on('click', '.bookmarks_delete', function(e) {
480		"use strict";
481		var idx = jQuery(this).parent().index();
482		var list = jQuery.cookie('citygov_bookmarks');
483		if (list) {
484			try {
485				list = JSON.parse(list);
486			} catch (e) {}
487			if (list.length) {
488				list.splice(idx, 1);
489				jQuery.cookie('citygov_bookmarks', JSON.stringify(list), {expires: 365, path: '/'});
490			}
491		}
492		jQuery(this).parent().remove();
493		e.preventDefault();
494		return false;
495	});
496
497
498
499	// Other settings
500    //------------------------------------
501
502	// Scroll to top button
503	jQuery('.scroll_to_top').on('click', function(e) {
504		"use strict";
505		jQuery('html,body').animate({
506			scrollTop: 0
507		}, 'slow');
508		e.preventDefault();
509		return false;
510	});
511
512    // Show system message
513	citygov_show_system_message();
514
515	// Init post format specific scripts
516	citygov_init_post_formats();
517
518	// Init shortcodes scripts
519	citygov_init_shortcodes(jQuery('body').eq(0));
520
521	// Init hidden elements (if exists)
522	if (window.citygov_init_hidden_elements) citygov_init_hidden_elements(jQuery('body').eq(0));
523	
524} //end ready
525
526
527
528
529// Scroll actions
530//==============================================
531
532// Do actions when page scrolled
533function citygov_scroll_actions() {
534	"use strict";
535
536	// Call skin specific action (if exists)
537    //----------------------------------------------
538	if (window.citygov_skin_scroll_actions) citygov_skin_scroll_actions();
539
540	// Call theme specific action (if exists)
541    //----------------------------------------------
542	if (window.citygov_theme_scroll_actions) citygov_theme_scroll_actions();
543
544	var scroll_offset = jQuery(window).scrollTop();
545	var scroll_to_top_button = jQuery('.scroll_to_top');
546	var adminbar_height = Math.max(0, jQuery('#wpadminbar').height());
547
548	if (CITYGOV_STORAGE['top_panel_height'] == 0)	CITYGOV_STORAGE['top_panel_height'] = jQuery('.top_panel_wrap').height();
549
550	// Scroll to top button show/hide
551	if (scroll_offset > CITYGOV_STORAGE['top_panel_height'])
552		scroll_to_top_button.addClass('show');
553	else
554		scroll_to_top_button.removeClass('show');
555	
556	// Fix/unfix top panel
557	if (!jQuery('body').hasClass('responsive_menu') && CITYGOV_STORAGE['menu_fixed']) {
558		var slider_height = 0;
559		if (jQuery('.top_panel_below .slider_wrap').length > 0) {
560			slider_height = jQuery('.top_panel_below .slider_wrap').height();
561			if (slider_height < 10) {
562				slider_height = jQuery('.slider_wrap').hasClass('.slider_fullscreen') ? jQuery(window).height() : CITYGOV_STORAGE['slider_height'];
563			}
564		}
565		if (scroll_offset <= slider_height + CITYGOV_STORAGE['top_panel_height']) {
566			if (jQuery('body').hasClass('top_panel_fixed')) {
567				jQuery('body').removeClass('top_panel_fixed');
568			}
569		} else if (scroll_offset > slider_height + CITYGOV_STORAGE['top_panel_height']) {
570			if (!jQuery('body').hasClass('top_panel_fixed') && jQuery(document).height() > jQuery(window).height()*1.5) {
571				jQuery('.top_panel_fixed_wrap').height(CITYGOV_STORAGE['top_panel_height']);
572				jQuery('.top_panel_wrap').css('marginTop', '-150px').animate({'marginTop': 0}, 500);
573				jQuery('body').addClass('top_panel_fixed');
574			}
575		}
576	}
577	
578	// Fix/unfix side panel
579	if (jQuery('.sidebar_outer').length > 0) {
580		if (CITYGOV_STORAGE['side_panel_height'] == 0)	
581			CITYGOV_STORAGE['side_panel_height'] = jQuery('.sidebar_outer_logo_wrap').outerHeight() + jQuery('.sidebar_outer_menu').outerHeight() + jQuery('.sidebar_outer_widgets').outerHeight();
582		if (scroll_offset + jQuery(window).height() > CITYGOV_STORAGE['side_panel_height'] + 100) {
583			if (jQuery('.sidebar_outer').css('position')!=='fixed') {
584				jQuery('.sidebar_outer').css({
585					//'top': (scroll_offset + jQuery(window).height() - CITYGOV_STORAGE['side_panel_height'] - 100) + 'px'
586					'position': 'fixed',
587					'top': Math.min(0, jQuery(window).height() - CITYGOV_STORAGE['side_panel_height'] - 100) + 'px',
588				});
589			}
590		} else {
591			if (jQuery('.sidebar_outer').css('position')=='fixed') {
592				jQuery('.sidebar_outer').css({
593					'position': 'absolute',
594					'top': 0
595				});
596			}
597		}
598	}
599
600	// TOC current items
601	jQuery('#toc .toc_item').each(function() {
602		"use strict";
603		var id = jQuery(this).find('a').attr('href');
604		var pos = id.indexOf('#');
605		if (pos < 0 || id.length == 1) return;
606		var loc = window.location.href;
607		var pos2 = loc.indexOf('#');
608		if (pos2 > 0) loc = loc.substring(0, pos2);
609		var now = pos==0;
610		if (!now) now = loc == href.substring(0, pos);
611		if (!now) return;
612		var off = jQuery(id).offset().top;
613		var id_next  = jQuery(this).next().find('a').attr('href');
614		var off_next = id_next ? jQuery(id_next).offset().top : 1000000;
615		if (off < scroll_offset + jQuery(window).height()*0.8 && scroll_offset + CITYGOV_STORAGE['top_panel_height'] < off_next)
616			jQuery(this).addClass('current');
617		else
618			jQuery(this).removeClass('current');
619	});
620	
621	// Infinite pagination
622	citygov_infinite_scroll()
623	
624	// Parallax scroll
625	citygov_parallax_scroll();
626	
627	// Scroll actions for shortcodes
628	citygov_animation_shortcodes();
629}
630
631
632// Infinite Scroll
633function citygov_infinite_scroll() {
634	"use strict";
635	if (CITYGOV_STORAGE['viewmore_busy']) return;
636	var infinite = jQuery('#viewmore.pagination_infinite');
637	if (infinite.length > 0) {
638		var viewmore = infinite.find('#viewmore_link:not(.viewmore_empty)');
639		if (viewmore.length > 0) {
640			if (jQuery(window).scrollTop() + jQuery(window).height() + 100 >= infinite.offset().top) {
641				viewmore.eq(0).trigger('click');
642			}
643		}
644	}
645}
646
647// Parallax scroll
648function citygov_parallax_scroll(){
649	jQuery('.sc_parallax').each(function(){
650		var windowHeight = jQuery(window).height();
651		var scrollTops = jQuery(window).scrollTop();
652		var offsetPrx = Math.max(jQuery(this).offset().top, windowHeight);
653		if ( offsetPrx <= scrollTops + windowHeight ) {
654			var speed  = Number(jQuery(this).data('parallax-speed'));
655			var xpos   = jQuery(this).data('parallax-x-pos');  
656			var ypos   = Math.round((offsetPrx - scrollTops - windowHeight) * speed + (speed < 0 ? windowHeight*speed : 0));
657			jQuery(this).find('.sc_parallax_content').css('backgroundPosition', xpos+' '+ypos+'px');
658			// Uncomment next line if you want parallax video (else - video position is static)
659			jQuery(this).find('div.sc_video_bg').css('top', ypos+'px');
660		} 
661	});
662}
663
664
665
666
667
668// Resize actions
669//==============================================
670
671// Do actions when page scrolled
672function citygov_resize_actions() {
673	"use strict";
674
675	// Call skin specific action (if exists)
676    //----------------------------------------------
677	if (window.citygov_skin_resize_actions) citygov_skin_resize_actions();
678
679	// Call theme specific action (if exists)
680    //----------------------------------------------
681	if (window.citygov_theme_resize_actions) citygov_theme_resize_actions();
682
683	citygov_responsive_menu();
684	citygov_video_dimensions();
685	citygov_resize_video_background();
686	citygov_resize_fullscreen_slider();
687	citygov_resize_alter_portfolio();
688	citygov_stretch_width();
689}
690
691// Stretch area to full window width
692function citygov_stretch_width() {
693	jQuery('.trx-stretch-width').each(function() {
694		var $el = jQuery(this);
695		var $el_full = $el.next('.trx-stretch-width-original');
696		var el_margin_left = parseInt( $el.css( 'margin-left' ), 10 );
697		var el_margin_right = parseInt( $el.css( 'margin-right' ), 10 );
698		var offset = 0 - $el_full.offset().left - el_margin_left;
699		var width = jQuery( window ).width();
700		if (!$el.hasClass('inited')) {
701			$el.addClass('inited invisible');
702			$el.css({
703				'position': 'relative',
704				'box-sizing': 'border-box'
705			});
706		}
707		$el.css({
708			'left': offset,
709			'width': jQuery( window ).width()
710		});
711		if ( !$el.hasClass('trx-stretch-content') ) {
712			var padding = Math.max(0, -1*offset);
713			var paddingRight = Math.max(0, width - padding - $el_full.width() + el_margin_left + el_margin_right);
714			$el.css( { 'padding-left': padding + 'px', 'padding-right': paddingRight + 'px' } );
715		}
716		$el.removeClass('invisible');
717	});
718}
719
720// Check window size and do responsive menu
721function citygov_responsive_menu() {
722	if (citygov_is_responsive_need(CITYGOV_STORAGE['menu_responsive'])) {
723		if (!jQuery('body').hasClass('responsive_menu')) {
724			jQuery('body').removeClass('top_panel_fixed').addClass('responsive_menu');
725			if (jQuery('body').hasClass('menu_relayout'))
726				jQuery('body').removeClass('menu_relayout');
727			if (jQuery('ul.menu_main_nav').hasClass('inited')) {
728				jQuery('ul.menu_main_nav').removeClass('inited').superfish('destroy');
729			}
730			if (jQuery('ul.menu_side_nav').hasClass('inited')) {
731				jQuery('ul.menu_side_nav').removeClass('inited').superfish('destroy');
732			}
733		}
734	} else {
735		if (jQuery('body').hasClass('responsive_menu')) {
736			jQuery('body').removeClass('responsive_menu');
737			jQuery('.menu_main_responsive').hide();
738			jQuery('.menu_side_responsive').hide();
739			citygov_init_sfmenu('ul.menu_main_nav,ul.menu_side_nav');
740			jQuery('.menu_main_nav_area').show();
741		}
742		if (citygov_is_responsive_need(CITYGOV_STORAGE['menu_relayout']))
743			jQuery('body').addClass('menu_relayout');
744		else if (jQuery('body').hasClass('menu_relayout'))
745			jQuery('body').removeClass('menu_relayout');
746	}
747	if (!jQuery('.top_panel_wrap').hasClass('menu_show')) jQuery('.top_panel_wrap').addClass('menu_show');
748	// Show widgets block on the sidebar outer (if sidebar not responsive and widgets are hidden)
749	if (jQuery('.sidebar_outer').length > 0 && jQuery('.sidebar_outer').css('position')=='absolute' && jQuery('.sidebar_outer_widgets:visible').length==0) 
750		jQuery('.sidebar_outer_widgets').show();
751	// Switch popup menu / hierarchical list on product categories list
752	var sb = jQuery('body:not(.woocommerce) .sidebar');
753	var cat_menu = jQuery('body:not(.woocommerce) .sidebar .widget_product_categories ul.product-categories');
754	if (sb.length > 0 && cat_menu.length > 0) {
755		if (sb.css('float')=='none') {
756			if (cat_menu.hasClass('inited')) {
757				cat_menu.removeClass('inited').addClass('plain').superfish('destroy');
758				cat_menu.find('ul.animated').removeClass('animated').addClass('no_animated');
759			}
760		} else {
761			if (!cat_menu.hasClass('inited')) {
762				cat_menu.removeClass('plain').addClass('inited');
763				cat_menu.find('ul.no_animated').removeClass('no_animated').addClass('animated');
764				citygov_init_sfmenu('body:not(.woocommerce) .sidebar .widget_product_categories ul.product-categories');
765			}
766		}
767	}
768}
769
770
771// Check if responsive menu need
772function citygov_is_responsive_need(max_width) {
773	"use strict";
774	var rez = false;
775	if (max_width > 0) {
776		var w = window.innerWidth;
777		if (w == undefined) {
778			w = jQuery(window).width()+(jQuery(window).height() < jQuery(document).height() || jQuery(window).scrollTop() > 0 ? 16 : 0);
779		}
780		rez = max_width > w;
781	}
782	return rez;
783}
784
785
786// Fit video frames to document width
787function citygov_video_dimensions() {
788	jQuery('.sc_video_frame').each(function() {
789		"use strict";
790		var frame  = jQuery(this).eq(0);
791		var player = frame.parent();
792		var ratio = (frame.data('ratio') ? frame.data('ratio').split(':') : (frame.find('[data-ratio]').length>0 ? frame.find('[data-ratio]').data('ratio').split(':') : [16,9]));
793		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
794		var w_attr = frame.data('width');
795		var h_attr = frame.data('height');
796		if (!w_attr || !h_attr) return;
797		var percent = (''+w_attr).substr(-1)=='%';
798		w_attr = parseInt(w_attr);
799		h_attr = parseInt(h_attr);
800		var w_real = Math.min(percent || frame.parents('.columns_wrap').length>0 ? 10000 : w_attr, frame.parents('div,article').width()), //player.width();
801			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
802		if (parseInt(frame.attr('data-last-width'))==w_real) return;
803		if (percent) {
804			frame.height(h_real);
805		} else {
806			frame.css({'width': w_real+'px', 'height': h_real+'px'});
807		}
808		frame.attr('data-last-width', w_real);
809	});
810	jQuery('video.sc_video,video.wp-video-shortcode').each(function() {
811		"use strict";
812		var video = jQuery(this).eq(0);
813		var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
814		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
815		var mejs_cont = video.parents('.mejs-video');
816		var frame = video.parents('.sc_video_frame');
817		var w_attr = frame.length>0 ? frame.data('width') : video.data('width');
818		var h_attr = frame.length>0 ? frame.data('height') : video.data('height');
819		if (!w_attr || !h_attr) {
820			w_attr = video.attr('width');
821			h_attr = video.attr('height');
822			if (!w_attr || !h_attr) return;
823			video.data({'width': w_attr, 'height': h_attr});
824		}
825		var percent = (''+w_attr).substr(-1)=='%';
826		w_attr = parseInt(w_attr);
827		h_attr = parseInt(h_attr);
828		var w_real = Math.round(mejs_cont.length > 0 ? Math.min(percent ? 10000 : w_attr, mejs_cont.parents('div,article').width()) : video.width()),
829			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
830		if (parseInt(video.attr('data-last-width'))==w_real) return;
831		if (mejs_cont.length > 0 && mejs) {
832			citygov_set_mejs_player_dimensions(video, w_real, h_real);
833		}
834		if (percent) {
835			video.height(h_real);
836		} else {
837			video.attr({'width': w_real, 'height': h_real}).css({'width': w_real+'px', 'height': h_real+'px'});
838		}
839		video.attr('data-last-width', w_real);
840	});
841	jQuery('video.sc_video_bg').each(function() {
842		"use strict";
843		var video = jQuery(this).eq(0);
844		var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
845		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
846		var mejs_cont = video.parents('.mejs-video');
847		var container = mejs_cont.length>0 ? mejs_cont.parent() : video.parent();
848		var w = container.width();
849		var h = container.height();
850		var w1 = Math.ceil(h*ratio);
851		var h1 = Math.ceil(w/ratio);
852		if (video.parents('.sc_parallax').length > 0) {
853			var windowHeight = jQuery(window).height();
854			var speed = Number(video.parents('.sc_parallax').data('parallax-speed'));
855			var h_add = Math.ceil(Math.abs((windowHeight-h)*speed));
856			if (h1 < h + h_add) {
857				h1 = h + h_add;
858				w1 = Math.ceil(h1 * ratio);
859			}
860		}
861		if (h1 < h) {
862			h1 = h;
863			w1 = Math.ceil(h1 * ratio);
864		}
865		if (w1 < w) { 
866			w1 = w;
867			h1 = Math.ceil(w1 / ratio);
868		}
869		var l = Math.round((w1-w)/2);
870		var t = Math.round((h1-h)/2);
871		if (parseInt(video.attr('data-last-width'))==w1) return;
872		if (mejs_cont.length > 0) {
873			citygov_set_mejs_player_dimensions(video, w1, h1);
874			mejs_cont.css({
875				//'left': -l+'px',
876				'top': -t+'px'
877			});
878		} else
879			video.css({
880				//'left': -l+'px',
881				'top': -t+'px'
882			});
883		video.attr({'width': w1, 'height': h1, 'data-last-width':w1}).css({'width':w1+'px', 'height':h1+'px'});
884		if (video.css('opacity')==0) video.animate({'opacity': 1}, 3000);
885	});
886	jQuery('iframe').each(function() {
887		"use strict";
888		var iframe = jQuery(this).eq(0);
889		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]));
890		ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
891		var w_attr = iframe.attr('width');
892		var h_attr = iframe.attr('height');
893		var frame = iframe.parents('.sc_video_frame');
894		if (frame.length > 0) {
895			w_attr = frame.data('width');
896			h_attr = frame.data('height');
897		}
898		if (!w_attr || !h_attr) {
899			return;
900		}
901		var percent = (''+w_attr).substr(-1)=='%';
902		w_attr = parseInt(w_attr);
903		h_attr = parseInt(h_attr);
904		var w_real = frame.length > 0 ? frame.width() : iframe.width(),
905			h_real = Math.round(percent ? w_real/ratio : w_real/w_attr*h_attr);
906		if (parseInt(iframe.attr('data-last-width'))==w_real) return;
907		iframe.css({'width': w_real+'px', 'height': h_real+'px'});
908	});
909}
910
911// Resize fullscreen video background
912function citygov_resize_video_background() {
913	"use strict";
914	var bg = jQuery('.video_bg');
915	if (bg.length < 1) 
916		return;
917	if (CITYGOV_STORAGE['media_elements_enabled'] && bg.find('.mejs-video').length == 0)  {
918		setTimeout(citygov_resize_video_background, 100);
919		return;
920	}
921	var video = bg.find('video');
922	var ratio = (video.data('ratio')!=undefined ? video.data('ratio').split(':') : [16,9]);
923	ratio = ratio.length!=2 || ratio[0]==0 || ratio[1]==0 ? 16/9 : ratio[0]/ratio[1];
924	var w = bg.width();
925	var h = bg.height();
926	var w1 = Math.ceil(h*ratio);
927	var h1 = Math.ceil(w/ratio);
928	if (h1 < h) {
929		h1 = h;
930		w1 = Math.ceil(h1 * ratio);
931	}
932	if (w1 < w) { 
933		w1 = w;
934		h1 = Math.ceil(w1 / ratio);
935	}
936	var l = Math.round((w1-w)/2);
937	var t = Math.round((h1-h)/2);
938	if (bg.find('.mejs-container').length > 0) {
939		citygov_set_mejs_player_dimensions(bg.find('video'), w1, h1);
940		bg.find('.mejs-container').css({'left': -l+'px', 'top': -t+'px'});
941	} else
942		bg.find('video').css({'left': -l+'px', 'top': -t+'px'});
943	bg.find('video').attr({'width': w1, 'height': h1}).css({'width':w1+'px', 'height':h1+'px'});
944}
945
946// Set Media Elements player dimensions
947function citygov_set_mejs_player_dimensions(video, w, h) {
948	"use strict";
949	if (mejs) {
950		for (var pl in mejs.players) {
951			if (mejs.players[pl].media.src == video.attr('src')) {
952				if (mejs.players[pl].media.setVideoSize) {
953					mejs.players[pl].media.setVideoSize(w, h);
954				}
955				mejs.players[pl].setPlayerSize(w, h);
956				mejs.players[pl].setControlsSize();
957				//var mejs_cont = video.parents('.mejs-video');
958				//mejs_cont.css({'width': w+'px', 'height': h+'px'}).find('.mejs-layers > div, .mejs-overlay, .mejs-poster').css({'width': w, 'height': h});
959			}
960		}
961	}
962}
963
964// Resize Fullscreen Slider
965function citygov_resize_fullscreen_slider() {
966	"use strict";
967	var slider_wrap = jQuery('.slider_wrap.slider_fullscreen');
968	if (slider_wrap.length < 1) 
969		return;
970	var slider = slider_wrap.find('.sc_slider_swiper');
971	if (slider.length < 1) 
972		return;
973	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);
974	slider.height(h);
975}
976
977// Resize Alter portfolio elements
978function citygov_resize_alter_portfolio() {
979	"use strict";
980	var wrap = jQuery('.isotope_wrap.inited');
981	if (wrap.length==0) return;
982	wrap.each(function() {
983		"use strict";
984		var alter = jQuery(this).find('.post_item_alter');
985		if (alter.length==0) return;
986		var single = alter.find('.post_featured img[data-alter-items-w="1"]').eq(0);
987		if (single.length != 1) return;
988		var w_real = single.width();
989		var h_real = single.height();
990		var space = Number(single.data('alter-item-space'));
991		var relayout = false;
992		alter.find('.post_featured img').each(function() {
993			"use strict";
994			var items_w = Number(jQuery(this).data('alter-items-w'));
995			var items_h = Number(jQuery(this).data('alter-items-h'));
996			if (items_h > 1) {
997				jQuery(this).height(Math.round(items_h*h_real+(items_h-1)*(space+1)));
998				relayout = true;
999			} else if (items_w > 1) {
1000				jQuery(this).height(h_real);
1001				relayout = true;
1002			}
1003		});
1004		if (relayout) {
1005			jQuery(this).isotope('layout');
1006		}
1007	});
1008}
1009
1010
1011
1012
1013
1014// Navigation
1015//==============================================
1016
1017// Init Superfish menu
1018function citygov_init_sfmenu(selector) {
1019	jQuery(selector).show().each(function() {
1020		if (citygov_is_responsive_need() && (jQuery(this).attr('id')=='menu_main' || jQuery(this).attr('id')=='menu_side')) return;
1021		jQuery(this).addClass('inited').superfish({
1022			delay: 500,
1023			animation: {
1024				opacity: 'show'
1025			},
1026			animationOut: {
1027				opacity: 'hide'
1028			},
1029			speed: 		CITYGOV_STORAGE['css_animation'] ? 500 : (CITYGOV_STORAGE['menu_slider'] ? 300 : 200),
1030			speedOut:	CITYGOV_STORAGE['css_animation'] ? 500 : (CITYGOV_STORAGE['menu_slider'] ? 300 : 200),
1031			autoArrows: false,
1032			dropShadows: false,
1033			onBeforeShow: function(ul) {
1034				if (jQuery(this).parents("ul").length > 1){
1035					var w = jQuery(window).width();  
1036					var par_offset = jQuery(this).parents("ul").offset().left;
1037					var par_width  = jQuery(this).parents("ul").outerWidth();
1038					var ul_width   = jQuery(this).outerWidth();
1039					if (par_offset+par_width+ul_width > w-20 && par_offset-ul_width > 0)
1040						jQuery(this).addClass('submenu_left');
1041					else
1042						jQuery(this).removeClass('submenu_left');
1043				}
1044				if (CITYGOV_STORAGE['css_animation']) {
1045					jQuery(this).removeClass('animated fast '+CITYGOV_STORAGE['menu_animation_out']);
1046					jQuery(this).addClass('animated fast '+CITYGOV_STORAGE['menu_animation_in']);
1047				}
1048			},
1049			onBeforeHide: function(ul) {
1050				if (CITYGOV_STORAGE['css_animation']) {
1051					jQuery(this).removeClass('animated fast '+CITYGOV_STORAGE['menu_animation_in']);
1052					jQuery(this).addClass('animated fast '+CITYGOV_STORAGE['menu_animation_out']);
1053				}
1054			}
1055		});
1056	});
1057}
1058
1059
1060// Build page TOC from the tag's id
1061function citygov_build_page_toc() {
1062	"use strict";
1063	var toc = '', toc_count = 0;
1064	jQuery('[id^="toc_"],.sc_anchor').each(function(idx) {
1065		"use strict";
1066		var obj = jQuery(this);
1067		var id = obj.attr('id');
1068		var url = obj.data('url');
1069		var icon = obj.data('icon');
1070		if (!icon) icon = 'icon-circle-dot';
1071		var title = obj.attr('title');
1072		var description = obj.data('description');
1073		var separator = obj.data('separator');
1074		toc_count++;
1075		toc += '<div class="toc_item'+(separator=='yes' ? ' toc_separator' : '')+'">'
1076			+(description ? '<div class="toc_description">'+description+'</div>' : '')
1077			+'<a href="'+(url ? url : '#'+id)+'" class="toc_icon'+(title ? ' with_title' : '')+' '+icon+'">'+(title ? '<span class="toc_title">'+title+'</span>' : '')+'</a>'
1078			+'</div>';
1079	});
1080	if (toc_count > (CITYGOV_STORAGE['toc_menu_home'] ? 1 : 0) + (CITYGOV_STORAGE['toc_menu_top'] ? 1 : 0)) {
1081		if (jQuery('#toc').length > 0)
1082			jQuery('#toc .toc_inner').html(toc);
1083		else
1084			jQuery('body').append('<div id="toc" class="toc_'+CITYGOV_STORAGE['toc_menu']+'"><div class="toc_inner">'+toc+'</div></div>');
1085	}
1086}
1087
1088
1089// Show current page title on the responsive menu button
1090function citygov_show_current_menu_item(menu, button) {
1091	"use strict";
1092	menu.find('a').each(function () {
1093		var menu_link = jQuery(this);
1094		if (menu_link.text() == "") {
1095			return;
1096		}
1097		if (menu_link.attr('href') == window.location.href)
1098			button.text(menu_link.text());
1099	});
1100}
1101
1102
1103// Prepare menus (if menu cache is used)
1104function citygov_prepare_menus() {
1105	"use strict";
1106	var menus = [
1107		jQuery('ul#menu_main'),
1108		jQuery('ul#menu_user'),
1109		jQuery('ul#menu_side'),
1110		jQuery('ul#menu_footer'),
1111		jQuery('ul#menu_pushy')
1112	];
1113	var href = window.location.href;
1114	for (var m in menus) {
1115		if (menus[m].length==0) continue;
1116		menus[m].find('li').removeClass('current-menu-ancestor current-menu-parent current-menu-item current_page_item');
1117		menus[m].find('a[href="'+href+'"]').each(function(idx) {
1118			var li = jQuery(this).parent();
1119			li.addClass('current-menu-item');
1120			if (li.hasClass('menu-item-object-page')) li.addClass('current_page_item');
1121			var cnt = 0;
1122			while ((li = li.parents('li')).length > 0) {
1123				cnt++;
1124				li.addClass('current-menu-ancestor'+(cnt==1 ? ' current-menu-parent' : ''));
1125			}
1126		});
1127	}
1128}
1129
1130jQuery(document).ready(function() {
1131
1132
1133    // Inject our code in the VC function wpb_prepare_tab_content()
1134    // to init our elements on the new VC tabs, tour and accordion activation
1135    typeof window.wpb_prepare_tab_content == "function"
1136    && typeof window.wpb_prepare_tab_content_old == "undefined"
1137    && (window.wpb_prepare_tab_content_old = window.wpb_prepare_tab_content)
1138    && (window.wpb_prepare_tab_content = function(e, ui) {
1139        // Call ThemeREX Addons actions
1140        if (typeof ui.newPanel !== 'undefined' && ui.newPanel.length > 0) {
1141            citygov_sc_init(ui.newPanel);
1142            if (window.citygov_init_hidden_elements) citygov_init_hidden_elements(ui.newPanel);
1143            citygov_init_isotope();
1144        } else if (typeof ui.panel !== 'undefined' && ui.panel.length > 0) {
1145            citygov_sc_init(ui.newPanel);
1146            if (window.citygov_init_hidden_elements) citygov_init_hidden_elements(ui.newPanel);
1147            citygov_init_isotope();
1148        }
1149        // Call old VC handler
1150        window.wpb_prepare_tab_content_old(e, ui);
1151    });
1152    // Inject our code in the VC function vc_accordionActivate()
1153    // to init our elements on the old VC accordion activation
1154    typeof window.vc_accordionActivate == "function"
1155    && typeof window.vc_accordionActivate_old == "undefined"
1156    && (window.vc_accordionActivate_old = window.vc_accordionActivate)
1157    && (window.vc_accordionActivate = function(e, ui) {
1158        // Call ThemeREX Addons actions
1159        if (typeof ui.newPanel !== 'undefined' && ui.newPanel.length > 0) {
1160            citygov_sc_init(ui.newPanel);
1161            if (window.citygov_init_hidden_elements) citygov_init_hidden_elements(ui.newPanel);
1162            citygov_init_isotope();
1163        } else if (typeof ui.panel !== 'undefined' && ui.panel.length > 0) {
1164            citygov_sc_init(ui.panel);
1165            if (window.citygov_init_hidden_elements) citygov_init_hidden_elements(ui.panel);
1166            citygov_init_isotope();
1167        }
1168        // Call old VC handler
1169        window.vc_accordionActivate_old(e, ui);
1170    });
1171
1172
1173});
1174
1175// Isotope
1176//=====================================================
1177
1178// First init isotope containers
1179function citygov_init_isotope() {
1180	"use strict";
1181
1182	var all_images_complete = true;
1183
1184	// Check if all images in isotope wrapper are loaded
1185	jQuery('.isotope_wrap:not(.inited)').each(function () {
1186		"use strict";
1187		all_images_complete = all_images_complete && citygov_check_images_complete(jQuery(this));
1188	});
1189	// Wait for images loading
1190	if (!all_images_complete && CITYGOV_STORAGE['isotope_init_counter']++ < 30) {
1191		setTimeout(citygov_init_isotope, 200);
1192		return;
1193	}
1194
1195	// Isotope filters handler
1196	jQuery('.isotope_filters:not(.inited)').addClass('inited').on('click', 'a', function(e) {
1197		"use strict";
1198		jQuery(this).parents('.isotope_filters').find('a').removeClass('active');
1199		jQuery(this).addClass('active');
1200	
1201		var selector = jQuery(this).data('filter');
1202		jQuery(this).parents('.isotope_filters').siblings('.isotope_wrap').eq(0).isotope({
1203			filter: selector
1204		});
1205
1206		if (selector == '*')
1207			jQuery('#viewmore_link').fadeIn();
1208		else
1209			jQuery('#viewmore_link').fadeOut();
1210
1211		e.preventDefault();
1212		return false;
1213	});
1214
1215	// Init isotope script
1216	jQuery('.isotope_wrap:not(.inited)').each(function() {
1217		"use strict";
1218
1219		var isotope_container = jQuery(this);
1220
1221		// Init shortcodes
1222		citygov_init_shortcodes(isotope_container);
1223
1224		// If in scroll container - no init isotope
1225		if (isotope_container.parents('.sc_scroll').length > 0) {
1226			isotope_container.addClass('inited').find('.isotope_item').animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); });
1227			return;
1228		}
1229
1230        if (jQuery(this).parents('div:hidden,article:hidden').length > 0) return;
1231
1232        // Init isotope with timeout
1233		setTimeout(function() {
1234			isotope_container.addClass('inited').isotope({
1235				itemSelector: '.isotope_item',
1236				animationOptions: {
1237					duration: 750,
1238					easing: 'linear',
1239					queue: false
1240				}
1241			});
1242
1243			// Show elements
1244			isotope_container.find('.isotope_item').animate({opacity: 1}, 200, function () {
1245				jQuery(this).addClass('isotope_item_show');
1246			});
1247
1248			// Resize Alter portfolio elements
1249			citygov_resize_alter_portfolio();
1250
1251		}, 500);
1252
1253	});
1254}
1255
1256function citygov_init_appended_isotope(posts_container, filters) {
1257	"use strict";
1258	
1259	if (posts_container.parents('.sc_scroll_horizontal').length > 0) return;
1260	
1261	if (!citygov_check_images_complete(posts_container) && CITYGOV_STORAGE['isotope_init_counter']++ < 30) {
1262		setTimeout(function() { citygov_init_appended_isotope(posts_container, filters); }, 200);
1263		return;
1264	}
1265	// Add filters
1266	var flt = posts_container.siblings('.isotope_filter');
1267	for (var i in filters) {
1268		if (flt.find('a[data-filter=".flt_'+i+'"]').length == 0) {
1269			flt.append('<a href="#" class="isotope_filters_button" data-filter=".flt_'+i+'">'+filters[i]+'</a>');
1270		}
1271	}
1272	// Init shortcodes in added elements
1273	citygov_init_shortcodes(posts_container);
1274	// Get added elements
1275	var elems = posts_container.find('.isotope_item:not(.isotope_item_show)');
1276	// Notify isotope about added elements with timeout
1277	setTimeout(function() {
1278		posts_container.isotope('appended', elems);
1279		// Show appended elements
1280		elems.animate({opacity: 1}, 200, function () { jQuery(this).addClass('isotope_item_show'); });
1281	}, 500);
1282}
1283
1284
1285
1286// Shortcodes init
1287//=====================================================
1288
1289function citygov_init_shortcodes(cont) {
1290	"use strict";
1291
1292	// Call theme specific action (if exists)
1293	if (window.citygov_theme_sc_init) citygov_theme_sc_init(cont);
1294
1295	// Call core shortcodes action (if exists)
1296	if (window.citygov_sc_init) citygov_sc_init(cont);
1297}
1298
1299function citygov_animation_shortcodes() {
1300	"use strict";
1301	if (window.citygov_sc_animation) citygov_sc_animation();
1302}
1303
1304
1305
1306// Post formats init
1307//=====================================================
1308
1309function citygov_init_post_formats() {
1310	"use strict";
1311
1312	// Call theme specific action (if exists)
1313	if (window.citygov_theme_init_post_formats) citygov_theme_init_post_formats();
1314
1315	// MediaElement init
1316	citygov_init_media_elements(jQuery('body'));
1317	
1318	// Isotope first init
1319	if (jQuery('.isotope_wrap:not(.inited)').length > 0) {
1320		CITYGOV_STORAGE['isotope_init_counter'] = 0;
1321		citygov_init_isotope();
1322	}
1323
1324	// Hover Effect 'Dir'
1325	if (jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').length > 0) {
1326		jQuery('.isotope_wrap .isotope_item_content.square.effect_dir:not(.inited)').each(function() {
1327			jQuery(this).addClass('inited').hoverdir();
1328		});
1329	}
1330
1331	// Popup init
1332	if (CITYGOV_STORAGE['popup_engine'] == 'pretty') {
1333		jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'prettyPhoto[slideshow]');
1334		var images = jQuery("a[rel*='prettyPhoto']:not(.inited):not(.esgbox):not([data-rel*='pretty']):not([rel*='magnific']):not([data-rel*='magnific'])").addClass('inited');
1335		try {
1336			images.prettyPhoto({
1337				social_tools: '',
1338				theme: 'facebook',
1339				deeplinking: false
1340			});
1341		} catch (e) {};
1342	} else if (CITYGOV_STORAGE['popup_engine']=='magnific') {
1343		jQuery("a[href$='jpg'],a[href$='jpeg'],a[href$='png'],a[href$='gif']").attr('rel', 'magnific');
1344		var images = jQuery("a[rel*='magnific']:not(.inited):not(.esgbox):not(.prettyphoto):not([rel*='pretty']):not([data-rel*='pretty'])").addClass('inited');
1345		try {
1346			images.magnificPopup({
1347				type: 'image',
1348				mainClass: 'mfp-img-mobile',
1349				closeOnContentClick: true,
1350				closeBtnInside: true,
1351				fixedContentPos: true,
1352				midClick: true,
1353				//removalDelay: 500, 
1354				preloader: true,
1355				tLoading: CITYGOV_STORAGE['strings']['magnific_loading'],
1356				gallery:{
1357					enabled: true
1358				},
1359				image: {
1360					tError: CITYGOV_STORAGE['strings']['magnific_error'],
1361					verticalFit: true
1362				}
1363			});
1364		} catch (e) {};
1365	}
1366
1367
1368	// Add hover icon to products thumbnails
1369	jQuery(".post_item_product .product .images a.woocommerce-main-image:not(.hover_icon)").addClass('hover_icon hover_icon_view');
1370
1371
1372	// Likes counter
1373	if (jQuery('.post_counters_likes:not(.inited)').length > 0) {
1374		jQuery('.post_counters_likes:not(.inited)')
1375			.addClass('inited')
1376			.on('click', function(e) {
1377				var button = jQuery(this);
1378				var inc = button.hasClass('enabled') ? 1 : -1;
1379				var post_id = button.data('postid');
1380				var likes = Number(button.data('likes'))+inc;
1381				var cookie_likes = citygov_get_cookie('citygov_likes');
1382				if (cookie_likes === undefined || cookie_likes===null) cookie_likes = '';
1383				jQuery.post(CITYGOV_STORAGE['ajax_url'], {
1384					action: 'post_counter',
1385					nonce: CITYGOV_STORAGE['ajax_nonce'],
1386					post_id: post_id,
1387					likes: likes
1388				}).done(function(response) {
1389					var rez = {};
1390					try {
1391						rez = JSON.parse(response);
1392					} catch (e) {
1393						rez = { error: CITYGOV_STORAGE['ajax_error'] };
1394						console.log(response);
1395					}
1396					if (rez.error === '') {
1397						if (inc == 1) {
1398							var title = button.data('title-dislike');
1399							button.removeClass('enabled').addClass('disabled');
1400							cookie_likes += (cookie_likes.substr(-1)!=',' ? ',' : '') + post_id + ',';
1401						} else {
1402							var title = button.data('title-like');
1403							button.removeClass('disabled').addClass('enabled');
1404							cookie_likes = cookie_likes.replace(','+post_id+',', ',');
1405						}
1406						button.data('likes', likes).attr('title', title).find('.post_counters_number').html(likes);
1407						citygov_set_cookie('citygov_likes', cookie_likes, 365);
1408					} else {
1409						citygov_message_warning(CITYGOV_STORAGE['strings']['error_like']);
1410					}
1411				});
1412				e.preventDefault();
1413				return false;
1414			});
1415	}
1416
1417    // Social share links
1418    if (jQuery('.sc_socials_share:not(.inited)').length > 0) {
1419        jQuery('.sc_socials_share:not(.inited)').each(function() {
1420            "use strict";
1421            jQuery(this).addClass('inited').on('click', '.social_item_popup > a.social_icons', function(e) {
1422                "use strict";
1423                var url = jQuery(this).data('link');
1424                window.open(url, '_blank', 'scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=480, height=400, toolbar=0, status=0');
1425                e.preventDefault();
1426                return false;
1427            });
1428        });
1429    }
1430
1431	// Add video on thumb click
1432	if (jQuery('.sc_video_play_button:not(.inited)').length > 0) {
1433		jQuery('.sc_video_play_button:not(.inited)').each(function() {
1434			"use strict";
1435			jQuery(this)
1436				.addClass('inited')
1437				.animate({opacity: 1}, 1000)
1438				.on('click', function (e) {
1439					"use strict";
1440					if (!jQuery(this).hasClass('sc_video_play_button')) return;
1441					var video = jQuery(this).removeClass('sc_video_play_button hover_icon_play').data('video');
1442					if (video!=='') {
1443						jQuery(this).empty().html(video);
1444						citygov_video_dimensions();
1445						var video_tag = jQuery(this).find('video');
1446						var w = video_tag.width();
1447						var h = video_tag.height();
1448						citygov_init_media_elements(jQuery(this));
1449						// Restore WxH attributes, because Chrome broke it!
1450						jQuery(this).find('video').css({'width':w, 'height': h}).attr({'width':w, 'height': h});
1451					}
1452					e.preventDefault();
1453					return false;
1454				});
1455		});
1456	}
1457
1458	// Tribe Events buttons
1459	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');
1460}
1461
1462
1463function citygov_init_media_elements(cont) {
1464	if (CITYGOV_STORAGE['media_elements_enabled'] && cont.find('audio,video').length > 0) {
1465		if (window.mejs) {
1466			window.mejs.MepDefaults.enableAutosize = false;
1467			window.mejs.MediaElementDefaults.enableAutosize = false;
1468			cont.find('audio:not(.wp-audio-shortcode),video:not(.wp-video-shortcode)').each(function() {
1469				if (jQuery(this).parents('.mejs-mediaelement').length == 0) {
1470					var media_tag = jQuery(this);
1471					var settings = {
1472						enableAutosize: true,
1473						videoWidth: -1,		// if set, overrides <video width>
1474						videoHeight: -1,	// if set, overrides <video height>
1475						audioWidth: '100%',	// width of audio player
1476						audioHeight: 30,	// height of audio player
1477						success: function(mejs) {
1478							var autoplay, loop;
1479							if ( 'flash' === mejs.pluginType ) {
1480								autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
1481								loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
1482								autoplay && mejs.addEventListener( 'canplay', function () {
1483									mejs.play();
1484								}, false );
1485								loop && mejs.addEventListener( 'ended', function () {
1486									mejs.play();
1487								}, false );
1488							}
1489							media_tag.parents('.sc_audio,.sc_video').addClass('inited sc_show');
1490						}
1491					};
1492					jQuery(this).mediaelementplayer(settings);
1493				}
1494			});
1495		} else
1496			setTimeout(function() { citygov_init_media_elements(cont); }, 400);
1497	}
1498}
1499
1500
1501
1502
1503
1504
1505// Popups and system messages
1506//==============================================
1507
1508// Show system message (bubble from previous page)
1509function citygov_show_system_message() {
1510	if (CITYGOV_STORAGE['system_message'] && CITYGOV_STORAGE['system_message']['message']) {
1511		if (CITYGOV_STORAGE['system_message']['status'] == 'success')
1512			citygov_message_success(CITYGOV_STORAGE['system_message']['message'], CITYGOV_STORAGE['system_message']['header']);
1513		else if (CITYGOV_STORAGE['system_message']['status'] == 'info')
1514			citygov_message_info(CITYGOV_STORAGE['system_message']['message'], CITYGOV_STORAGE['system_message']['header']);
1515		else if (CITYGOV_STORAGE['system_message']['status'] == 'error' || CITYGOV_STORAGE['system_message']['status'] == 'warning')
1516			citygov_message_warning(CITYGOV_STORAGE['system_message']['message'], CITYGOV_STORAGE['system_message']['header']);
1517	}
1518}
1519
1520// Toggle popups
1521function citygov_toggle_popup(popup) {
1522	if (popup.css('display')!='none')
1523		citygov_hide_popup(popup);
1524	else
1525		citygov_show_popup(popup);
1526}
1527
1528// Show popups
1529function citygov_show_popup(popup) {
1530	if (popup.css('display')=='none') {
1531		if (CITYGOV_STORAGE['css_animation'])
1532			popup.show().removeClass('animated fast '+CITYGOV_STORAGE['menu_animation_out']).addClass('animated fast '+CITYGOV_STORAGE['menu_animation_in']);
1533		else
1534			popup.slideDown();
1535	}
1536}
1537
1538// Hide popups
1539function citygov_hide_popup(popup) {
1540	if (popup.css('display')!='none') {
1541		if (CITYGOV_STORAGE['css_animation'])
1542			popup.removeClass('animated fast '+CITYGOV_STORAGE['menu_animation_in']).addClass('animated fast '+CITYGOV_STORAGE['menu_animation_out']).delay(500).hide();
1543		else
1544			popup.fadeOut();
1545	}
1546}
1547
1548
1549
1550
1551// Forms validation
1552//-------------------------------------------------------
1553
1554
1555// Comments form
1556function citygov_comments_validate(form) {
1557	"use strict";
1558	form.find('input').removeClass('error_fields_class');
1559	var error = citygov_form_validate(form, {
1560		error_message_text: CITYGOV_STORAGE['strings']['error_global'],	// Global error message text (if don't write in checked field)
1561		error_message_show: true,									// Display or not error message
1562		error_message_time: 4000,									// Error message display time
1563		error_message_class: 'sc_infobox sc_infobox_style_error',	// Class appended to error message block
1564		error_fields_class: 'error_fields_class',					// Class appended to error fields
1565		exit_after_first_error: false,								// Cancel validation and exit after first error
1566		rules: [
1567			{
1568				field: 'author',
1569				min_length: { value: 1, message: CITYGOV_STORAGE['strings']['name_empty']},
1570				max_length: { value: 60, message: CITYGOV_STORAGE['strings']['name_long']}
1571			},
1572			{
1573				field: 'email',
1574				min_length: { value: 7, message: CITYGOV_STORAGE['strings']['email_empty']},
1575				max_length: { value: 60, message: CITYGOV_STORAGE['strings']['email_long']},
1576				mask: { value: CITYGOV_STORAGE['email_mask'], message: CITYGOV_STORAGE['strings']['email_not_val
1576id']}
1577			},
1578			{
1579				field: 'comment',
1580				min_length: { value: 1, message: CITYGOV_STORAGE['strings']['text_empty'] },
1581				max_length: { value: CITYGOV_STORAGE['comments_maxlength'], message: CITYGOV_STORAGE['strings']['text_long']}
1582			}
1583		]
1584	});
1585	return !error;
1586}
1587
1588
1589// Login form
1590function citygov_login_validate(form) {
1591	"use strict";
1592	form.find('input').removeClass('error_fields_class');
1593	var error = citygov_form_validate(form, {
1594		error_message_show: true,
1595		error_message_time: 4000,
1596		error_message_class: 'sc_infobox sc_infobox_style_error',
1597		error_fields_class: 'error_fields_class',
1598		exit_after_first_error: true,
1599		rules: [
1600			{
1601				field: "log",
1602				min_length: { value: 1, message: CITYGOV_STORAGE['strings']['login_empty'] },
1603				max_length: { value: 60, message: CITYGOV_STORAGE['strings']['login_long'] }
1604			},
1605			{
1606				field: "pwd",
1607				min_length: { value: 4, message: CITYGOV_STORAGE['strings']['password_empty'] },
1608				max_length: { value: 30, message: CITYGOV_STORAGE['strings']['password_long'] }
1609			}
1610		]
1611	});
1612	if (!error) {
1613		jQuery.post(CITYGOV_STORAGE['ajax_url'], {
1614			action: 'login_user',
1615			nonce: CITYGOV_STORAGE['ajax_nonce'],
1616			remember: form.find('#rememberme').val(),
1617			user_log: form.find('#log').val(),
1618			user_pwd: form.find('#password').val()
1619		}).done(function(response) {
1620			var rez = {};
1621			try {
1622				rez = JSON.parse(response);
1623			} catch (e) {
1624				rez = { error: CITYGOV_STORAGE['ajax_error'] };
1625				console.log(response);
1626			}
1627			var result_box = form.find('.result');
1628			if (result_box.length==0) result_box = form.siblings('.result');
1629			if (result_box.length==0) result_box = form.after('<div class="result"></div>').next('.result');
1630			result_box.toggleClass('sc_infobox_style_error', false).toggleClass('sc_infobox_style_success', false);
1631			if (rez.error === '') {
1632				result_box.addClass('sc_infobox sc_infobox_style_success').html(CITYGOV_STORAGE['strings']['login_success']);
1633				setTimeout(function() { 
1634					location.reload(); 
1635					}, 3000);
1636			} else {
1637				result_box.addClass('sc_infobox sc_infobox_style_error').html(CITYGOV_STORAGE['strings']['login_failed'] + '<br>' + rez.error);
1638			}
1639			result_box.fadeIn().delay(3000).fadeOut();
1640		});
1641	}
1642	return false;
1643}
1644
1645
1646// Registration form 
1647function citygov_registration_validate(form) {
1648	"use strict";
1649	form.find('input').removeClass('error_fields_class');
1650	var error = citygov_form_validate(form, {
1651		error_message_show: true,
1652		error_message_time: 4000,
1653		error_message_class: "sc_infobox sc_infobox_style_error",
1654		error_fields_class: "error_fields_class",
1655		exit_after_first_error: true,
1656		rules: [
1657			{
1658				field: "registration_username",
1659				min_length: { value: 1, message: CITYGOV_STORAGE['strings']['login_empty'] },
1660				max_length: { value: 60, message: CITYGOV_STORAGE['strings']['login_long'] }
1661			},
1662			{
1663				field: "registration_email",
1664				min_length: { value: 7, message: CITYGOV_STORAGE['strings']['email_empty'] },
1665				max_length: { value: 60, message: CITYGOV_STORAGE['strings']['email_long'] },
1666				mask: { value: CITYGOV_STORAGE['email_mask'], message: CITYGOV_STORAGE['strings']['email_not_valid'] }
1667			},
1668			{
1669				field: "registration_pwd",
1670				min_length: { value: 4, message: CITYGOV_STORAGE['strings']['password_empty'] },
1671				max_length: { value: 30, message: CITYGOV_STORAGE['strings']['password_long'] }
1672			},
1673			{
1674				field: "registration_pwd2",
1675				equal_to: { value: 'registration_pwd', message: CITYGOV_STORAGE['strings']['password_not_equal'] }
1676			}
1677		]
1678	});
1679	if (!error) {
1680		jQuery.post(CITYGOV_STORAGE['ajax_url'], {
1681			action: 'registration_user',
1682			nonce: CITYGOV_STORAGE['ajax_nonce'],
1683			user_name: 	form.find('#registration_username').val(),
1684			user_email: form.find('#registration_email').val(),
1685			user_pwd: 	form.find('#registration_pwd').val()
1686		}).done(function(response) {
1687			var rez = {};
1688			try {
1689				rez = JSON.parse(response);
1690			} catch (e) {
1691				rez = { error: CITYGOV_STORAGE['ajax_error'] };
1692				console.log(response);
1693			}
1694			var result_box = form.find('.result');
1695			if (result_box.length==0) result_box = form.siblings('.result');
1696			if (result_box.length==0) result_box = form.after('<div class="result"></div>').next('.result');
1697			result_box.toggleClass('sc_infobox_style_error', false).toggleClass('sc_infobox_style_success', false);
1698			if (rez.error === '') {
1699				result_box.addClass('sc_infobox sc_infobox_style_success').html(CITYGOV_STORAGE['strings']['registration_success']);
1700				setTimeout(function() { 
1701					jQuery('.popup_login_link').trigger('click'); 
1702					}, 3000);
1703			} else {
1704				result_box.addClass('sc_infobox sc_infobox_style_error').html(CITYGOV_STORAGE['strings']['registration_failed'] + ' ' + rez.error);
1705			}
1706			result_box.fadeIn().delay(3000).fadeOut();
1707		});
1708	}
1709	return false;
1710}
1711
1712
1713// Contact form handlers
1714function citygov_sc_form_validate(form){
1715	"use strict";
1716	var url = form.attr('action');
1717	if (url == '') return false;
1718	form.find('input').removeClass('error_fields_class');
1719	var error = false;
1720	var form_custom = form.data('formtype')=='form_custom';
1721	if (!form_custom) {
1722		error = citygov_form_validate(form, {
1723			error_message_show: true,
1724			error_message_time: 4000,
1725			error_message_class: "sc_infobox sc_infobox_style_error",
1726			error_fields_class: "error_fields_class",
1727			exit_after_first_error: false,
1728			rules: [
1729				{
1730					field: "username",
1731					min_length: { value: 1,	 message: CITYGOV_STORAGE['strings']['name_empty'] },
1732					max_length: { value: 60, message: CITYGOV_STORAGE['strings']['name_long'] }
1733				},
1734				{
1735					field: "email",
1736					min_length: { value: 7,	 message: CITYGOV_STORAGE['strings']['email_empty'] },
1737					max_length: { value: 60, message: CITYGOV_STORAGE['strings']['email_long'] },
1738					mask: { value: CITYGOV_STORAGE['email_mask'], message: CITYGOV_STORAGE['strings']['email_not_valid'] }
1739				},
1740				{
1741					field: "subject",
1742					min_length: { value: 1,	 message: CITYGOV_STORAGE['strings']['subject_empty'] },
1743					max_length: { value: 100, message: CITYGOV_STORAGE['strings']['subject_long'] }
1744				},
1745				{
1746					field: "message",
1747					min_length: { value: 1,  message: CITYGOV_STORAGE['strings']['text_empty'] },
1748					max_length: { value: CITYGOV_STORAGE['contacts_maxlength'], message: CITYGOV_STORAGE['strings']['text_long'] }
1749				}
1750			]
1751		});
1752	}
1753	if (!error && url!='#') {
1754		jQuery.post(url, {
1755			action: "send_form",
1756			nonce: CITYGOV_STORAGE['ajax_nonce'],
1757			type: form.data('formtype'),
1758			data: form.serialize()
1759		}).done(function(response) {
1760			"use strict";
1761			var rez = {};
1762			try {
1763				rez = JSON.parse(response);
1764			} catch (e) {
1765				rez = { error: CITYGOV_STORAGE['ajax_error'] };
1766				console.log(response);
1767			}
1768			var result = form.find(".result").toggleClass("sc_infobox_style_error", false).toggleClass("sc_infobox_style_success", false);
1769			if (rez.error === '') {
1770				form.get(0).reset();
1771				result.addClass("sc_infobox_style_success").html(CITYGOV_STORAGE['strings']['send_complete']);
1772				var return_url = form.find('input[name="return_url"]');
1773				if (return_url.length > 0 && return_url.val()!='') {
1774					setTimeout(function() {
1775						"use strict";
1776						window.location.href = return_url.val();
1777					}, 3300);
1778				}
1779			} else {
1780				result.addClass("sc_infobox_style_error").html(CITYGOV_STORAGE['strings']['send_error'] + ' ' + rez.error);
1781			}
1782			result.fadeIn().delay(3000).fadeOut();
1783		});
1784	}
1785	return !error;
1786}

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.