var g_allEventsMaxDisplay=parseInt("8");
function populateAllEvents(eventsData){ 
try{
	// alert('eventsData :'+eventsData.length);
	// NOTE- eventVOs in eventsData are not set Merchants. they will be set on
	// Click of 'See Where to Eat link'
	 if(eventsData==null ||eventsData.length==0){
		 // show no results found when no data
		YAHOO.util.Dom.get('noResultsAll').innerHTML='Sorry no matches found.';
		YAHOO.util.Dom.setStyle("noResultsAll",'display','block');
		return;
	 }
	YAHOO.util.Dom.setStyle("noResultsAll",'display','none');
	var allEventItemList=YAHOO.util.Dom.get('allEventItemList');
// alert('all events');
	 for(var i=0;i<eventsData.length;i++){
		 var eventItem=document.createElement("DIV");
		 eventItem.setAttribute("id",'eventRow'+i);
		 eventItem.setAttribute("class",'eventRow');
		 eventItem.setAttribute("className",'eventRow');
		 // event date
		 var aElement=document.createElement("DIV");
		 aElement.setAttribute("id",'eventRowDate'+i);
		 aElement.setAttribute("class",'eventDateCol');
		 aElement.setAttribute("className",'eventDateCol');
		 aElement.innerHTML= eventsData[i].eventTimeLong;
		 // add to eventRow
		 eventItem.appendChild(aElement);
		 // event time
		 var aElement=document.createElement("DIV");
		 aElement.setAttribute("id",'eventRowTime'+i);
		 aElement.setAttribute("class",'eventTimeCol');
		 aElement.setAttribute("className",'eventTimeCol');
		 aElement.innerHTML =eventsData[i].eventTimeDetail; // =eventsData[i].eventHour;
		 // add to eventRow
		 eventItem.appendChild(aElement);
		// event venue
		 var aElement=document.createElement("DIV");
		 aElement.setAttribute("id",'eventRowVenue'+i);
		 aElement.setAttribute("class",'eventVenueCol');
		 aElement.setAttribute("className",'eventVenueCol');
		 aElement.innerHTML=eventsData[i].venue;
		 eventItem.appendChild(aElement);
		 
		// event address
		 var aElement=document.createElement("DIV");
		 aElement.setAttribute("id",'eventRowAddress'+i);
		 aElement.setAttribute("class",'eventLocationCol');
		 aElement.setAttribute("className",'eventLocationCol');
		 aElement.innerHTML=eventsData[i].city+", "+eventsData[i].state;
		 eventItem.appendChild(aElement);
		 // link where to eat
		 var aElementDiv=document.createElement("DIV");
		 aElementDiv.setAttribute("class",'eventLinkCol');
		 aElementDiv.setAttribute("className",'eventLinkCol');
		 
		 var aElement=document.createElement("A");
		 aElement.setAttribute("id",'eventRowLink'+i);
		 aElement.setAttribute("href","#");
		 aElement.setAttribute("class",'eventRowItemLink');
		 aElement.setAttribute("className",'eventRowItemLink');
		  aElement.onclick= function(e) {return false;}; 
		 // custom attribute for eventId
		 aElement.setAttribute("eventid",eventsData[i].id);
		 var linkText=document.createTextNode('SEE WHERE TO EAT');

		// add the text as a child of the link
		 aElement.appendChild(linkText);
		 aElementDiv.appendChild(aElement);
		 eventItem.appendChild(aElementDiv);
		 /*
		//create a down arrow image and add as child to link
		 var linkImg=document.createElement("IMG");
		 linkImg.setAttribute("class",'eventRowLinkImage');
		 linkImg.setAttribute("className",'eventItemLinkImage');
		 linkImg.setAttribute("id",'eventRowItemLinkImage'+i);
		 linkImg.setAttribute("src","/images/events/"+g_siteid+"/general/btn-grayarrow.gif");
		 aElement.appendChild(linkImg);*/
		// add clear to eventItem
		 var aElement=document.createElement("DIV");
		 aElement.setAttribute("class","clear");
		 aElement.setAttribute("className","clear");
		 eventItem.appendChild(aElement);

		 // fnally add eventItem to eventItemList
		 allEventItemList.appendChild(eventItem);
		
		
	    
	 } // even Data Loop
	 // attach click event to eventItemLink elements
	 var eventItemLinks = YAHOO.util.Dom.getElementsByClassName('eventRowItemLink', 'a'); 
	
	 for(var i=0;i<eventItemLinks.length;i++){
		 	// alert('eventItemImages[i].id'+eventItemImages[i].id);
		 	if(YAHOO.util.Dom.get(eventItemLinks[i])!=null){
			 	AttachEvent(eventItemLinks[i],'click',getMerchantsForAnEvent,false);
			 	//also attach MouseUp events
				 var venue=YAHOO.util.Dom.get('eventRowVenue'+i).innerHTML;
				 var omnObject=new omnitureObject('eventItemLink', venue);
				 YAHOO.util.Event.addListener(eventItemLinks[i], "mouseup",doOmniture, omnObject);
		 	}
	 }
	 // let the items List scroll. beyond maxDisplay items allowed
	// alert('eventsData.length '+eventsData.length );
	 if(eventsData.length > g_allEventsMaxDisplay){
		 setListContainerHeight('eventRow','allEventBody','div',g_allEventsMaxDisplay);
		 YAHOO.util.Dom.setStyle("allEventBody","width",  '580px');
		 //alert('all events body W'+YAHOO.util.Dom.getStyle("allEventBody","width") );
		 	
			var scrollDivs=YAHOO.util.Dom.getElementsByClassName("jScrollPaneContainer", "div","allEventWrapper");
			if(scrollDivs!=null){
				scrollDivs[0].style.height=YAHOO.util.Dom.getStyle("allEventBody","height") ;
				scrollDivs[0].style.width=  YAHOO.util.Dom.getStyle("allEventBody","width") ;
			}
			
			reinitialiseEventBodyScrollPane();
		 
	 }
 }
 catch(e){
 	// alert('error in population of ALL events Rows----'+e.message);
 } 
} // end


	/*
	 * Called by see where to eat link of an event listed on All Events display.
	 */
	function getMerchantsForAnEvent(e){
		try{
			
			var targ;
			if (!e) var e = window.event; 
			
			if (e.target){
				targ = e.target; 
			} else if (e.srcElement) {
				targ = e.srcElement;
			}
			var selectedEventId=targ.getAttribute('eventid');
			yelpDetailsDialog.cfg.setProperty('context',[targ.id, 'tl', 'tr']);
			//Move overlay by half height of the overlay
			
			var yelpMoveTo=yelpDetailsDialog.cfg.getProperty('y');
			//alert('offsetHeight of yelpDetails'+xx);
			yelpDetailsDialog.moveTo(yelpDetailsDialog.cfg.getProperty('x'), yelpMoveTo-190); 
			
			//show yelp overlay
			showYelpDialog();
			//display ajax indic div
			showMerchantLoader();
			/* call Ajax */
			var sUrl=g_sUrl+'doMerchantsForAnEvent.html?&selectedEventId='+selectedEventId;
		
			var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, yelpLinkCallback, null);
			
		}catch(e){
 		// alert('error in getMerchantsForAnEvent---'+e.message);
 		} 
 		return false;
	}
	
	
	var yelpLinkCallback={
		
		success: function(o) {
		try {
			//hide Ajax show body
			hideMerchantLoader();
			var jsonData = YAHOO.lang.JSON.parse(o.responseText);
			var eventMerchants=jsonData.eventMerchants;
			//eventMerchants is an eventVO that has merchants and yelp see all url
			/*
			//Move overlay by half height of the overlay
			
			var yelpMoveTo=yelpDetailsDialog.cfg.getProperty('y');
			//alert('offsetHeight of yelpDetails'+xx);
			yelpDetailsDialog.moveTo(yelpDetailsDialog.cfg.getProperty('x'), yelpMoveTo-190); 
			*/
			// populate yelpRatingItems
			
			populateYelpRatingItems(eventMerchants );
			// populate google map
			loadGoogleMap(eventMerchants.merchants,"map_canvas");
		}catch(e){
 		// alert('error in yelpLinkCallback---'+e.message);
 		} 
		
	
	},
	failure: function(o)  {
		hideYelpOverlay();
		// alert('yelpLinkCallback fail');
	}
};
	function showMerchantLoader(){
		YAHOO.util.Dom.setStyle('yelpRatingBodyWrapper','display','none');
		YAHOO.util.Dom.setStyle('eventsAjaxIndDiv','display','block');
	}
	function hideMerchantLoader(){
		YAHOO.util.Dom.setStyle('yelpRatingBodyWrapper','display','block');
		YAHOO.util.Dom.setStyle('eventsAjaxIndDiv','display','none');
	}
	// this initialises the  scollpanes on the page.
	 function initEventBodyScrollPane  () {
		 jQuery('#allEventBody').jScrollPane({showArrows:true});
	}
	function reinitialiseEventBodyScrollPane(){
		 jQuery('#allEventBody').jScrollPane({showArrows:true});
	}	
	
