var eid;
var hEvents = new Array("Brunch","Tea","H-tea","Lunch","Martini");
var hEventsNames = new Array("Brunch","Afternoon Tea","High Tea","Lunch","Martinis");

var getEID = function(eventName) {
	var i = null;
	for (i = 0; events.length > i; i += 1) {if (events[i].name === eventName) {return i;}}
	return false;
};



jQuery(document).ready(function($) {	
	buildInventory();
	$('#inventory li:not(.hover) .desc').hide('fast');
	$("#inventory:not(.bullets) li").hoverIntent({
		sensitivity: 7, 
		interval: 100, 
		over: showMe, 
		timeout: 700, 
		out: hideMe
	});
	openByPound();
});


function buildLinks(eventName){
	var justThis=false,linksHTML="",nameRegexp = new RegExp(eventName);
	if(hEventsNames.toString().match(nameRegexp)){justThis=true;}
	for (i = 0; hEvents.length > i; i += 1) {
		if ( !justThis || (hEventsNames[i] == eventName) ) {
			linksHTML+='<a href="https://www.omansion.com/events/reservation.shtml?Event='+hEvents[i]+'">reserve '+hEventsNames[i]+'</a>';
			if(justThis){return linksHTML}
		}
	}
	return linksHTML
}

function buildInventory(){
	var theOptions = "",moreBlurb = " Want something more<span class='publicOnly'>, like a private room or a specialty cake</span>? Let us know when you fill out your form.";
	var list =jQuery('#inventory');
	var theOptions = list.html();
	
	jQuery.each(events,function(i,thisEvent){
		url = (this.url!="")? this.url: "https://www.omansion.com/fun/form/?Event="+this.name;
		urlText = (this.url!="")? "learn more": "reserve";
		myPer = (this.per=="Quantity")?"group":this.per ;
		perString = '<span class="per">$' + this.price + "/" + myPer + ".</span> ";
		links= (audience=="public")?buildLinks(this.name):'<a href="'+url+'">'+urlText+'</a>';
		var amenities= (audience=="public")?"":this.amenities;
		var foodDescription= (audience=="public")?'includes food from selected event':this.food;
		var description= (audience=="public")?'explore over 100 rooms and 32 secret doors while you visit.':this.description;
		var showToAudience = new RegExp(audience);
		if(this.extra!=""){perString = this.extra }
		if(this.showTo.toString().match(showToAudience)){
	 		theOptions+= '<li><a name="'+this.name+'" class="name">' +this.name + '</a><div class="desc">'+description + ' ' + foodDescription + ' '  + amenities +  " &mdash; " + perString +moreBlurb + links+'</div></li>';
	 	}
	});
	
	list.html(theOptions);
	//$('#inventory').append(theOptions);
}

function showMe(){ 
	if(!jQuery(this).is('.hover') ){
		//first remove selected from any others (accommodation for initial selected
		jQuery("#content div.selected").removeClass('hover').find('.desc').hide('fast');	
		jQuery(this).addClass('hover').find('.desc').show('fast', function(){
			jQuery(this).css("min-height","140px")
		});
	}
}

function hideMe(){ jQuery(this).removeClass('hover').find('.desc').css("min-height","0px").hide('fast');}

function openByPound(){
	if(location.hash!=""){
		var mySel = "a[name='"+unescape(location.hash).substring(1,location.hash.length)+"']";
		jQuery(mySel).parent().addClass('hover').find('.desc').show();
  		jQuery.scrollTo( mySel, 800 ); 
	}
}
