/*var listing = {
	codes : Array,
	init : function() {
		listing.codes = document.getElementsByClassName('l-itemOn');
		listing.attach();
	},
	attach : function() {
		var i;
		for (i=0;i<listing.codes.length;i++ ) {
			Event.observe(listing.codes[i],'click',listing.collapse,false);
			Element.cleanWhitespace(listing.codes[i].parentNode);
			Element.cleanWhitespace(listing.codes[i].parentNode.parentNode);
		}
	},
	getEventSrc : function (e) {
		if (!e) e = window.event;
		if (e.originalTarget)
			return e.originalTarget;
		else if (e.srcElement)
			return e.srcElement;
	},
	collapse : function(e) {
		var el = listing.getEventSrc(e).nextSibling;
		Effect.toggle(el.id,'slide', {duration:0.2});
		
		if (el.style.display == "none") {
			listing.getEventSrc(e).className = "l-itemOn";
		} else {
			listing.getEventSrc(e).className = "l-item";
		}
	}
};*/

// ATTACH ONCLICK EVENT TO ALL ELEMENTS WITH THE l-item CLASS
//Event.observe(window,'load',listing.init,false);

function openIPIX(id) {
  var popupWin = window.open('./IPIX.cfm?ipixID=' + id, 'ipixWin',  'status,scrollbars=no,resizable=no,dependent,width=410,height=330,left=50,top=50');
	popupWin.focus();
}

function parseURLParam(name) {
	name = name.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
	var regexS = '[\\?&]' + name + '=([^&#]*)';
	var regex = new RegExp(regexS, 'i');
	var results = regex.exec(window.location.href);
	if (results == null) {
		return '';
	} else {
		return results[1];
	}
}

jQuery(function() {
	/*
	 * Because we're using jQuery Tools' version of Tabs, there's no way to have a function run
	 * when a tab is displayed. So we're adding a custom effect and having the callback on the "show"
	 * function run a custom function. In this case, we're having it check to see if it's the maps tab
	 * and if so, re-center the map and display the info window.
	 */
	jQuery.fx.off = true;
	jQuery.tools.tabs.addEffect('listingsDefault', function(tabIndex, done) {
		this.getPanes().hide().eq(tabIndex).show('fast', function() {
			/*
			 * If we're on the Google Maps tab, re-center the map and open the info window
			 */
			if (jQuery(this).find('.gMapHolder').length >= 1) {
				window.setTimeout(function() {
					loadMap();
				}, 500);
			}
			if (jQuery(this).hasClass('tripAdvisor')) {
				//jQuery(this).load('');
				if (jQuery(this).find('#tripAdvisor_detail').length === 0) {
					jQuery(this).load(imgroot + '/includes/docs/TripAdvisorContent/' + parseURLParam('listingID') + '.html');
				}
				/*
				if (jQuery('head').find('#taStyles').length === 0) {
					jQuery('head').append(jQuery('<link id="taStyles" rel="stylesheet" href="' + imgroot + '/includes/css/tripadvisor.css" type="text/css" />'));
				}
				*/
			}
		});
	});
});

jQuery(document).ready(function() {
	/*
	 * Initialize the jQuery Tools Tabs with the above custom effect
	 */
	jQuery('ul#listingTabs').tabs('div#listingTabPanes > div.listingTabPane', {
		effect: 'listingsDefault'
	});
});

jQuery(document).ready(function() {
	/*
	 * Initialize the jQuery Tools Tabs with the above custom effect
	 */
	jQuery('ul#amenityTabs').tabs('div#amenityTabPanes > div.amenityTabPane', {
		effect: 'listingsDefault'
	});
});

jQuery(document).ready(function() {
	/*
	 * Initialize the jQuery Tools Tabs with the above custom effect
	 */
	jQuery('ul#meetingFacilityTabs').tabs('div#meetingFacilityTabPanes > div.meetingFacilityTabPane', {
		effect: 'listingsDefault'
	});
});

jQuery(document).ready(function() {
	jQuery('div#gMapHolder ul#gMapTabs li a').click(function () {
		$('div#gMapHolder ul#gMapTabs li a').removeClass('current');
		$(this).addClass('current');
		return false;
	});
});
