PageSourceSearch

https://www.harlemrocket.com/wp-content/themes/harlemrocket/assets…?ver=839848c15140eaf0c5ec563d2d8872d6

js harlemrocket.com collected 2026-10-06 17:21:33 UTC 77,705 bytes, 1,748 lines download raw bytes

1var monthsLZ = [];
2var monthsSZ = [];
3monthsLZ[1] = 'January';
4monthsLZ[2] = 'February';
5monthsLZ[3] = 'March';
6monthsLZ[4] = 'April';
7monthsLZ[5] = 'May';
8monthsLZ[6] = 'June';
9monthsLZ[7] = 'July';
10monthsLZ[8] = 'August';
11monthsLZ[9] = 'September';
12monthsLZ[10] = 'October';
13monthsLZ[11] = 'November';
14monthsLZ[12] = 'December';
15monthsSZ[1] = 'Jan';
16monthsSZ[2] = 'Feb';
17monthsSZ[3] = 'Mar';
18monthsSZ[4] = 'Apr';
19monthsSZ[5] = 'May';
20monthsSZ[6] = 'Jun';
21monthsSZ[7] = 'Jul';
22monthsSZ[8] = 'Aug';
23monthsSZ[9] = 'Sep';
24monthsSZ[10] = 'Oct';
25monthsSZ[11] = 'Nov';
26monthsSZ[12] = 'Dec';
27
28var customStyles = {
29    palette: {
30        background: {
31            default: "#ffffff"
32        }
33    }
34};
35
36var checkoutCustomStyle = {
37	"palette": {
38		"primary": {
39			"main": "#E9002F",
40		},
41		"secondary": {
42			"main": "#E9002F",
43		},
44		"calendar": {
45			"main": "#E9002F",
46			"contrastText": "#fff"
47		},
48		"background": {
49			"default": "#ffffff"
50		},
51	}
52};
53
54
55var allTranslations = ['ar','da','de','el','es','fr','he','hi','it','ja','ko','ms','nl','pt','ru','sw','tr','vi','zh'];
56
57function plusSlides(slideId, n) {
58    //window['slide_' + slideId] += n;
59    hbShowSlides(slideId, window['slide_' + slideId] += n);
60}
61
62function currentSlide(slideId, n) {
63    //window['slide_' + slideId] = n;
64    hbShowSlides(slideId, window['slide_' + slideId] = n);
65}
66
67function hbShowSlides(id, n) {
68    var slides = jQuery('.hbSlides[data-id='+id+']');
69    var dots = jQuery('.hb-dot[data-id='+id+']');
70    if (n > slides.length) {window['slide_' + id] = 1}
71    if (n < 1) {window['slide_' + id] = slides.length}
72    slides.attr('style', 'display: none;').removeClass('show');
73    for (var i = 0; i < dots.length; i++) {
74        dots[i].className = dots[i].className.replace(" active", "");
75    }
76    jQuery(slides[window['slide_' + id]-1]).attr('style', 'display: block;').addClass('show');
77    jQuery(dots).removeClass('active');
78    jQuery(dots[window['slide_' + id]-1]).addClass('active');;
79}
80
81function prepareHBSlideImages(id, slideIndex) {
82    window['slide_' + id] = slideIndex;
83    hbShowSlides(id, slideIndex);
84}
85
86function getPageTranslation() {
87    var thisPath = window.location.pathname.split('/');
88    var thisPath = jQuery.map( thisPath, function(v){
89        return v === "" ? null : v;
90    });
91    if(thisPath.length === 0) {
92        return 'en';
93    } else {
94        if(allTranslations.includes(thisPath[0])) {
95            //console.log('found',thisPath[0]);
96            return thisPath[0];
97        } else {
98            return 'en';
99        }
100    }
101}
102
103function updateHeaderHeight(el, head) {
104    console.log('el', el.height());
105    console.log('head', head.height());
106    if(el.height() < head.height()) {
107        el.attr('style','height:'+head.height()+'px;');
108    }
109}
110
111function populateDefaultTour(obj) {
112    var selTour = '';
113    //selTour = '/tour-options/alcatraz-day-tour/';
114    //selTour = '/tour-options/alcatraz-night-tour/';
115    //selTour = '/tour-options/alcatraz-behind-the-scenes-tour/';
116    //selTour = '/tour-options/alcatraz-angel-island-combo-tour/';
117    if(selTour.length > 0) obj.val(selTour);
118}
119
120function buildPaginationList(tot, cur, cName) {
121    var paginationHTML = '';
122    paginationHTML += '<ul>';
123    for(var pIdx=0; pIdx < tot; pIdx++) {
124        var thisIdx = pIdx + 1;
125        paginationHTML += '<li class="page-'+thisIdx+'">';
126        paginationHTML += '<a href="" class="'+cName+' '+(thisIdx === cur ? 'selected' : '')+'" role-num="'+thisIdx+'">'+thisIdx+'</a>';
127        paginationHTML += '</li>';
128    }
129    paginationHTML += '</ul>';
130    return paginationHTML;
131}
132
133function assignIframeClassW(iframeID) {
134    var iframeW = jQuery('iframe#'+iframeID).width();
135    //console.log('iframeW',iframeW);
136    var selClass = '';
137    if(iframeW < 500) {
138        selClassNum = 'sm';
139    } else if (iframeW >= 500) {
140        selClassNum = 'md';
141    }
142    jQuery('iframe#'+iframeID).attr('data-size',selClassNum);
143}
144
145function setCookie(cname, cvalue, exdays) {
146    var d = new Date();
147    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
148    var expires = "expires="+d.toUTCString();
149    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
150}
151
152function getCookie(cname) {
153    var name = cname + "=";
154    var ca = document.cookie.split(';');
155    for(var i = 0; i < ca.length; i++) {
156        var c = ca[i];
157        while (c.charAt(0) == ' ') {
158            c = c.substring(1);
159        }
160        if (c.indexOf(name) == 0) {
161            return c.substring(name.length, c.length);
162        }
163    }
164    return "";
165}
166
167function checkCookie() {
168    var user = getCookie("username");
169    if (user != "") {
170        alert("Welcome again " + user);
171    } else {
172        user = prompt("Please enter your name:", "");
173        if (user != "" && user != null) {
174            setCookie("username", user, 365);
175        }
176    }
177}
178
179function getElementProp_listing(obj) {
180    var elProp = [];
181    if (obj.length) {
182        var pos = obj.position();
183        elProp['posX'] = pos.left;
184        elProp['posY'] = pos.top;
185        elProp['w'] = obj.width();
186        elProp['h'] = obj.height();
187    }
188
189    return elProp;
190}
191
192function updateExpNav_listing(mainObj, ulWrap, ulObj, prevObj, nextObj) {
193    var expList = getElementProp_listing(ulWrap);
194    var listLen = ulObj.width();
195    var screenXsize = mainObj.width();
196    //ulWrap.attr('style', 'left:'+expList['posX']+'px; width:'+listLen+'px;');
197    if (listLen <= screenXsize - expList['posX']) {
198        nextObj.addClass('hide');
199    } else if (expList['w'] > screenXsize) {
200        nextObj.removeClass('hide');
201    }
202
203    if (expList['posX'] < 0) {
204        prevObj.removeClass('hide');
205    } else {
206        prevObj.addClass('hide');
207    }
208}
209
210function isJson(str) {
211    try {
212        JSON.parse(str);
213    } catch (e) {
214        return false;
215    }
216    return true;
217}
218
219function nextBtn_listing(mainObj, ulWrap, ulObj, prevObj, nextObj) {
220    var screenXsize = mainObj.width();
221    var listLen = ulObj.width();
222    var expList = getElementProp_listing(ulWrap);
223    var nextLeft = -(expList.posX - screenXsize);
224    console.log('screenXsize',screenXsize);
225    console.log('listLen',listLen);
226    console.log('expList',expList);
227    console.log('nextLeft',nextLeft);
228    nextLeft = nextLeft + screenXsize > listLen ? listLen - screenXsize : nextLeft;
229    console.log('nextLeft',nextLeft);
230    ulWrap.animate({
231        left: -nextLeft
232    }, 800, function () {
233        console.log('done animation');
234        updateExpNav_listing(mainObj, ulWrap, ulObj, prevObj, nextObj);
235    });
236}
237
238function prevBtn_listing(mainObj, ulWrap, ulObj, prevObj, nextObj) {
239    var screenXsize = mainObj.width();
240    var listLen = ulObj.width();
241    var expList = getElementProp_listing(ulWrap);
242    var nextRight = expList.posX + screenXsize > 0 ? 0 : expList.posX + screenXsize;
243    nextRight = nextRight > 0 ? 0 : nextRight;
244    ulWrap.animate({
245        left: nextRight
246    }, 800, function () {
247        updateExpNav_listing(mainObj, ulWrap, ulObj, prevObj, nextObj);
248    });
249}
250
251function calculateToShowFiller(mainObj, liDataObj, liFillerObj) {
252    var item_per_row = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
253    var allDataCount = liDataObj.length;
254    var allHiddenDataCount = 0; //liDataObj.attr('class','hide').length;
255
256    jQuery(liDataObj).each(function (liItem) {
257        allHiddenDataCount += jQuery(this).hasClass('hide') ? 1 : 0;
258    });
259    var allShowDataCount = allDataCount - allHiddenDataCount;
260    var fillerMax = liFillerObj.length;
261    var modVal = allShowDataCount % item_per_row;
262    var needFillerCount = allShowDataCount == 0 ? item_per_row : modVal ? item_per_row - modVal : modVal; //console.log('allDataCount',allDataCount);
263    //console.log('allHiddenDataCount',allHiddenDataCount);
264    //console.log('allShowDataCount',allShowDataCount);
265    //console.log('fillerMax',fillerMax);
266    //console.log('item_per_row',item_per_row);
267
268    var fillerIdx = [];
269
270    for (var idx = 0; idx < needFillerCount; idx++) {
271        fillerIdx = getAvailableIndex(fillerIdx, fillerMax);
272    } //console.log('fillerIdx',fillerIdx);
273
274
275    for (var fidx = 0; fidx < fillerIdx.length; fidx++) {
276        jQuery(liFillerObj).each(function (tx) {
277            //console.log('tx',tx,'fidx',fillerIdx[fidx]);
278            if (tx + 1 == fillerIdx[fidx]) {
279                //console.log('tx',tx);
280                jQuery(this).removeClass('hide');
281            }
282        });
283    }
284
285    ;
286}
287
288function getTodayDate() {
289    var today = new Date();
290    var dd = String(today.getDate()).padStart(2, '0');
291    var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
292    var yyyy = today.getFullYear();
293
294    return mm + '/' + dd + '/' + yyyy;
295}
296
297function getTodayDateOrUrlParam(urlParam) {
298    var selUrlParam = decodeURIComponent(getUrlParam(urlParam,''));
299    var today = new Date();
300    var dd = String(today.getDate()).padStart(2, '0');
301    var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
302    var yyyy = today.getFullYear();
303
304    return selUrlParam.length ? selUrlParam : mm + '/' + dd + '/' + yyyy;
305}
306
307function getAvailableIndex(existing, max) {
308    var found = false;
309    var maxIter = 10;
310    var curIter = 0;
311    var nextNum = 0;
312
313    while (!found && curIter < maxIter) {
314        nextNum = Math.floor(Math.random() * 1000000 % max) + 1;
315
316        if (existing.indexOf(nextNum) < 0) {
317            existing.push(nextNum);
318            found = true;
319            curIter = maxIter;
320        }
321
322        curIter++;
323    }
324
325    if (!found) {
326        for (idx = 0; idx < max; idx++) {
327            if (existing.indexOf(idx) < 0) {
328                existing.push(idx);
329                idx = max;
330            }
331        }
332    }
333
334    return existing;
335}
336
337function removeActiveFilterByClass(filterClass) {
338    jQuery('.' + filterClass).removeClass('active');
339}
340
341function hideAllListItemsByElement() {
342    for (i = 0; i < arguments.length; i++) {
343        jQuery(arguments[i]).addClass('hide');
344    }
345}
346
347function showAllListItemsByClass(liObj, cName) {
348    jQuery(liObj).each(function () {
349        if (cName == '' || jQuery(this).hasClass(cName)) {
350            jQuery(this).removeClass('hide');
351        }
352    });
353}
354
355function getCartContent() {
356	var anchorMetaStr = decodeURIComponent(getCookie('_anchorcidmeta'));
357	return isJson(anchorMetaStr) ? JSON.parse(anchorMetaStr) : { };
358}
359
360function getCartCount() {
361	var anchorMeta = getCartContent();
362	var count = anchorMeta.totalItems !== undefined ? anchorMeta.totalItems : 0;
363	//console.log('getCartCount', anchorMeta, count);
364	return anchorMeta.totalItems !== undefined ? anchorMeta.totalItems : 0;
365}
366
367function updateTourListingStatus(myObj, isFirst) {
368	var anchorMeta = getCartContent();
369	var addedBookId = [];
370	for( var i = 0; i < (anchorMeta.cartItems||[]).length; i++ ) {
371		if(addedBookId[anchorMeta.cartItems[i].bookingTypeId] === undefined) {
372			addedBookId[anchorMeta.cartItems[i].bookingTypeId] = [];
373		}
374		addedBookId[anchorMeta.cartItems[i].bookingTypeId].push(anchorMeta.cartItems[i].tourDateTimeFormatted);
375	}
376	if((anchorMeta.cartItems||[]).length) {
377		jQuery('.hbg-show-listing.cart-listing-tour .start-over').removeClass('disabled');
378	}
379	console.log('anchorMeta', addedBookId);
380	var foundFirstToOpen = true;
381	for( var j = 0; j < myObj.listing.length; j++ ) {
382		if(addedBookId[myObj.listing[j].bookingTypeId] !== undefined ) {
383			//console.log('found='+myObj.listing[j].bookingTypeId);
384			//jQuery('li.glisting-item[data-id='+myObj.listing[j].bookingTypeId+'] a.add-this-item-action').addClass('disabled');
385			var thisStr = addedBookId[myObj.listing[j].bookingTypeId].join('<br />');
386			jQuery('li.glisting-item[data-id='+myObj.listing[j].bookingTypeId+'] .added-in-cart-detail').html(thisStr);
387		} else {
388			//jQuery('li.glisting-item[data-id='+myObj.listing[j].bookingTypeId+'] a.add-this-item-action').removeClass('disabled');
389			jQuery('li.glisting-item[data-id='+myObj.listing[j].bookingTypeId+'] .added-in-cart-detail').html('');
390			if(isFirst && foundFirstToOpen) {
391				var id = jQuery('li.glisting-item[data-id='+myObj.listing[j].bookingTypeId+'] a.add-this-item-action').attr('data-id');
392				var title = jQuery('li.glisting-item[data-id='+myObj.listing[j].bookingTypeId+'] a.add-this-item-action').attr('data-name');
393				openCartItem(myObj, id, title);
394				foundFirstToOpen = false;
395			}
396		}
397	}
398	console.log('updateTourListingStatus', myObj.listing, anchorMeta);
399}
400
401function clearCartItem(myObj) {
402	window.HBCommerceClearCart();
403	location.reload()
404}
405
406function openCartItem(myObj, id, title) {
407	//console.log('openCartItem', myObj, id);
408	jQuery('#hb-commerce-sdk-root').html('');
409	jQuery('.glisting-cart h3').html(title);
410	myObj.HBCommerce.launch({
411		propertyId: 'rdrvz',
412		locale: 'en',
413		bookingTypeId: id,
414		customStyles: checkoutCustomStyle,
415		flags: {
416			//preselectionMode: true,
417			cartMode: true,
418		},
419		onPreselectionComplete: function (event) {
420			console.log('onPreselectionComplete');
421			var preselection = encodeURIComponent(JSON.stringify(event));
422			window.location = checkoutStr + preselection;
423			//console.log(preselection);
424		},
425		onCartChange: function(event) {
426			var cartItems = (((event || {}).payload || {}).cartItems || []);
427			var continueButton = ((event || {}).payload || {}).continueShopping || false;
428			console.log('onCartChange',cartItems,continueButton)
429			if(continueButton) {
430				location.reload();
431			} else {
432				cart_count = cartItems.length;
433				if(typeof update_cart_count_in_nav === 'function') {
434					update_cart_count_in_nav();
435				}
436				updateTourListingStatus(myObj);
437				var topPx = jQuery("#hb-commerce-sdk-root").offset().top;
438				jQuery( "html, body" ).animate( { scrollTop: topPx - 100 } );
439			}
440		},
441		onViewCart: function(event) {
442			// navigate to cart-checkout page url
443			location.href = '/checkout/';
444		}
445	}, "hb-commerce-sdk-root").then(function (instance) {
446		_HBCOMMERCEINSTANCE_ = instance;
447	}).catch(function (err) {
448		console.log("Error launching commerce sdk", err);
449	});
450}
451
452function populateTour(tour,lang) {
453    var tourObj = {};
454    var thisLang = lang === undefined ? 'en' : lang;
455    //console.log('populateTour',tour);
456    if(tour.unavailable.length) {
457        tourObj = tour.unavailable[0];
458        var localizedEnLang = tourObj.localizedInfo['en'];
459        var localizedLang = tourObj.localizedInfo[thisLang] || localizedEnLang;
460        //console.log('populateTour',localizedEnLang, localizedLang);
461        tourObj.title = localizedLang.title || localizedEnLang.title || 'No Title';
462        tourObj.overview = localizedLang.description || localizedEnLang.description || "";
463        tourObj.whatUget = localizedLang.whatYouGet || localizedEnLang.whatYouGet || "";
464        tourObj.schedule = localizedLang.schedule || localizedEnLang.schedule || "";
465        tourObj.whereToMeet = localizedLang.whereToMeet || localizedEnLang.whereToMeet || "";
466        tourObj.dressCode = localizedLang.dressCode || localizedEnLang.dressCode || "";
467
468        tourObj.has_whereToMeet = tourObj.whereToMeet.length > 0;
469        tourObj.has_whatUget = tourObj.whatUget.length > 0;
470        tourObj.has_schedule = tourObj.schedule.length > 0;
471        tourObj.has_dressCode = tourObj.dressCode.length > 0;
472
473		tourObj.video = (tourObj.media.videos.length ? tourObj.media.videos[0].url : '');
474        tourObj.has_video = (tourObj.media.videos.length ? true : false);
475        tourObj.address = (tourObj.settings['address.formatted'] || '');
476        tourObj.additional_assets = [];
477        tourObj.additional_assets_no_map = [];
478        tourObj.lat = tourObj.settings['address.latitude'];
479        tourObj.lon = tourObj.settings['address.longitude'];
480        tourObj.has_main_image = false;
481
482        tourObj.review = (tourObj.settings.review || "");
483        //tourObj.overview = (tourObj.overview.length ? '<h2>Overview</h2>' + tourObj.overview : "");
484        //tourObj.whatUget = (tourObj.whatUget.length ? '<h2>Includes</h2>' + tourObj.whatUget : "");
485        //tourObj.schedule = (tourObj.schedule.length ? '<h2>Schedule</h2>' + tourObj.schedule : "");
486        //tourObj.whereToMeet = (tourObj.whereToMeet.length ? '<h2>Where to Meet</h2>' + tourObj.whereToMeet : "");
487        //tourObj.dressCode = (tourObj.dressCode.length ? '<h2>Dress Code</h2>' + tourObj.dressCode : "");
488        tourObj.has_review = (tourObj.review.length ? true : false);
489
490        var mainImageIndex = 0;
491        tourObj.has_prime_image = !tourObj.has_video;
492        tourObj.has_main_image = false;
493        if(tourObj.media.images.length && tourObj.has_prime_image) {
494            tourObj.prime_image_url = tourObj.media.images[0].url;
495            mainImageIndex++;
496        }
497
498        if(tourObj.media.images.length > mainImageIndex) {
499            tourObj.main_image_url = tourObj.media.images[mainImageIndex].url;
500            tourObj.main_image_index = mainImageIndex + 1;
501            tourObj.has_main_image = true;
502        }
503			
504		tourObj.liCategories = convertCategories(tourObj.categories || '');
505		if (tourObj.schedule.length) {
506    let _schedule = tourObj.schedule.replace("</p><p>", " / ").replace("<p>", "").replace("</p>", "").split(" / ");
507    //if(_schedule.length == 2 && _schedule[0].split(" - ").length == 2 && _schedule[1].split("Time - ").length == 2){
508    //    tourObj.schedule = { boardingTime: _schedule[0].split(" - ")[1], cruiseTime: _schedule[1].split("Time - ")[1] };
509    //}
510    //else{
511    //    tourObj.schedule = false;
512    //}
513}
514
515if (tourObj.liCategories.length) {
516    let _cats = tourObj.liCategories, 
517        _catsArr = _cats.split(" ");
518
519    tourObj.childCruisePrice = _catsArr.filter(e => e.indexOf("child-s-cruise-price") > -1);
520    tourObj.windowSeats = _catsArr.filter(e => e.indexOf("window-seats") > -1);
521
522    tourObj.childCruisePrice = tourObj.childCruisePrice.length ? tourObj.childCruisePrice[0].split("---")[1] : "$0.00";
523    tourObj.windowSeats = tourObj.windowSeats.length ? tourObj.windowSeats[0].split("---")[1] : "$0.00";
524}
525
526        //console.log('mainImageIndex',mainImageIndex);
527        var shiftIndex = tour.is_experiences ? 0 : 1;
528        tourObj.max_image_assets = tourObj.media.images.length;
529        for(var idx=mainImageIndex;idx < tourObj.media.images.length; idx+=2) {
530            var add_images = { top: '', top_image_assets: '', bottom: '', bottom_image_assets: '', has_bottom: false};
531            if(idx < tourObj.media.images.length) {
532                add_images.top = tourObj.media.images[idx].url;
533                add_images.top_image_assets = idx + 1;
534            }
535            if(idx + 1 < tourObj.media.images.length) {
536                add_images.bottom = tourObj.media.images[idx+1].url;
537                add_images.bottom_image_assets = idx + 2;
538                add_images.has_bottom = true;
539            }
540            tourObj.additional_assets.push(add_images)
541        }
542    }
543    return tourObj;
544}
545
546var formatter = new Intl.NumberFormat('en-US', {
547    style: 'currency',
548    currency: 'USD',
549});
550
551function getItineraryDayPort(itinObj, dayNum) {
552    var portObj = { port_id: 0, 'port_name': '', 'port_link': '', 'port_image': '', 'port_content': '', 'has_excursion': false, 'excursions': { 'has_included': false, 'has_premium': false, 'included': [], 'premium': [] } };
553    var thisPort = itinObj.length > (dayNum-1) ? itinObj[dayNum-1].port : itinObj[itinObj.length-1].port;
554    var thisExcursion = itinObj.length > (dayNum-1) ? itinObj[dayNum-1].excursions : itinObj[itinObj.length-1].excursions;
555    //console.log('itinObj',itinObj);
556    //console.log('thisPort',thisPort);
557    portObj.port_id = thisPort.id;
558    portObj.port_name = (thisPort.localizedInfo.en !== undefined && thisPort.localizedInfo.en.portName) || '';
559    portObj.port_link = '';
560    portObj.port_image = thisPort.media.images[0];
561    portObj.port_content = (thisPort.localizedInfo.en !== undefined && thisPort.localizedInfo.en.portDescription) || '';
562    portObj.has_excursion = thisExcursion.length > 0;
563    portObj.excursions = thisExcursion;
564    return portObj;
565}
566
567function getDateProps(thisDate) {
568    var thisDateProp = { 'ldate': '', 'lsdate': '', 'sdate0': '', 'sdate': '', 'cdate': '', 'mdate': '', 'yydate': '', 'mmdate': '', 'dddate': '', 'phpdate': '', 'ymddate':'', 'gmtdate': '' }
569    var thisDateObj = thisDate.split('-');
570    var thisDateMM = thisDateObj[1];
571    var thisDateM = parseInt(thisDateMM);
572    var thisDateDD = thisDateObj[2];
573    var thisDateD = parseInt(thisDateDD);
574    var thisDateYYYY = thisDateObj[0];
575    var thisDateYY = thisDateYYYY.substr(-2,2);
576    thisDateProp.ldate = monthsLZ[thisDateM] + ' ' + thisDateD + ', ' + thisDateYYYY;
577    thisDateProp.lsdate = monthsSZ[thisDateM] + ' ' + thisDateD + ', ' + thisDateYYYY;
578    thisDateProp.sdate0 = thisDateMM + '/' + thisDateDD + '/' + thisDateYYYY;
579    thisDateProp.sdate = thisDateM + '/' + thisDateD + '/' + thisDateYYYY;
580    thisDateProp.cdate = thisDateM + '/' + thisDateD + '/' + thisDateYYYY;
581    thisDateProp.udate = thisDateM + '-' + thisDateD + '-' + thisDateYYYY;
582    thisDateProp.mdate = thisDateYYYY + '-' + thisDateMM;
583    thisDateProp.yydate = thisDateYYYY;
584    thisDateProp.mmdate = thisDateMM;
585    thisDateProp.dddate = thisDateDD;
586    thisDateProp.phpdate = thisDateYYYY;
587    thisDateProp.ymddate = thisDateYYYY+thisDateMM+thisDateDD;
588    thisDateProp.gmtdate = thisDate;
589    return thisDateProp;
590}
591
592function populateSdkTours(tours, selMonth) {
593    var listObj = { listing: [] };
594    //console.log('selMonth',selMonth);
595    for(var tIdx=0; tIdx < tours.length; tIdx++) {
596        var thisTour = populateSdkTour(tours[tIdx]);
597        //console.log('thisTourthisTour',thisTour);
598        var thisVesselData = thisTour.cruise_data.vessel_data;
599        for(var vIdx=0; vIdx < thisVesselData.length; vIdx++) {
600            var thisListing = { item_image: '', item_name: '', sub_title: '', description: '', depart_date: { ldate: ''}, has_sale_price: false, from_original_price_str: '', permalink: '', sailingId: 0 };
601            thisListing.item_image = thisTour.prime_image_url;
602            thisListing.item_name = thisTour.title;
603            thisListing.sub_title = thisTour.sub_title;
604            thisListing.description = thisTour.localizedInfo.en.shortDescription;
605            thisListing.permalink = thisTour.permalink;
606            thisListing.item_link = thisTour.permalink;
607            var thisVessel = thisVesselData[vIdx];
608            thisListing.itineraryName = thisVesselData[vIdx].itineraryName;
609            thisListing.sailingId = thisVesselData[vIdx].sailingID;
610            thisListing.depart_date = thisVesselData[vIdx].vessel_date;
611            thisListing.arrive_date = thisVesselData[vIdx].vessel_end_date;
612            thisListing.vessel_name = thisVesselData[vIdx].vesselName;
613            thisListing.numDays = thisVesselData[vIdx].numDays;
614            thisListing.cruise_date = thisListing.depart_date.ymddate;
615            thisListing.has_sale_price = thisVesselData[vIdx].has_startingAtSalePrice;
616            thisListing.from_original_price_str = thisVesselData[vIdx].startingFromPrice_str;
617            thisListing.from_sale_price_str = thisVesselData[vIdx].startingAtSalePrice_str;
618            thisListing.save_per_couple_str = thisVesselData[vIdx].starting_save_per_couple_str;
619            if(selMonth === '' || selMonth === thisListing.depart_date.mdate) {
620                listObj.listing.push(thisListing);
621            }
622        }
623    }
624    return listObj;
625}
626
627function populateSdkTour(tour) {
628    var tourObj = {};
629    //console.log('tourtour',tour);
630    tourObj = tour;
631    tourObj.title = (tourObj.localizedInfo.en.title || 'No Title');
632    tourObj.sub_title = (tourObj.localizedInfo.en.subTitle || '');
633    tourObj.video = (tourObj.media.videos.length ? tourObj.media.videos[0].url : '');
634    tourObj.has_video = (tourObj.media.videos.length ? true : false);
635    tourObj.address = (tourObj.settings['address.formatted'] || '');
636    tourObj.additional_assets = [];
637    tourObj.lat = tourObj.settings['address.latitude'];
638    tourObj.lon = tourObj.settings['address.longitude'];
639    tourObj.has_main_image = false;
640
641    tourObj.overview = (tourObj.localizedInfo.en.description || "");
642    tourObj.whatUget = (tourObj.localizedInfo.en.whatYouGet || "");
643    tourObj.schedule = (tourObj.localizedInfo.en.schedule || "");
644    tourObj.whereToMeet = (tourObj.localizedInfo.en.whereToMeet || "");
645    tourObj.dressCode = (tourObj.localizedInfo.en.dressCode || "");
646    tourObj.review = (tourObj.settings.review || "{}");
647    tourObj.overview = (tourObj.overview.length ? '<h2>Cruise Highlights</h2>' + tourObj.overview : "");
648    tourObj.whatUget = (tourObj.whatUget.length ? '<h2>Itinerary</h2>' + tourObj.whatUget : "");
649    tourObj.schedule = (tourObj.schedule.length ? '<h2>Schedule</h2>' + tourObj.schedule : "");
650    tourObj.whereToMeet = (tourObj.whereToMeet.length ? '<h2>Where to Meet</h2>' + tourObj.whereToMeet : "");
651    tourObj.dressCode = (tourObj.dressCode.length ? '<h2>Dress Code</h2>' + tourObj.dressCode : "");
652    tourObj.has_review = (tourObj.review.length ? true : false);
653    tourObj.listing =  JSON.parse(isJson(tourObj.review) ? tourObj.review :  '{}');
654    tourObj.total_listing = tourObj.listing.length;
655    for(var lidx=0; lidx < tourObj.listing.length; lidx++) {
656        var thisYStr = tourObj.listing[lidx].cruise_date.slice(0,4);
657        var thisMStr = tourObj.listing[lidx].cruise_date.slice(4,6).replace(/^0+/, '');
658        var thisDStr = tourObj.listing[lidx].cruise_date.slice(6,8).replace(/^0+/, '');
659        tourObj.listing[lidx].cruise_date_numeric = thisMStr+'/'+thisDStr+'/'+thisYStr;
660        tourObj.listing[lidx].cruise_date_str_long = monthsLZ[thisMStr]+' '+thisDStr+', '+thisYStr;
661        tourObj.listing[lidx].cruise_date_str_short = monthsSZ[thisMStr]+' '+thisDStr+', '+thisYStr;
662    }
663
664    var mainImageIndex = 0;
665    tourObj.has_prime_image = !tourObj.has_video;
666    tourObj.has_main_image = false;
667    if(tourObj.media.images.length && tourObj.has_prime_image) {
668        tourObj.prime_image_url = tourObj.media.images[0].url;
669        mainImageIndex++;
670    }
671
672    tourObj.max_image_assets = tourObj.media.images.length;
673    for(var idx=mainImageIndex;idx < tourObj.media.images.length; idx+=2) {
674        var add_images = { top: '', top_image_assets: '', bottom: '', bottom_image_assets: '', has_bottom: false};
675        if(idx < tourObj.media.images.length) {
676            add_images.top = tourObj.media.images[idx].url;
677            add_images.top_image_assets = idx + 1;
678        }
679        if(idx + 1 < tourObj.media.images.length) {
680            add_images.bottom = tourObj.media.images[idx+1].url;
681            add_images.bottom_image_assets = idx + 2;
682            add_images.has_bottom = true;
683        }
684        tourObj.additional_assets.push(add_images)
685    }
686    tourObj.has_menu = tourObj.menuId && tourObj.menuId.length ? true : false;
687    tourObj.has_itineraries = (tourObj.itineraries || []).length ? true : false;
688    tourObj.itinerariesData = [];
689    tourObj.portData = [];
690    tourObj.vesselData = [];
691    tourObj.cruise_data = { cruise_year: [], cruise_date: [], vessel_data: [] };
692    if(tourObj.has_itineraries) {
693        for(var itinIdx=0; itinIdx < tourObj.itineraries.length; itinIdx++) {
694            var thisItinProp = {};
695            var thisItin = tourObj.itineraries[itinIdx];
696            thisItinProp.itinID = thisItin.id;
697            thisItinProp.mapFrame = thisItin.settings.itineraryMapEmbedLink;
698            thisItinProp.has_map = (thisItinProp.mapFrame || '').length ? true : false;
699            thisItinProp.z_index = itinIdx === 0 ? 100 : 1;
700            thisItinProp.numDays = thisItin.settings.itineraryNumberOfDays;
701            thisItinProp.vesselID = thisItin.settings.vesselId;
702            thisItinProp.vessel = thisItin.vessel;
703            thisItinProp.sailing = thisItin.sailings;
704            thisItinProp.itineraryName = thisItin.localizedInfo.en.itineraryName;
705            thisItinProp.numDays = thisItin.settings.itineraryNumberOfDays;
706            thisItinProp.itineraryInternalName = thisItin.localizedInfo.en.itineraryInternalName;
707            thisItinProp.itineraryDayItem = [];
708            for(var iDayIdx=0; iDayIdx < thisItin.itineraryDayItem.length; iDayIdx++) {
709                var thisItinDay = thisItin.itineraryDayItem[iDayIdx];
710                var thisItinObj = {
711                    itineraryDayNumber: thisItinDay.settings.itineraryDayNumber,
712                    itineraryPortId: thisItinDay.settings.itineraryPortId,
713                    itineraryIncludedPortExcursions: thisItinDay.settings.itineraryIncludedPortExcursions,
714                    itineraryPremiumPortExcursions: thisItinDay.settings.itineraryPremiumPortExcursions,
715                    active: iDayIdx === 0 ? 'active' : '',
716                    show:  iDayIdx === 0 ? 'show' : '',
717                    media: thisItinDay.media,
718                    port: thisItinDay.port,
719                    excursions: thisItinDay.excursions,
720                    port_id: thisItinDay.port.id,
721                    port_name: (thisItinDay.port.localizedInfo.en !== undefined && thisItinDay.port.localizedInfo.en.portName) || '',
722                    port_int_name: (thisItinDay.port.localizedInfo.en !== undefined && thisItinDay.port.localizedInfo.en.portInternalName) || '',
723                    port_desc: (thisItinDay.port.localizedInfo.en !== undefined && thisItinDay.port.localizedInfo.en.portDescription) || '',
724                    port_image: thisItinDay.port.media.images.length ? thisItinDay.port.media.images[0].url : '',
725                    inc_excursions: [],
726                    prm_excursions: [],
727                    has_excursion: false,
728                    has_inc_exc: false,
729                    has_prm_exc: false,
730                }
731                for(var iExcIdx=0; iExcIdx < thisItinObj.excursions.length; iExcIdx++) {
732                    var thisExcursion = thisItinObj.excursions[iExcIdx];
733                    var thisExcObj = {
734                        exc_id: thisExcursion.id,
735                        exc_price_str: thisExcursion.settings.excursionDisplayPrice,
736                        exc_type: thisExcursion.settings.excursionType,
737                        exc_port_id: thisExcursion.settings.portId,
738                        exc_port_name: thisExcursion.settings.portName,
739                        exc_link: thisExcursion.settings.excursionLink,
740                        exc_name: thisExcursion.localizedInfo.en.excursionName,
741                        exc_desc: thisExcursion.localizedInfo.en.excursionDescription,
742                        exc_int_name: thisExcursion.localizedInfo.en.excursionInternalTitle,
743                        exc_image: thisExcursion.media.images.length > 0 ? thisExcursion.media.images[0].url : '',
744                        exc_has_img: thisExcursion.media.images.length > 0,
745                        exc_media: thisExcursion.media,
746                        exc_show: false,
747                    };
748                    if(thisExcObj.exc_type === 'Included') {
749                        thisExcObj.exc_idx = thisItinObj.inc_excursions.length + 1;
750                        thisExcObj.exc_show = thisItinObj.inc_excursions.length === 0;
751                        thisItinObj.inc_excursions.push(thisExcObj);
752                    } else if(thisExcObj.exc_type === 'Premium') {
753                        thisExcObj.exc_show = thisItinObj.prm_excursions.length === 0;
754                        thisExcObj.exc_idx = thisItinObj.prm_excursions.length + 1;
755                        thisItinObj.prm_excursions.push(thisExcObj);
756                    }
757                }
758                thisItinObj.has_inc_exc = thisItinObj.inc_excursions.length > 0;
759                thisItinObj.has_prm_exc = thisItinObj.prm_excursions.length > 0;
760                thisItinObj.has_excursion = thisItinObj.has_inc_exc || thisItinObj.has_prm_exc;
761                thisItinProp.itineraryDayItem.push(thisItinObj);
762            }
763            for(var iSailIdx=0; iSailIdx < thisItin.sailings.length; iSailIdx++) {
764                var thisSailingProp = {};
765                var thisSailing = thisItin.sailings[iSailIdx];
766                thisSailingProp.itineraryName = thisItinProp.itineraryName;
767                thisSailingProp.numDays = thisItinProp.numDays;
768                thisSailingProp.id = thisSailing.id;
769                thisSailingProp.voyageCode = thisSailing.settings.voyageCode;
770                thisSailingProp.sailingID = thisSailing.id;
771                thisSailingProp.vesselID = thisSailing.settings.vesselId;
772                thisSailingProp.vessel_start_date = getDateProps(thisSailing.settings.startDate);
773                thisSailingProp.vessel_date = thisSailingProp.vessel_start_date;
774                thisSailingProp.vessel_end_date = getDateProps(thisSailing.settings.endDate);
775                //thisSailingProp.startingFromPrice = thisSailing.settings.startingFromPrice;
776                //thisSailingProp.startingAtSalePrice = thisSailing.settings.startingAtSalePrice;
777
778                //thisSailingProp.startingFromPrice_str = thisSailing.settings.startingFromPrice || '';
779                thisSailingProp.startingFromPrice_str = thisSailing.settings.startingFromPrice === '' ? formatter.format(0) : formatter.format(thisSailing.settings.startingFromPrice.replace(/\$|\,/g,'').trim());
780                thisSailingProp.startingAtSalePrice_str = thisSailing.settings.startingAtSalePrice || '';
781                thisSailingProp.startingFromPrice = thisSailingProp.startingFromPrice_str.replace(/\$|\,/g,'').trim();
782                thisSailingProp.startingAtSalePrice = thisSailingProp.startingAtSalePrice_str.replace(/\$|\,/g,'').trim();
783                thisSailingProp.has_startingAtSalePrice = thisSailingProp.startingAtSalePrice.length > 0;
784                thisSailingProp.starting_save_per_couple_str = '';
785                thisSailingProp.starting_save_per_couple = 0;
786                if(thisSailingProp.has_startingAtSalePrice) {
787                    thisSailingProp.starting_save_per_couple = thisSailingProp.startingFromPrice - thisSailingProp.startingAtSalePrice;
788                    thisSailingProp.starting_save_per_couple_str = formatter.format(thisSailingProp.starting_save_per_couple);
789                }
790
791                thisSailingProp.vessel_start_port = getItineraryDayPort(thisItinProp.itineraryDayItem, 1);
792                thisSailingProp.vessel_end_port = getItineraryDayPort(thisItinProp.itineraryDayItem, thisItinProp.numDays);
793                thisSailingProp.vesselName = thisSailing.vessel.translations.en.name;
794                thisSailingProp.shortDescription = thisSailing.vessel.translations.en.shortDescription;
795                thisSailingProp.vesselMedia = thisSailing.vessel.media;
796                if(!tourObj.cruise_data.cruise_year.includes(thisSailingProp.vessel_start_date.yydate)) {
797                    tourObj.cruise_data.cruise_year.push(thisSailingProp.vessel_start_date.yydate);
798                }
799                if(!tourObj.cruise_data.cruise_date.includes(thisSailingProp.vessel_start_date.mdate)) {
800                    tourObj.cruise_data.cruise_date.push(thisSailingProp.vessel_start_date.mdate);
801                }
802                thisSailingProp.cabins = [];
803                thisSailingProp.vessel_from_original_price = "";
804                thisSailingProp.vessel_from_sale_price = "";
805                thisSailingProp.vessel_save_per_couple = "";
806                thisSailingProp.vessel_from_original_price_str = "";
807                thisSailingProp.vessel_from_sale_price_str = "";
808                thisSailingProp.vessel_save_per_couple_str = "";
809                thisSailingProp.has_vessel_from_sale_price = false;
810                for(var iCabinIdx=0; iCabinIdx < thisSailing.vessel.cabins.length; iCabinIdx++) {
811                    var thisCabin = thisSailing.vessel.cabins[iCabinIdx];
812                    var thisCabinProp = {};
813                    if(thisSailing.cabinStandardPrice[thisCabin.id] !== undefined) {
814                        thisCabinProp.id = thisCabin.id;
815                        thisCabinProp.cabin_idx = thisSailingProp.cabins.length + 1;
816                        thisCabinProp.cabin_active = thisCabinProp.cabin_idx === 1 ? true : false;
817                        thisCabinProp.cabin_id = thisCabin.id;
818                        thisCabinProp.cabin_name = thisCabin.translations.en.name;
819                        thisCabinProp.cabin_desc = thisCabin.translations.en.description;
820                        thisCabinProp.media = thisCabin.media;
821                        thisCabinProp.cabin_image = thisCabinProp.media.images.length > 0 ? thisCabinProp.media.images[0].url : '';
822                        thisCabinProp.standardPrice = thisSailing.cabinStandardPrice[thisCabin.id];
823                        thisCabinProp.salePrice = thisSailing.cabinSalePrice[thisCabin.id] || '';
824                        thisCabinProp.cabin_price_str = thisCabinProp.standardPrice.trim();
825                        thisCabinProp.cabin_price_sale_str = thisCabinProp.salePrice.trim();
826                        var thisCabinStandardPrice = thisCabinProp.cabin_price_str.replace(/\$|\,/g,'').trim();
827                        thisCabinStandardPrice = thisCabinStandardPrice.length > 0 ? parseFloat(thisCabinStandardPrice).toFixed(2) : thisCabinStandardPrice;
828                        var thisCabinSalePrice = thisCabinProp.cabin_price_sale_str.replace(/\$|\,/g,'').trim();
829                        thisCabinSalePrice = thisCabinSalePrice.length > 0 ? parseFloat(thisCabinSalePrice).toFixed(2) : thisCabinSalePrice;
830                        if( (thisCabinStandardPrice.length > 0 && thisSailingProp.vessel_from_original_price.length === 0) || (thisCabinStandardPrice.length > 0 && thisSailingProp.vessel_from_original_price.length > 0 && thisSailingProp.vessel_from_original_price > thisCabinStandardPrice)) {
831                            thisSailingProp.vessel_from_original_price = thisCabinStandardPrice;
832                            thisSailingProp.vessel_from_sale_price = thisCabinSalePrice;
833                            thisSailingProp.vessel_from_original_price_str = thisCabinProp.standardPrice.trim();
834                            thisSailingProp.vessel_from_sale_price_str = thisCabinProp.salePrice.trim();
835                            thisSailingProp.has_vessel_from_sale_price = thisSailingProp.vessel_from_sale_price.length > 0 ? true : false;
836                            if(thisSailingProp.has_vessel_from_sale_price) {
837                                thisSailingProp.vessel_save_per_couple = (thisSailingProp.vessel_from_original_price - thisSailingProp.vessel_from_sale_price) * 2;
838                                thisSailingProp.vessel_save_per_couple_str = formatter.format(thisSailingProp.vessel_save_per_couple);
839                            }
840                        }
841                        thisSailingProp.cabins.push(thisCabinProp);
842                    }
843                }
844                for(var cIdx=0; cIdx < thisSailingProp.cabins.length; cIdx++) {
845                    thisSailingProp.cabins[cIdx].prev_cabin_idx = cIdx === 0 ? thisSailingProp.cabins.length : cIdx;
846                    thisSailingProp.cabins[cIdx].next_cabin_idx = thisSailingProp.cabins.length - (cIdx + 1) > 0 ? cIdx + 2 : 1;
847                }
848                tourObj.cruise_data.vessel_data.push(thisSailingProp);
849            }
850            tourObj.itinerariesData.push(thisItinProp);
851        }
852    }
853    tourObj.cruise_data.vessel_data.sort(function (a, b) {
854        var numberToSortA = a.vessel_start_date.ymddate === null ? 0 : parseInt(a.vessel_start_date.ymddate);
855        var numberToSortB = b.vessel_start_date.ymddate === null ? 0 : parseFloat(b.vessel_start_date.ymddate);
856        return numberToSortA - numberToSortB;
857    });
858    //console.log('sortedTours',sortedTours);
859    tourObj.cruise_data.cruise_year = tourObj.cruise_data.cruise_year.sort();
860    tourObj.cruise_data.cruise_date = tourObj.cruise_data.cruise_date.sort();
861    return tourObj;
862}
863
864function populateTours() {
865    var tours = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
866    var maxCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
867    var availability = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
868    var max_show_onload = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
869    var steps_show_more = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
870    var localMyObj = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
871    var excludeList = localMyObj.exclude_list || '';
872    var lang = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'en';
873    var toursObj = {
874        listing: []
875    };
876    //console.log('localMyObj',localMyObj);
877    var numberPattern = /[\d|.]+/g;
878    var tourList = availability ? tours.available : tours.unavailable;
879    var maxTourCount = maxCount === 0 ? tourList.length : tourList.length <= maxCount ? tourList.length : maxCount;
880    max_show_onload = max_show_onload === 0 ? maxTourCount : max_show_onload;
881    var excludeArr = excludeList.split(',');
882
883    for (i = 0; i < maxTourCount; i++) {
884        var localTour = tourList[i];
885
886        if (excludeArr.indexOf(localTour.tourId) < 0 && !(localTour.isArchived||false)) {
887            localTour.liCategories = convertCategories(localTour.categories || '');
888            localTour.localizedInfo.en.shortDesc = (localTour.localizedInfo.en.shortDescription || '').replace(/\n/g, '<br />');
889            localTour.settings.displayPriceOnly = (localTour.settings.displayPrice || '').match(numberPattern);
890            localTour.settings.displayPriceSign = (localTour.settings.displayPrice || '').replace(localTour.settings.displayPriceOnly, '');
891            localTour.noMedia = localTour.media.images.length ? false : true;
892            localTour.hasTileMedia = localTour.media.tiles.length ? true : false;
893            localTour.slider_max = localTour.media.images.length;
894			localTour.has_no_price = localTour.settings.displayPriceOnly === null;
895
896            for (j = 0; j < localTour.media.images.length; j++) {
897                localTour.media.images[j].slide_num = j + 1;
898                localTour.media.images[j].active = j == 0 ? 'active' : '';
899            }
900
901            localTour.no_image = localTour.noMedia;
902            localTour.has_image = !localTour.no_image;
903            localTour.has_event_data = true; //localTour.use_filler = !localTour.has_event_data;
904
905			if(localTour.hasTileMedia) {
906				localTour.item_image = localTour.media.tiles[0].url;
907			} else if (!localTour.no_image) {
908                localTour.item_image = localTour.media.images[0].url;
909            }
910
911            localTour.item_link = localTour.permalink;
912
913            var localizedEnLang = localTour.localizedInfo['en'];
914            var localizedLang = localTour.localizedInfo[lang] || localizedEnLang;
915
916            localTour.item_name = localizedLang.title || localizedEnLang.title || 'No Title';
917            localTour.description = localizedLang.description || localizedEnLang.description || '';
918            localTour.overview = (localizedLang.description || localizedEnLang.description || '').replace(/<(?:.|\n)*?>/gm, '');
919            localTour.clean_desc = (localizedLang.description || localizedEnLang.description || '').replace(/<(?:.|\n)*?>/gm, '');
920            localTour.clean_schedule = (localizedLang.schedule || localizedEnLang.schedule || '').replace(/<(?:.|\n)*?>/gm, '');
921            localTour.slider_id = localTour.tourId;
922            localTour.show_after_click_btn = max_show_onload <= i;
923            localTour.tourReview = localTour.settings.review || '';
924            localTour.has_tourReview = localTour.tourReview.length ? true : false;
925			localTour.custom_cta_text = localMyObj.settings.custom_cta_text || 'Learn More';
926			if( (localMyObj.settings.coming_soon_cta || []).includes(localTour.bookingTypeId) ) {
927				localTour.custom_cta_text = 'On Sale starting July 11th';
928			}
929            toursObj.listing.push(localTour);
930        }
931    }
932
933    return toursObj;
934}
935
936function convertCategories(categories) {
937    var cat = [];
938    categories.split(',').map(function (category) {
939        cat.push(category.trim().replace(/ |\'/g, '-'));
940    });
941    return cat.join(' ');
942}
943
944function build_nav_script_js(listingID, listingName) {
945    window[listingID + '_mainObj'] = jQuery( listingName );
946    window[listingID + '_ulScrollObj'] = jQuery( listingName + ' .glisting-container' );
947    window[listingID + '_ulWrapObj'] = jQuery( listingName + ' .glisting-content' );
948    window[listingID + '_ulObj'] = jQuery( listingName + ' .glisting-content ul.glisting' );
949    window[listingID + '_next'] = jQuery( listingName + ' .nav-arrow a.next' );
950    window[listingID + '_prev'] = jQuery( listingName + ' .nav-arrow a.prev' );
951    window[listingID + '_next'].on('click', function(e) {
952        console.log('clicked next');
953        e.preventDefault();
954        console.log('_mainObj',window[listingID + '_mainObj']);
955        console.log('_ulScrollObj',window[listingID + '_ulScrollObj']);
956        console.log('_ulWrapObj',window[listingID + '_ulWrapObj']);
957        console.log('_ulObj',window[listingID + '_ulObj']);
958        console.log('_next',window[listingID + '_next']);
959        console.log('_prev',window[listingID + '_prev']);
960        nextBtn_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
961    });
962    window[listingID + '_prev'].on('click', function(e) {
963        console.log('clicked prev');
964        e.preventDefault();
965        prevBtn_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
966    });
967    window[listingID + '_ulScrollObj'].on('scroll', function(e) {
968        console.log('scrolled');
969        updateExpNav_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
970    });
971    updateExpNav_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
972}
973
974function build_nav_assets_script_js(listingID, listingName) {
975    window[listingID + '_mainObj'] = jQuery( listingName );
976    window[listingID + '_ulScrollObj'] = jQuery( listingName + ' .event-assets' );
977    window[listingID + '_ulWrapObj'] = jQuery( listingName + ' .assets-wrapper' );
978    window[listingID + '_ulObj'] = jQuery( listingName + ' .assets-wrapper ul.assets-list' );
979    window[listingID + '_next'] = jQuery( listingName + ' .nav-arrow a.next' );
980    window[listingID + '_prev'] = jQuery( listingName + ' .nav-arrow a.prev' );
981    window[listingID + '_next'].on('click', function(e) {
982        console.log('clicked next');
983        e.preventDefault();
984        nextBtn_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
985    });
986    window[listingID + '_prev'].on('click', function(e) {
987        console.log('clicked prev');
988        e.preventDefault();
989        prevBtn_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
990    });
991    window[listingID + '_ulScrollObj'].on('scroll', function(e) {
992        console.log('scrolled');
993        updateExpNav_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
994    });
995    updateExpNav_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
996}
997
998function addTourListFilterAction(name, show_nav, listingID) {
999    var alink = jQuery('.hbg-display-tour-listing.' + name + ' ul.filter-list li a.detach-filter').on('click', function(e) {
1000        e.preventDefault();
1001        jQuery('.hbg-display-tour-listing.' + name + ' ul.filter-list li a.detach-filter').removeClass('active');
1002        jQuery(this).addClass('active');
1003        var filterName = jQuery(this).attr('data-class');
1004        jQuery('.hbg-display-tour-listing.' + name + ' .glisting-content.nav ul.glisting li.glisting-item').addClass('hide');
1005        jQuery('.hbg-display-tour-listing.' + name + ' .glisting-container .loading-event').fadeIn( 'slow', function() {
1006            jQuery('.hbg-display-tour-listing.' + name + ' .glisting-content.nav').attr('style', '');
1007            jQuery('.hbg-display-tour-listing.' + name + ' .glisting-container .loading-event').fadeOut( 'slow', function() {
1008                if(filterName !== '') {
1009                    jQuery('.hbg-display-tour-listing.' + name + ' .glisting-content.nav ul.glisting li.glisting-item.' + filterName).removeClass('hide');
1010                } else {
1011                    jQuery('.hbg-display-tour-listing.' + name + ' .glisting-content.nav ul.glisting li.glisting-item').removeClass('hide');
1012                }
1013                if(show_nav) {
1014                    updateExpNav_listing(window[listingID + '_mainObj'], window[listingID + '_ulWrapObj'], window[listingID + '_ulObj'], window[listingID + '_prev'], window[listingID + '_next']);
1015                }
1016            });
1017        });
1018    });
1019}
1020
1021function prepareImgWrapWithSlider() {
1022    var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1023
1024    if (id.length > 0) {
1025        jQuery('#' + id + '.img-wrap.with-slider a.prev').on('click', function (e) {
1026            e.preventDefault();
1027            var wrapperID = jQuery(this).attr('wrapper-id');
1028            var curSlide = parseInt(jQuery('#' + wrapperID).attr('slider-cur'));
1029            var curNextSlide = parseInt(jQuery('#' + wrapperID).attr('slider-next'));
1030            var maxSlide = parseInt(jQuery('#' + wrapperID).attr('slider-max'));
1031
1032            if (curSlide === curNextSlide) {
1033                var nextSlide = curSlide - 1;
1034
1035                if (nextSlide <= 0) {
1036                    nextSlide = maxSlide;
1037                }
1038
1039                jQuery('#' + wrapperID).attr('slider-next', nextSlide);
1040                sliderActionRight(wrapperID, curSlide, nextSlide, maxSlide);
1041            }
1042        });
1043        jQuery('#' + id + '.img-wrap.with-slider a.next').on('click', function (e) {
1044            e.preventDefault();
1045            var wrapperID = jQuery(this).attr('wrapper-id');
1046            var curSlide = parseInt(jQuery('#' + wrapperID).attr('slider-cur'));
1047            var curNextSlide = parseInt(jQuery('#' + wrapperID).attr('slider-next'));
1048            var maxSlide = parseInt(jQuery('#' + wrapperID).attr('slider-max'));
1049
1050            if (curSlide === curNextSlide) {
1051                var nextSlide = curSlide + 1;
1052
1053                if (nextSlide > maxSlide) {
1054                    nextSlide = 1;
1055                }
1056
1057                jQuery('#' + wrapperID).attr('slider-next', nextSlide);
1058                sliderActionLeft(wrapperID, curSlide, nextSlide, maxSlide);
1059            }
1060        });
1061        jQuery('#' + id + '.img-wrap.with-slider a.radio').on('click', function (e) {
1062            e.preventDefault();
1063            var wrapperID = jQuery(this).attr('wrapper-id');
1064            var curSlide = parseInt(jQuery('#' + wrapperID).attr('slider-cur'));
1065            var curNextSlide = parseInt(jQuery('#' + wrapperID).attr('slider-next'));
1066            var maxSlide = parseInt(jQuery('#' + wrapperID).attr('slider-max'));
1067            var nextSlide = jQuery(this).attr('slide-id');
1068
1069            if (curSlide === curNextSlide && curSlide != nextSlide) {
1070                if (curSlide < nextSlide) {
1071                    jQuery('#' + wrapperID).attr('slider-next', nextSlide);
1072                    sliderActionLeft(wrapperID, curSlide, nextSlide, maxSlide);
1073                } else {
1074                    jQuery('#' + wrapperID).attr('slider-next', nextSlide);
1075                    sliderActionRight(wrapperID, curSlide, nextSlide, maxSlide);
1076                }
1077            }
1078        });
1079    }
1080}
1081
1082function topFunction() {
1083    document.body.scrollTop = 0; // For Safari
1084
1085    document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
1086}
1087
1088function gravityFormRearrange(bObj) {
1089    gBody = jQuery(bObj).find('div.gform_body'); //console.log('calling gravityFormRearrange',bObj);
1090
1091    if (gBody) {
1092        jQuery(gBody).find('ul.gform_fields li.gfield').each(function () {
1093            var labelTag = jQuery(this).find('label');
1094            var divTag = jQuery(this).find('div.ginput_container');
1095
1096            if (divTag.hasClass('ginput_container_text') || divTag.hasClass('ginput_container_phone') || divTag.hasClass('ginput_container_email') || divTag.hasClass('ginput_container_textarea')) {
1097                divTag.addClass('mui-textfield mui-textfield--float-label');
1098                divTag.append(labelTag);
1099            } else if (divTag.hasClass('ginput_container_select')) {
1100                divTag.addClass('mui-select');
1101                divTag.append(labelTag);
1102            } else if (divTag.hasClass('ginput_container_date')) {
1103                //divTag.addClass('mui-textfield');
1104                //divTag.append(labelTag);
1105            }
1106
1107        });
1108    }
1109}
1110
1111function populateFleets() {
1112    var fleets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1113    var excludeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1114    var maxCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1115    var max_show_onload = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1116    //console.log('populateFleets');
1117    var fleetsObj = {
1118        listing: []
1119    };
1120    var maxFleetCount = maxCount === 0 ? fleets.length : fleets.length <= maxCount ? fleets.length : maxCount;
1121    exArr = excludeList.split(',');
1122    max_show_onload = max_show_onload === 0 ? maxFleetCount : max_show_onload;
1123
1124    for (idx = 0; idx < maxFleetCount; idx++) {
1125        var localFleet = fleets[idx];
1126
1127        if (exArr.indexOf(localFleet.id) == -1) {
1128            /*
1129            localFleet.fleet_images = (localFleet.media || []);
1130            localFleet.noMedia = (localFleet.media.images.length ? false : true);
1131            localFleet.no_image = localFleet.noMedia;
1132            localFleet.has_image = !localFleet.no_image;
1133            localFleet.slider_max = localFleet.media.images.length;
1134            for(j=0;j<localFleet.media.images.length;j++) {
1135                localFleet.media.images[j].slide_num = j + 1;
1136                localFleet.media.images[j].active = (j == 0 ? 'active' : '');
1137            }
1138            localFleet.slider_id = localFleet.id;
1139            localFleet.item_link = (localFleet.vesselDetails.permalink || '');
1140            localFleet.item_name = (localFleet.translations.en.name || 'No Title');
1141            localFleet.description = (localFleet.translations.en.description || '');
1142            localFleet.shortDescription = (localFleet.translations.en.shortDescription || '');
1143            localFleet.fleet_overview = localFleet.shortDescription.replace(/<(?:.|\n)*?>/gm, '');
1144            localFleet.has_fleet_data = true;
1145            if(!localFleet.no_image) {
1146                localFleet.item_image = localFleet.media.images[0].url;
1147            }
1148            delete localFleet.media;
1149            localFleet.buffetMealsCapacity = (localFleet.vesselDetails.buffetMealsCapacity || 0);
1150            localFleet.cocktailsCapacity = (localFleet.vesselDetails.cocktailsCapacity || 0);
1151            localFleet.seatedMealsCapacity = (localFleet.vesselDetails.seatedMealsCapacity || 0);
1152            localFleet.fleet_capacity = 'CAPACITY: UP TO ' + Math.max(localFleet.buffetMealsCapacity, localFleet.cocktailsCapacity, localFleet.seatedMealsCapacity) + ' GUESTS';
1153            */
1154            localFleet.show_after_click_btn = max_show_onload < fleetsObj.listing.length + 1;
1155            fleetsObj.listing.push(populateFleet(localFleet));
1156        }
1157    } //console.log('fleetsObj.listing',fleetsObj.listing);
1158
1159
1160    return fleetsObj;
1161}
1162
1163function populateFleet() {
1164    var fleet = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1165    //console.log('fleetfleetfleetfleetfleetfleetfleetfleet', fleet);
1166    var fleetObj = fleet;
1167
1168    if (!jQuery.isEmptyObject(fleet)) {
1169        fleetObj.fleet_has_image = fleetObj.media.images.length > 0;
1170        fleetObj.has_image = fleetObj.fleet_has_image;
1171        fleetObj.fleet_has_video = fleetObj.media.videos.length > 0;
1172        fleetObj.fleet_has_virtual = fleetObj.media.virtualTour.length > 0;
1173
1174        for (i = 0; i < fleetObj.media.images.length; i++) {
1175            fleetObj.media.images[i].item_num = i + 1;
1176            fleetObj.media.images[i].active = i == 0 ? 'active' : '';
1177            fleetObj.media.images[i].item_image = fleetObj.media.images[i].url;
1178        }
1179
1180        for (k = 0; k < fleetObj.media.videos.length; k++) {
1181            fleetObj.media.videos[k].item_num = k + 1;
1182            fleetObj.media.videos[k].active = k == 0 ? 'active' : '';
1183            fleetObj.media.videos[k].video_url = jQuery(fleetObj.media.videos[k].url).attr('src');
1184        }
1185
1186        fleetObj.item_name = fleetObj.translations.en.name || 'No Title';
1187        fleetObj.fleet_main_images = fleetObj.media.images;
1188        fleetObj.fleet_main_image = fleetObj.media.images.length > 0 ? fleetObj.media.images.slice(0, 1) : {};
1189        fleetObj.fleet_additional_images = fleetObj.media.images.slice(1, fleetObj.media.images.length);
1190        fleetObj.main_id = 'main-' + fleetObj.id;
1191        fleetObj.main_max_image = fleetObj.media.images.length;
1192        fleetObj.has_deck = fleetObj.decks.length > 0 ? true : false;
1193        fleetObj.item_link = fleetObj.details.permalink || '';
1194        fleetObj.buffetMealsCapacity = fleetObj.details.buffetMealsCapacity || 0;
1195        fleetObj.cocktailsCapacity = fleetObj.details.cocktailsCapacity || 0;
1196        fleetObj.seatedMealsCapacity = fleetObj.details.seatedMealsCapacity || 0;
1197        fleetObj.has_buffetMealsCapacity = fleetObj.details.buffetMealsCapacity != null || false;
1198        fleetObj.has_cocktailsCapacity = fleetObj.details.cocktailsCapacity != null || false;
1199        fleetObj.has_seatedMealsCapacity = fleetObj.details.seatedMealsCapacity != null || false;
1200        fleetObj.fleet_capacity = 'CAPACITY: UP TO ' + Math.max(fleetObj.buffetMealsCapacity, fleetObj.cocktailsCapacity, fleetObj.seatedMealsCapacity) + ' GUESTS';
1201        fleetObj.slider_id = fleetObj.id;
1202        fleetObj.shortDescription = fleetObj.translations.en.shortDescription || '';
1203        fleetObj.description = fleetObj.translations.en.description || '';
1204        fleetObj.reviews = fleetObj.translations.en.reviews || '';
1205        fleetObj.fleet_overview = fleetObj.shortDescription.replace(/<(?:.|\n)*?>/gm, '');
1206        fleetObj.fleet_clean_desc = fleetObj.description.replace(/<(?:.|\n)*?>/gm, '');
1207        fleetObj.fleet_has_shortDescription = fleetObj.shortDescription.length ? true : false;
1208        fleetObj.fleet_has_description = fleetObj.description.length ? true : false;
1209        fleetObj.fleet_has_reviews = fleetObj.reviews.length ? true : false;
1210        fleetObj.has_fleet_data = true;
1211
1212        for (j = 0; j < fleetObj.decks.length; j++) {
1213            fleetObj.decks[j].active = j == 0 ? 'active' : '';
1214            fleetObj.decks[j].show = j == 0 ? 'in' : '';
1215            fleetObj.decks[j].odd_row = j % 2 ? false : true;
1216            fleetObj.decks[j].even_row = !fleetObj.decks[j].odd_row;
1217            fleetObj.decks[j].deck_has_media = fleetObj.decks[j].media.images.length > 0;
1218
1219            for (k = 0; k < fleetObj.decks[j].media.images.length; k++) {
1220                fleetObj.decks[j].media.images[k].item_num = k + 1;
1221                fleetObj.decks[j].media.images[k].active = k == 0 ? 'active' : '';
1222                fleetObj.decks[j].media.images[k].item_image = fleetObj.decks[j].media.images[k].url;
1223            }
1224
1225            fleetObj.decks[j].deck_has_video = fleetObj.decks[j].media.videos.length > 0;
1226
1227            for (l = 0; l < fleetObj.decks[j].media.videos.length; l++) {
1228                fleetObj.decks[j].media.videos[l].item_num = l + 1;
1229                fleetObj.decks[j].media.videos[l].active = l == 0 ? 'active' : '';
1230                fleetObj.decks[j].media.videos[l].video_url = jQuery(fleetObj.media.videos[l].url).attr('src');
1231            }
1232
1233            fleetObj.decks[j].deck_has_virtual = fleetObj.decks[j].media.virtualTour.length > 0;
1234            fleetObj.decks[j].deck_media = fleetObj.decks[j].media;
1235            fleetObj.decks[j].deck_has_buffetMealsCapacity = fleetObj.decks[j].details.buffetMealsCapacity != null || false;
1236            fleetObj.decks[j].deck_has_cocktailsCapacity = fleetObj.decks[j].details.cocktailsCapacity != null || false;
1237            fleetObj.decks[j].deck_has_seatedMealsCapacity = fleetObj.decks[j].details.seatedMealsCapacity != null || false;
1238            delete fleetObj.decks[j].media;
1239        }
1240
1241        fleetObj.fleet_media = fleetObj.media;
1242        delete fleetObj.media;
1243    } //console.log('fleetObj',fleetObj);
1244
1245
1246    return fleetObj;
1247}
1248
1249function sliderActionLeft(id, cur, final, max) {
1250    var slideLen = jQuery('#' + id).width();
1251    var next = cur + 1;
1252
1253    if (next > max) {
1254        next = 1;
1255    }
1256
1257    jQuery('#' + id + ' .slide-wrapper.slide-' + next).addClass('next');
1258    jQuery('#' + id + ' .slide-wrapper.slide-' + cur).animate({
1259        "left": '-=' + slideLen,
1260        "easing": "linear"
1261    }, 700, function () {
1262        jQuery('#' + id).attr('slider-cur', next);
1263        jQuery('#' + id + ' .slide-wrapper.slide-' + cur).removeClass('active').attr('style', '');
1264        jQuery('#' + id + ' .slide-wrapper.slide-' + next).addClass('active').removeClass('next');
1265        updateRadioSlider(id, next);
1266
1267        if (next < final) {
1268            sliderActionLeft(id, next, final, max);
1269        }
1270    });
1271}
1272
1273function sliderActionRight(id, cur, final, max) {
1274    var slideLen = jQuery('#' + id).width();
1275    var next = cur - 1;
1276
1277    if (next <= 0) {
1278        next = max;
1279    }
1280
1281    jQuery('#' + id + ' .slide-wrapper.slide-' + next).addClass('active').attr('style', 'left: -' + slideLen + 'px');
1282    jQuery('#' + id + ' .slide-wrapper.slide-' + cur).removeClass('active').addClass('next');
1283    jQuery('#' + id + ' .slide-wrapper.slide-' + next).animate({
1284        "left": '+=' + slideLen,
1285        "easing": "linear"
1286    }, 700, function () {
1287        jQuery('#' + id).attr('slider-cur', next);
1288        jQuery('#' + id + ' .slide-wrapper.slide-' + cur).removeClass('next');
1289        updateRadioSlider(id, next);
1290
1291        if (next > final) {
1292            sliderActionRight(id, next, final, max);
1293        }
1294    });
1295}
1296
1297function updateRadioSlider(id, active) {
1298    jQuery('#' + id + ' .nav-radio a.radio').removeClass('active');
1299    jQuery('#' + id + ' .nav-radio a.radio.radio-' + active).addClass('active');
1300    jQuery('#' + id + ' .thumb-wrapper a.radio').removeClass('active');
1301    jQuery('#' + id + ' .thumb-wrapper a.radio.radio-' + active).addClass('active');
1302}
1303
1304function returnAllPortName() {
1305    var portNames = [];
1306    portNames['hbmdr'] = 'Marina del Rey';
1307    portNames['hbsf'] = 'San Francisco';
1308    portNames['hbber'] = 'Berkeley';
1309    portNames['hblb'] = 'Long Beach';
1310    portNames['hbsd'] = 'San Diego';
1311    portNames['hbnpb'] = 'Newport Beach';
1312    portNames['hbsac'] = 'Sacramento';
1313    portNames['hbny'] = 'New York';
1314    return portNames;
1315}
1316
1317function rearrangePortList() {
1318    var portList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1319    var arrangedPortList = [];
1320    var socal = ['hbmdr', 'hblb', 'hbnpb'];
1321    var norcal = ['hbsf', 'hbber', 'hbsac'];
1322
1323    if (socal.includes(portList[0].id)) {
1324        var mainSocalPort = 'hbmdr';
1325
1326        if (portList[0].id != mainSocalPort && portList[1].id == mainSocalPort) {
1327            var tmpPort = portList[0];
1328            portList[0] = portList[1];
1329            portList[1] = tmpPort;
1330        } else if (portList[0].id != mainSocalPort && portList[2].id == mainSocalPort) {
1331            var tmpPort = portList[0];
1332            portList[0] = portList[2];
1333            portList[2] = tmpPort;
1334        }
1335    }
1336
1337    if (norcal.includes(portList[0].id)) {
1338        var mainNorcalPort = 'hbsf';
1339
1340        if (portList[0].id != mainNorcalPort && portList[1].id == mainNorcalPort) {
1341            var tmpPort = portList[0];
1342            portList[0] = portList[1];
1343            portList[1] = tmpPort;
1344        } else if (portList[0].id != mainNorcalPort && portList[2].id == mainNorcalPort) {
1345            var tmpPort = portList[0];
1346            portList[0] = portList[2];
1347            portList[2] = tmpPort;
1348        }
1349    }
1350
1351    return portList;
1352}
1353
1354function assignListingByTagList() {
1355    var listing = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1356    var tagList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1357    var newListing = [];
1358
1359    for (tagIdx = 0; tagIdx < tagList.length; tagIdx++) {
1360        curLTagName = tagList[tagIdx].ltag_name;
1361        newListing[tagIdx] = {
1362            listing: [],
1363            tag_id: tagList[tagIdx].tag_id,
1364            tag_name: tagList[tagIdx].tag_name,
1365            tag_code: tagList[tagIdx].tag_code,
1366            ltag_name: tagList[tagIdx].ltag_name
1367        };
1368
1369        for (listIdx = 0; listIdx < listing.length; listIdx++) {
1370            var thisCatArr = (listing[listIdx].categories || '').split(",");
1371            if(thisCatArr.includes(curLTagName)) {
1372                newListing[tagIdx].listing.push(listing[listIdx]);
1373            }
1374        }
1375
1376        newListing[tagIdx].port_has_data = newListing[tagIdx].listing.length > 0;
1377    }
1378
1379    return newListing;
1380}
1381
1382function generateTagList() {
1383    var tagList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1384    var tagProp = [];
1385    //var portNames = returnAllPortName();
1386    var tagNames = [];
1387    var thisPortName = '';
1388
1389    for (idx = 0; idx < tagList.length; idx++) {
1390        tagProp[idx] = {
1391            tag_name: tagList[idx].tag_name,
1392            tag_code: tagList[idx].tag_code,
1393            ltag_name: tagList[idx].tag_name.toLowerCase(),
1394            tag_id: tagList[idx].tag_id
1395        };
1396    }
1397    //console.log('tagProptagProptagProptagProp',tagProp);
1398
1399    return tagProp;
1400}
1401
1402function dateSelectionButton(id, dropId) {
1403    jQuery('button#'+id).on('click', function() {
1404        location.href = jQuery('#'+dropId).val();
1405    });
1406}
1407
1408function enableDepartureMonths(data) {
1409    //months-wrapper
1410    //console.log('data enableDepartureMonths', data);
1411    for(var mIdx=0; mIdx < data.length; mIdx++) {
1412        jQuery('a.select-departure-month[data-role='+data[mIdx]+']').removeClass('disabled');
1413    }
1414}
1415
1416function selectedDepartureMonth(selMonth) {
1417    //console.log('selMonth',selMonth);
1418    if(selMonth != null && selMonth.length && !jQuery('a.select-departure-month[data-role='+selMonth+']').hasClass('disabled')) {
1419        jQuery('a.select-departure-month[data-role='+selMonth+']').addClass('selected');
1420    }
1421}
1422
1423function enableTriggerSelectDepartureMonth() {
1424    jQuery('a.select-departure-month').on('click', function(e) {
1425        e.preventDefault();
1426        if(!jQuery(this).hasClass('disabled')) {
1427            var thisClicked = jQuery(this).attr('data-role');
1428            var thisHide = jQuery(this).hasClass('selected') ? true : false;
1429            if(thisHide) {
1430                jQuery('div[data-myear='+thisClicked+']').addClass('hide');
1431                jQuery(this).removeClass('selected');
1432            } else {
1433                jQuery('div[data-myear='+thisClicked+']').removeClass('hide');
1434                jQuery(this).addClass('selected');
1435            }
1436        }
1437    });
1438}
1439
1440function triggerNavLinkShortcut() {
1441    jQuery('a.nav-link-shortcut').on('click', function(e) {
1442        e.preventDefault();
1443        //if (this.hash !== "" && jQuery(this.hash).length) {
1444        console.log(this.hash);
1445        //jQuery(this.hash).tab('show');
1446        jQuery('#myTab a[href="'+this.hash+'"]').tab('show')
1447    });
1448}
1449
1450function getUrlVars() {
1451    var vars = {};
1452    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
1453        vars[key] = value;
1454    });
1455    return vars;
1456}
1457
1458function getUrlParam(parameter, defaultvalue){
1459    var urlparameter = defaultvalue;
1460    if(window.location.href.indexOf(parameter) > -1){
1461        urlparameter = getUrlVars()[parameter];
1462    }
1463    return urlparameter;
1464}
1465
1466function mergeDownListing(filterArr) {
1467    var newFilterArr = [];
1468    var keysArr = Object.keys(filterArr);
1469    for(var keyIdx=0; keyIdx < keysArr.length; keyIdx++) {
1470        newFilterArr = newFilterArr.concat(filterArr[keysArr[keyIdx]]);
1471    }
1472    //console.log('newFilterArr',newFilterArr);
1473    return newFilterArr;
1474}
1475
1476function filterByPromotion(filterArr, usePromoID, promoID) {
1477    var promoArr = [];
1478    for(var idx=0; idx < filterArr.length; idx++) {
1479        if( (filterArr[idx]['has_promotion'] && !usePromoID) || (usePromoID && filterArr[idx]['has_promotion'] && filterArr[idx]['promotions'].includes(promoID)) ) {
1480            promoArr.push(filterArr[idx]);
1481        }
1482    }
1483    //console.log('promoID', promoID);
1484    //console.log('promoArr', promoArr);
1485    return promoArr;
1486}
1487
1488function filterListingByBookingID(allArr, filterArr, hasDateParam) {
1489    //console.log('allArr',allArr);
1490    //console.log('filterArr',filterArr);
1491    var allByBookingID = [];
1492    for(var allIdx=0; allIdx < allArr.length; allIdx++) {
1493        allByBookingID[allArr[allIdx].bookingTypeId] = allArr[allIdx];
1494    }
1495    //console.log('allByBookingID',allByBookingID);
1496    var newArr = [];
1497    var filterArr2 = [];
1498    for(var filterIdx=0; filterIdx < filterArr.length; filterIdx++) {
1499        filterArr[filterIdx] = jQuery.extend( filterArr[filterIdx], allByBookingID[filterArr[filterIdx].booking_type_id] );
1500        filterArr[filterIdx]['depart_date_sort'] = filterArr[filterIdx]['depart_date'].phpdate;
1501    }
1502    filterArr = filterArr.sort(function (a, b) {
1503        var numberToSortA = a.depart_date_sort === null ? 0 : parseInt(a.depart_date_sort);
1504        var numberToSortB = b.depart_date_sort === null ? 0 : parseInt(b.depart_date_sort);
1505        return numberToSortA - numberToSortB;
1506    });
1507    return filterArr;
1508}
1509
1510function populateMonthsAndSelected(selObj, selMonth) {
1511    //console.log('selObj',selObj);
1512    //console.log('selMonth',selMonth);
1513    var now = new Date();
1514    var thisMonth = now.getMonth() + 1;
1515    var thisYear = now.getFullYear();
1516    var dateVal = '';
1517    var dateStr = '';
1518    for(var monthIdx=0; monthIdx < 24; monthIdx++) {
1519        if(thisMonth == 13) {
1520            thisMonth = 1;
1521            thisYear += 1;
1522        }
1523        dateStr = monthsLZ[thisMonth] + ' ' + thisYear;
1524        dateVal = thisYear + '-' + (thisMonth < 10 ? '0' + thisMonth : thisMonth);
1525        selObj.append(new Option(dateStr, dateVal, selMonth===dateVal, selMonth===dateVal));
1526        thisMonth += 1;
1527    }
1528}
1529
1530function addOnClickAnchor(id) {
1531    jQuery( '#' + id + ' a.anchor-to-deck' ).on('click', function(e) {
1532        e.preventDefault();
1533        if (this.hash !== "") {
1534            //console.log('jQuery(this.hash)',jQuery(this.hash));
1535            jQuery('html, body').animate({
1536                scrollTop: jQuery(this.hash).offset().top - document.getElementById('masthead').offsetHeight - 50
1537            }, 800, function(e){
1538            });
1539        }
1540    });
1541}
1542
1543function generateTopInAppBannerHTML_local(bannerObj) {
1544	var topBannerHTML = '';
1545	if (bannerObj.length) {
1546		topBannerHTML += '<div class="container">';
1547		topBannerHTML += '<div class="banner-text-wrapper">';
1548		for(var i=0; i < bannerObj.length; i++) {
1549			var thisInAppObj = bannerObj[i];
1550			topBannerHTML += '<div class="each-inApp-notification">' + thisInAppObj.notificationBody + '</div>';
1551		}
1552		topBannerHTML += '</div>';
1553		topBannerHTML += '</div>';
1554		jQuery('div.top-banner-wrapper').removeClass('hide');
1555	}
1556	jQuery('div.top-banner-wrapper').html(topBannerHTML);
1557	jQuery('.followWrap').attr('style','height: '+jQuery('header').height()+'px;');
1558}
1559
1560function closeMobileNav() {
1561	jQuery('body').removeClass('onepress-menu-mobile-opening');
1562	jQuery('ul.onepress-menu').removeClass('onepress-menu-mobile');
1563	jQuery('ul.onepress-menu').attr('style', '');
1564	jQuery('#nav-toggle').removeClass('nav-is-visible');
1565}
1566
1567function getCartItems() {
1568    var anchorMetaStr = decodeURIComponent(getCookie('_anchorcidmeta'));
1569    return isJson(anchorMetaStr) ? JSON.parse(anchorMetaStr) : { };
1570}
1571
1572function getCartCount() {
1573    var anchorMeta = getCartItems();
1574    return anchorMeta.totalItems !== undefined ? anchorMeta.totalItems : 0;
1575}
1576
1577function anchorCartChange(itemsTotal) {
1578    if(itemsTotal > 0) {
1579        jQuery('.cart-total').addClass('show');
1580        jQuery('.cart-total').html(itemsTotal);
1581		jQuery('li.cart-mobile > a').html('Cart (' + itemsTotal + ')');
1582    } else {
1583        jQuery('.cart-total').removeClass('show');
1584        jQuery('.cart-total').html('');
1585		jQuery('li.cart-mobile > a').html('Cart');
1586    }
1587}
1588
1589function update_cart_count_in_nav() {
1590	anchorCartChange(getCartCount());
1591}
1592
1593function updateScheduleTable(scheduleUrl, bookId) {
1594	jQuery.ajax({
1595		dataType: "json",
1596		url: scheduleUrl,
1597		success: function (scheduleList) {
1598			console.log('scheduleList', scheduleUrl, scheduleList, typeof scheduleList === 'object');
1599			if (typeof scheduleList === 'object') {
1600				generateScheduleTable(scheduleList, bookId);
1601			}
1602		},
1603		error: function (jqXHR, error, errorThrown) {
1604			if (jqXHR.status && jqXHR.status == 400) {
1605				console.log(jqXHR.responseText);
1606			} else {
1607				console.log("Something went wrong - ", error);
1608				jQuery('.ferry-schedule-day[data-id='+bookId+']').html('<p>There is no schedule on this date</p>');
1609			}
1610		},
1611	});
1612}
1613
1614function reformatScheduleTime(str) {
1615	str = str.replace(/^00/, '12');
1616	str = str.replace(/^13/, '01');
1617	str = str.replace(/^14/, '02');
1618	str = str.replace(/^15/, '03');
1619	str = str.replace(/^16/, '04');
1620	str = str.replace(/^17/, '05');
1621	str = str.replace(/^18/, '06');
1622	str = str.replace(/^19/, '07');
1623	str = str.replace(/^20/, '08');
1624	str = str.replace(/^21/, '09');
1625	str = str.replace(/^22/, '10');
1626	str = str.replace(/^23/, '11');
1627	//console.log('str', str);
1628	return str;
1629}
1630
1631function generateScheduleTable(scheduleList, bookId) {
1632	var jsonKeys = Object.keys(scheduleList);
1633	var scheHtml = '<table class="schedule-ferry"><tr>';
1634	for(var idx = 0; idx < jsonKeys.length; idx++) {
1635		scheHtml += '<th>'+jsonKeys[idx]+'</th>';
1636	}
1637	scheHtml += '</tr>';
1638	var done = false;
1639	var counter = 0;
1640	while(!done) {
1641		var stillHasData = false;
1642		var thisDataHtml = '';
1643		for(var idx = 0; idx < jsonKeys.length; idx++) {
1644			var thisSche = scheduleList[jsonKeys[idx]].length > counter ? scheduleList[jsonKeys[idx]][counter] : { };
1645			var thisTime = thisSche.time || '';
1646			thisTime = reformatScheduleTime(thisTime);
1647			thisDataHtml += '<td>
1647'+thisTime+'</td>';
1648			stillHasData = thisTime.length || stillHasData;
1649		}
1650		if(stillHasData) {
1651			scheHtml += '<tr>' + thisDataHtml + '</tr>';
1652		}
1653		counter++;
1654		if(!stillHasData || counter >= 100) {
1655			done = true;
1656		}
1657	}
1658	scheHtml += '</table>';
1659	var divId = '.ferry-schedule-day[data-id='+bookId+']';
1660	//console.log('generateScheduleTable', scheduleList, divId);
1661	jQuery(divId).html(scheHtml);
1662}
1663
1664(function ($) {
1665    'use strict';
1666
1667    $(document).ready(function () {
1668		
1669		anchorCartChange(getCartCount());
1670
1671        $(document).on('click', '[data-toggle="lightbox"]', function (event) {
1672            event.preventDefault();
1673            $(this).ekkoLightbox({
1674                alwaysShowClose: true
1675            });
1676        });
1677		
1678		$(window).click(function() {
1679			
1680			//console.log('start clicking');
1681			if($('.left-menu-wrapper').hasClass('open')) {
1682				$('.left-menu-wrapper').removeClass('open');
1683			}
1684		});
1685		
1686		$('.mobile-placeholder-nav').on('click', function(e) {
1687			//console.log('placeholder');
1688			e.preventDefault();
1689			closeMobileNav();
1690			event.stopPropagation();
1691		});
1692		
1693		
1694		$('nav.main-navigation').on('click', function(e) {
1695			//console.log('nav');
1696			//e.preventDefault();
1697			//event.stopPropagation();
1698		});
1699		
1700		$('ul.onepress-menu li.mobile-close > a').on('click', function(e) {
1701			e.preventDefault();
1702			closeMobileNav();
1703			event.stopPropagation();
1704		});
1705
1706		$('a.left-menu-icon-link').on('click', function(e) {
1707			e.preventDefault();
1708			event.stopPropagation();
1709			if(!$('.left-menu-wrapper').hasClass('open')) {
1710				$('.left-menu-wrapper').addClass('open')
1711			}
1712		});
1713		$('a.left-menu-close-link').on('click', function(e) {
1714			e.preventDefault();
1715			event.stopPropagation();
1716			if($('.left-menu-wrapper').hasClass('open')) {
1717				$('.left-menu-wrapper').removeClass('open')
1718			}
1719		});
1720		
1721		$('.left-menu-wrapper').on('click', function(e) {
1722			event.stopPropagation();
1723		})
1724		
1725		$('a.switch-listing-action').on('click', function(e) {
1726			e.preventDefault();
1727			if(!$(this).hasClass('active')) {
1728				let thisGroup = $(this).attr('data-group');
1729				let thisId = $(this).attr('data-id');
1730				$('a.switch-listing-action[data-group='+thisGroup+']').removeClass('active');
1731				$(this).addClass('active');
1732				$('li[group-data='+thisGroup+']').removeClass('active');
1733				$('li#'+thisId).addClass('active');
1734			}
1735		});
1736		
1737		$('ul.hbg-block-faq-function li h4.faq-question').on('click', function(e) {
1738			e.preventDefault();
1739			var thisGroup = $(this).attr('data-group');
1740			var thisId = $(this).attr('data-id');
1741			$('ul#'+thisGroup+' .faq-answer').removeClass('active');
1742			$('ul#'+thisGroup+' .faq-answer.'+thisId).addClass('active');
1743		});
1744		
1745    });
1746})(jQuery);
1747
1748

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.