const initPannellum = function() {

	// init for shortcodes
	const scriptTag = document.getElementById('wp_virtualtour_script-js-extra')
	if (!scriptTag) { // bail if no shortcode is present..
		return
	}

	const tours = []
	let i = 0
	while (i < 100) { // loop through ars generated by the shortcode's wp_localize_script
		if (typeof window['wp_virtualtour_' + i] !== 'undefined')
			tours.push(window['wp_virtualtour_' + i].data)
		else
			break
		i++
	}
	for (let i = 0; i < tours.length; i++) { // init pannellum for each
		const tour = tours[i]
		pannellum.viewer('panorama_' + tour['id'], tour)
	}
	// end for shortcodes

	// init for blocks
	const tourElems = document.querySelectorAll('.wp-virtualtour-element')
	for (let i = 0; i < tourElems.length; i++) { // init pannellum for each
		const tourElem = tourElems[i]
		const id = tourElem.getAttribute('data-id')
		pannellum.viewer('panorama_' + id, wp_virtualtour_block.data[id])
	}
	// end for block
}

initPannellum()
