$(function(){
	generateShareAnyLink('.shareAnyLink');

	$('#printLink').click (function() {
			window.open(''+ $('#printLinkURL').text() +'');
	});
	
	//load list of favorite stores.
	Profile.Stores.load();
	
	Profile.Stores.setEvents();
	
	var calState = 1;
	
	// This is the month toggle control
	$('.NextCal').click(function(){
		$('#MonthDisplay'+ calState++).hide();
		$('#MonthDisplay'+ calState).show();
	});	
	
	$('.PreviousCal').click(function(){
		$('#MonthDisplay'+ calState--).hide();
		$('#MonthDisplay'+ calState).show();
	});	

	if(jQuery.browser.msie) {
		$('.image-indicator').pngFix();
	}

	var authorTimeout;
	$('ul.authorNameList li a').hover(function(){	
		var a = StoreLocator.Authors;
		var dest =this.parentNode;
		var authId = dest.id.substr(3);
		var obj=a.getData(authId);	
		if(obj==false){
			$.get(StoreLocator.location+'/storelocator/stores.aspx',{'uiaction':'getauthordetail','contributorid':dest.id.substr(3)},function(data){
				a.saveData(authId,data);
				$('.authorOverlay').remove();
				$(a.makeDisplay(data)).appendTo(dest);
				$('.authorOverlay').hover(function(){
					if(authorTimeout){
						clearTimeout(authorTimeout);
					}
				},function(){
					$('.authorOverlay').remove();
				});
			},'json');
		}else{
			$('.authorOverlay').remove();
			$(a.makeDisplay(obj)).appendTo(dest);
			$('.authorOverlay').hover(function(){
				if(authorTimeout){
					clearTimeout(authorTimeout);
				}
			},function(){
				$('.authorOverlay').remove();
			});
		}
	},function(){
		authorTimeout=setTimeout(function(){$('.authorOverlay').remove();},200);
		//var authId = this.id.substr(3);
		//$('#x'+authId).remove();
	});
	
	
	//myBnStoresDrop
	$("span.myBnStoresDrop img.mybn").click(function(){
		if(Profile.state!=false){
			Profile.Stores.insertFavorites('#bnStoresPushContent','short',function(){
				$('#bnStoresPushContent').html('');
				$('#dropDownStores').show();
						
			});
		}else{
			$('#dropDownStores').show();
		}
	});
	
		
	//dropDownSearch
	$("span.searchStoresDrop img").click(function(){
			$('#dropDownSearch').show();
	});

	//directions overlay
	$("span.storeDetail img.driveBtn").click(function(){	
		$('#directionsOverlay').show();	
	});
		

		// this is what happens when see events is openened in calendar or list
	$('span.openEvents').click(function(){
		var key=$(this).find('span.match').text();
		var eventColl = StoreLocator.getEventCollection(key);
		eventColl.appendTo(this.parentNode);
		eventColl.startAt(3);
	});
	

	
	// this is what happens when an store event is clicked on in calendar
	;
	var store={};
	$('.onMonth .shortEvent span').hover(function(){
			if($(this).find('.hideMe').text().length > 0 && StoreLocator.pauseHover==false){
				$(this).find('.hideMe').show();
				$(this.parentNode).css({'position':'relative','zIndex':300,'float':'left','margin':'0 -80px -30px 0','height':'auto','maxHeight':'36px'});
			}
		},function(){
			if($(this).find('.hideMe').text().length > 0  && StoreLocator.pauseHover==false){
				$(this).find('.hideMe').hide();
				$(this.parentNode).css({'position':'static','zIndex':0,'float':'none','margin':'0','height':'18px','maxHeight':'18px'});
			}
		}).click(function(){
			StoreLocator.pauseHover=true;
			if($(this).find('.hideMe').text().length > 0){
				$(this).find('.hideMe').hide();
				$(this.parentNode).css({'position':'static','zIndex':0,'float':'none','margin':'0','height':'18px','maxHeight':'18px'});
			}
			var start = this.parentNode;
			var evId=start.id.substr(start.id.indexOf('_')+1);
			var place = 0;
			var dateIdSrc =start.parentNode.parentNode.id;
			var dateId = ''+dateIdSrc.substr(10);
			var eventColl = StoreLocator.getEventCollection(dateId);
			var openAt = eventColl.getPosById(evId);
			$(start).css('overflow','visible');
			eventColl.appendTo(start);
			eventColl.startAt(openAt);	
	});
	
	//Expect only one
	$('span#drivingDistance').click(function(){
		StoreLocator.getDisplayList().changeMode();
	});	

	
	$('#findStore-off a').click(function(){
		$("#findStore-on").show();
		$("#findStore-off").hide();
		$("#findEvent-off").show();
		$("#findEvent-on").hide();
		$("#dropFormPagetype").val("storelist");
	});
	
	$('#findEvent-off a').click(function(){
		$("#findStore-on").hide();
		$("#findStore-off").show();
		$("#findEvent-off").hide();
		$("#findEvent-on").show();
		$("#dropFormPagetype").val("eventlist");
	});
	
	$(".imgGallery a").click(function(e) {
		$(".imgGallery img").removeClass("selected");
		e.preventDefault();
		var image =  $(this).attr("href");
		$(this).children("img").addClass("selected");
		$("img#mainStoreImg").attr("src", image);
	});
	
	
	BN.getLibrary('ListUtil');
	BN.getLibrary('DataUtil');
	
	//store locator core metrics
	if (typeof cmCreatePageviewTag !== "undefined") {
            
            var categoryId = '';
            var currentPage = '';
            
            if (window.location.href.substr(7,4)=='btob') {
                categoryId = "B2B:STORE_LOCATOR";
            } else { categoryId = "STORE_LOCATOR" };

			var pageType = $('.coreMetrics .pageType').text();
			var cmTagInfo = $('.coreMetrics .cmTag').text();
			
			if ($('li.currentPage span.numId').get(0) != null) {
			    currentPage = $('li.currentPage span.numId').text();
			    cmTagInfo = cmTagInfo.replace("-_X_-", currentPage);
			}

			//alert('testing: calling cmCreatePageviewTag: ' + (pageType + cmTagInfo).substr(0,49) + ' categoryId: '+ categoryId);
    	    cmCreatePageviewTag ((pageType + cmTagInfo).substr(0,49), categoryId); 
		};
	

});



	// Profile is already instantiated, because of page reload on login.
Profile ={};
Profile.state=true;
Profile.loadWidget=function(zip){
	if(zip){
		findMyStore(zip, 2);
		$('#searchBox').hide();
		$('#storeZipCodeDisplay').html(zip);
		$('#findmystore_zipcode').val(zip);
		$('#searchResults').show();
	}else{
		findMyStore('', 2);
	}
	
	$('#btn_saveMyStores').click(function(){
		Profile.Stores.contents=[];
		$('.storeBox .populated').each(function(idx){
			Profile.Stores.contents[idx]=this.id.substr(11);
		});
		Profile.Stores.display();
	});
	
	$('.btn_saveEventPref').click(function(){
		Profile.Stores.display();
	});
}

Profile.Stores={};
Profile.Stores.setEvents=function(){
	//Behavior on hovering over myBN whats this
	$('.addToMyBNStores span.controlLink').once('whatsmybn').hoverCopyFrom('#whatsThisSource');
	//Rss help anchor for   hover information
	$('.moreStoreEvents .rssHelpAnchor').once('myrsshelpanchor').hoverCopyFrom('#rssHelp');
	
	

	
	//remove and edit favorite stores
	$('.modifyMyBNStores span.controlLink').once('removeFaves').click(function(){
		if(Profile.state!=false){
			var root =$(this).parents('tr').get(0);
			var process = (root && root.id)?root.id:null;
			if(this.innerHTML=='Remove'){
				Profile.Stores.remove(process);
			}else if(this.innerHTML=='Edit'||
					$(this).text().toLowerCase()=='find a favorite store' ||
					$(this).text().toLowerCase()=='add another store to your profile'|| 
					$(this).text().toLowerCase()=='edit the stores in your profile'){
				if(process == null){
					var zipPos = document.cookie.search('zip=');
					process=(zipPos == -1 || isNaN(document.cookie.substr(zipPos+4,5)))?'':document.cookie.substr(zipPos+4,5);
				}
				initFindMyStore();
				Profile.loadWidget((root && root.id)?$('#'+process+' div.storeAddress span.zip').text():process);
			}
		}else{
			new $.SignInWidget();
		}
	});
	
	
	

	$('.addToMyBNStores img.addToMyBN').once('addFaves').click(function(){
		if(Profile.state!=false){
			var process = $(this).parents('tr').get(0).id;
			Profile.Stores.set(process);
		}else{
			new $.SignInWidget();
		}
	});
	
	
	$('.dismissOverlay').click(function(){
		//need some kind of overlay wrap so this isn't necessary
		$('#dropDownStores').hide();
		$('#dropDownSearch').hide();
		$('#directionsOverlay').hide();
	});
}


Profile.Stores.set=function(storeId,loaded){
	var result;
	if(Profile.Stores.contents && Profile.Stores.contents.length == 2){
		// if there are already two items, this prevents extra event firing from misbehaving.
		if(Profile.Stores.contents.join('~').search(storeId)==-1){
			showPopUpError('You can have a maximum of two favorite stores. <span id="editStores" class="controlLink">Click Here</span> to edit your favorites.','Too many favorites','Too many Favorites');
			$('#editStores').click(function(){
				$('.overlay').remove();
				initFindMyStore();
				Profile.loadWidget($('#'+storeId+' div.storeAddress span.zip').text());
			});
		}
	}else {
		var valid = true;
		if(!Profile.Stores.contents){
			Profile.Stores.contents = [];
		}
		if(storeId != 0){
			Profile.Stores.contents[Profile.Stores.contents.length]= storeId;
			if(!loaded){
				Profile.Stores.sync(Profile.Stores.contents.join('|'));
			}
			result='added';
		}else{
			result = 'empty';
		}
	}
	return result;
}
	

	
Profile.Stores.load = function(a){
	if(!a){
		//http://localhost.barnesandnoble.com:4866/Community/ServiceRequest.aspx?cbf=show&uiAction=GetFavoriteStores&page=UserProfile&pageType=profile
		//alert('make request');
		ui.request({ baseURL: $.hosts.commServices,
				parameters:  '?page=UserProfile&pageType=profile&uiAction=GetFavoriteStores',
				callback: {name: "cbf", value: "Profile.Stores.load"},
				signInRequired: false
		});
	}else{
		if(a.status =="True"){
			//alert('logged in ');
			if(a.output){
				 $(a.output).wrap('<div></div>').parent().parent().find('p').each(function(){
					var numSrc = this.id;
					Profile.Stores.set(numSrc.substr(numSrc.lastIndexOf('_')+1),true);
				});
			}else{
				Profile.Stores.set(0,true);
			}
		}else{
			//alert('not logged in ');
			Profile.state=false;
		}
	}
	return;
}




Profile.Stores.loadFavoritesHtml = function(mode,call){
	if(Profile.state!=false){
		$.get(StoreLocator.location+'/storelocator/stores.aspx',{'uiaction':'getfavoritestoreshtml','mode':mode},call,'html');
	}else{
		new $.SignInWidget();
	}
}

Profile.Stores.insertFavorites=function(sel,mode,exe){
	Profile.Stores.loadFavoritesHtml(mode,function(res){
		if(exe){
			exe();
		}
		$(sel).append(res);
		Profile.Stores.setEvents();
	});
}

	// param is passed as pipe separated ids
Profile.Stores.sync = function(param){
	if(param.length > 0){
		param+='|';
	}
	ui.request({ baseURL: $.hosts.commServices,
		parameters:  '?page=UserProfile&pageType=profile&uiAction=UpdateStores&storeIDsInput=' + param,
		callback: {name: "cbf", value: "Profile.Stores.display"}
	});
}
	
	
Profile.Stores.remove = function(storeId){
	if(Profile.Stores.contents[0]==storeId){
		Profile.Stores.contents[0] = Profile.Stores.contents[1];
		Profile.Stores.contents.length=(Profile.Stores.contents[0])?1:0;
	}else if(Profile.Stores.contents[1]==storeId){
		Profile.Stores.contents.length=1;
	}
	
	Profile.Stores.sync(Profile.Stores.contents.join('|'));
}
	
Profile.Stores.display = function(){
	if(window.location.search.search('pagetype=favoritestores')!= -1){
		Profile.Stores.insertFavorites('#storeLocatorResults','long',function(){
			$('#storeLocatorResults').html('');
		});
	}else{
		var drop=false;
		if($('#dropDownStores:visible').get().length != 0){
			$('#dropDownStores').hide();
			//duplicate ids in content screw up content main content.
			$('#bnStoresPushContent').html('');
			drop=true;
		}
		var temp=0;
		$('tr').each(function(){
			var check= (this.id)?this.id:null;
			if(check != null && !(isNaN(check)) ){			
				if(check == Profile.Stores.contents[0] ||check == Profile.Stores.contents[1]){
					$('#'+check+' div.addToMyBNStores').hide();
					$('#'+check+' div.modifyMyBNStores').add('#'+check+' .myBNImage').show();
				}else if(check){
					$('#'+check+' div.addToMyBNStores').show();
					$('#'+check+' div.modifyMyBNStores').add('#'+check+' .myBNImage').hide();
				}
			}
		});
		
		if(drop){
			//restore drop down now that collision is avoided
			$('span.myBnStoresDrop img.mybn').click();
		}
	}
}


	
StoreLocator={};
StoreLocator.pauseHover =false;
StoreLocator.location = 'http://'+( (window.location.href.substr(7,4)=='btob')?'btob.':'') + 'store-locator.barnesandnoble.com';

StoreLocator.Authors={};

StoreLocator.Authors.makeDisplay=function(obj){
	var evnt=obj.EventList.Events[0];
	var auth=obj.ContribDetails;
	var authImg=auth.Images[0];
	var authName='';
	for(var i=0;i<auth.AuthorNames.length;i++){
		var pl=auth.AuthorNames[i];
		if(pl.IsPrimary){
			authName = pl.FirstName +' '+pl.LastName;
		}
	}
	
	var htm='<div class="authorOverlay" style="width:'+(( (authImg)?355:290 ) )+'px"id="x'+evnt.AuthorList[0].ContributorId+'"><div class="contentContainer">';
	htm+='<div class="authorContent"><div class="eventHeader"><span class="eventName"><a href="'+StoreLocator.location+'/event/'+evnt.EventID + '">' + authName+ '</a></span><br/>';
	htm+='<span class="eventName"><a href="'+StoreLocator.location+'/event/'+evnt.EventID + '">' + evnt.EventName+ '</a></span>';
	var evntGenre=(evnt.EventGenre)?' ('+evnt.EventGenre+')':'';
	htm+='<br/><span class="eventDetails">'+evnt.EventType+' '+evntGenre+'</span></div>';
	if(auth.Bio && auth.Bio.length != 0){
		htm+='<p class="authorInfo"><strong>About the author</strong><br/>'+auth.Bio+'</p>';
	}
	htm+='<a href="'+StoreLocator.location+'/author-events/contributor/'+evnt.AuthorList[0].ContributorId+'"><span class="controlLink smallImage rArrow"> See upcoming events for '+authName+'</span></a>';

	htm+='</div>';
	if(authImg){
		htm+='<div class="imageContainer"><img class="authorImage"  src="'+ StoreLocator.imagePrefix + authImg.Path+ '" alt="'+ authImg.Alt+'"/></div>';
	}
	
	htm+='</div></div>';
	return htm;
}

StoreLocator.Authors.getData=function(key){
	if(!StoreLocator.Authors['id_'+key]){
		return false;
	}else{
		return StoreLocator.Authors['id_'+key];
	}
	
}

StoreLocator.Authors.saveData=function(key,content){
	StoreLocator.Authors['id_'+key]=content;
}

StoreLocator.getDisplayList=function(){
	if(!(StoreLocator.holdDisplayList)){
		StoreLocator.holdDisplayList= new StoreLocator.StoreDisplayList();
	}
	return StoreLocator.holdDisplayList;
}

StoreLocator.StoreDisplayList=function(){
	//driving time and distance
	//note- makes unreversable change to DOM
	var sortControl = $('#drivingDistance');	
	var sortActivation=sortControl.attr('href');
	
	//remove functionality
	sortControl.attr({'href':'#drivingDistanceSort'});
	
	var text={};
	text.crow='Sort by driving time and distance';
	text.car='Sort by physical distance';
	
	
	var mode='crow';
	
	var storeList=new BN.ListUtil.List();
	
	var drivingObj='';
	
	this.getMode=function(){
		return mode;		
	}
	
	this.changeMode=function(){
		$('tr td.distance strong.'+mode).hide();
		if(mode == 'crow'){
			mode='car';
		}else if(mode=='car'){
			mode='crow';
		}
		sortControl.text(text[mode]);
		sortBy(mode);
		$('tr td.distance strong.'+mode).show();		
	}

	
	storeList.useKey=true;
	
	storeList.setKeyEval(function(item){
		return item.id;
	});
	
	storeList.setFilter(function(item){
		if(item.id && !(isNaN(item.id))){
			return true;
		}else{
			return false;
		}
	});

	storeList.populateDOM('table.storeList tr');

	
	
	var getDrivingDistance=function(callb){
		if(drivingObj == ''){
			$.get(sortActivation+'&uiaction=getsortbydriving',{},function(data){
				drivingObj=data;
				insertDrivingDetails();
				callb(data);
			},'json');
		}else{
			callb(drivingObj)
		}
	}
	
	var sortBy=function(str){
		if(str=='car'){
			getDrivingDistance(function(dat){
				insertAccordingTo(dat.DrivingDistances,function(x){
					if(x.StoreId){
						return x.StoreId;
					}
				});			
			});
		}else if (str=='crow'){
			insertAccordingTo(storeList.toArray(),function(x){
				return x.getKey();	
			});			
				
		}
	}
	
	var insertDrivingDetails=function(){
		//do not call until drivingObj has been  retrieved from server
		//does not display either
		var arr =drivingObj.DrivingDistances;
		for(var iter in arr){
			var key=arr[iter].StoreId;
			var dist=arr[iter].Distance;
			var time=arr[iter].Time.split(':');
			var carSel='#'+key+' td.distance .car';
			$(carSel + ' span.miles').text(dist.toFixed(2));
			$(carSel + ' span.minutes').text(time[1]);
			if(time[0] != 0){
				$(carSel + ' span.hours').html(time[0]+'<br/>hours');
			}
		}
	}
	
	var reOrder=function(arr,func){
		var resorted=[];
		for(var x in arr){
			var key = func(arr[x]);
			resorted[x]=storeList.getByKey(key);
		}
		return resorted;
		
	}
	
	var insert=function(arr){
		$('table.storeList tr').filter(function(){
    		var line=$(this).find('td');
    		return this.id=='' && line.hasClass('dottedLine') && line.get.length ==1;
		}).each(function(idx){
			$(this).after(arr[idx]);
		});
	}
	
	 var insertAccordingTo=function(arr,func){
		insert(reOrder(arr,func));
	}
}

StoreLocator.imagePrefix = $.hosts.resources;






StoreLocator.EventCollection = function(listKey){
	var eList = new BN.ListUtil.List();

	eList.useKey=true;
	
	eList.setKeyEval(function(item){
		var obj=item.data();
		return obj.EventDetails.EventID;
	});

	eList.setProcess(function(item,idx){
		var eventKey = $(item).text();
		var eventItem= {};
		eventItem=new BN.DataUtil.Cache({url:StoreLocator.location+'/storelocator/stores.aspx',async: false,dataType:'json',type:'GET',data:{eventid:eventKey,uiaction:'getevent'}});
		return eventItem;
	});
	
	sel=('#'+listKey+' ');
	sel+='.eventID';
	eList.populateDOM(sel);
	
	this.getPosById=function(tKey){
		return eList.getPosByKey(tKey);
	}
	
	this.getById=function(tKey){
		return eList.getByKey(tKey).data().EventDetails;
	}
	
	this.getByPos=function(pos){
		return eList.i(pos-1).data().EventDetails;
	}
	
	var showNext=function(){
		display.setEvent(eList.i(display.next()-1).data().EventDetails);
		display.display();
	}
	
	var showPrev=function(){
		display.setEvent(eList.i(display.prev()-1).data().EventDetails);
		display.display();
	}
	
	this.startAt=function(n){
		display.setEvent(eList.i(display.setPos(n)-1).data().EventDetails);
		display.display();
	}
	
	this.show=function(){
		display.display();
	}
	
	this.appendTo=function(x){
		return display.appendTo(x);
	}
	
	var display = new StoreLocator.EventDisplay(1);
	display.setMax(eList.length());
	var jqDisp = display.access();
	jqDisp.find('img.backward').click(function(){
		showPrev()
	});
	
	jqDisp.find('img.forward').click(function(){
		showNext()
	});
	
}




StoreLocator.cloneSafe=function(jq){
	jq.appendTo('#cloneStore');
	return jq;	
}


StoreLocator.getEventCollection=function(key){
	var ret;
	if(!(StoreLocator.EventSets)){
		StoreLocator.EventSets={};
		ret = StoreLocator.EventSets['e'+key] = new StoreLocator.EventCollection(key);
	}else if(!(StoreLocator.EventSets['e'+key])){
		ret=StoreLocator.EventSets['e'+key] = new StoreLocator.EventCollection(key);
	}else{
		ret=StoreLocator.EventSets['e'+key];
	}
	return ret;
}





StoreLocator.EventDisplay=function(pos){
	var displayBlock = $('#eventBlock').clone();
	displayBlock=StoreLocator.cloneSafe($(displayBlock));
	displayBlock.attr('id','');
	
	var display=function(){
		$('.eventBlock:visible').hide();
		displayBlock.show();
	};
	
	var pos=(pos)?pos:1;
	var myMax=1;
	
	
	var showControls=function(){
		if(myMax==1){
			displayBlock.find('.counterContent').hide();
			displayBlock.find('.counterDisplay img').hide();
		}else{
			displayBlock.find('.counterContent').show();
			displayBlock.find('.counterDisplay img').show();
		}
	}
	var myKey ='';
	var showPosition=function(){
				displayBlock.find('.counterDisplay .counterContent').text((pos)  + ' of ' + (myMax));
	}
	showControls();
	showPosition();
	
	
	var setMax=function(n){
		myMax=n;
		showControls();
	}
	
	
	var setPos=function(n){
		pos=n;
		showPosition();
		return pos;
	}
	
	var next =function(){
		if(pos+1 <= myMax){
			pos=pos+1;
		}else{
			pos=1;
		}
		showPosition();
		return pos;
		
	}
	
	var prev = function(n){
		if(pos-1<1){
			pos=myMax;
		}else{
			pos=pos-1;
		}
		showPosition();
		return pos;
	}
	
	

	var setEvent=function(eventObj){
		showControls();
		showPosition();
		
		var isOnline= eventObj.IsOnline;
		
		var eventLink= ' href="'+StoreLocator.location+'/event/'+eventObj.EventID+'"';
		var imgDep = displayBlock.find('td.image-indicator');
		var img;
		var imgClass = ( (eventObj.ImageList[0].ImageType == "I")?'eventI':'i' ) + 'mage';
		img='<img class="'+imgClass+'" alt="'+eventObj.ImageList[0].Alt+'" src="'+StoreLocator.imagePrefix+eventObj.ImageList[0].Url+'"/>';
		if(eventObj.ImageList[1]){
			imgClass = ( (eventObj.ImageList[1].ImageType == "I")?'eventI':'i' ) + 'mage';
			img+='<img class="'+imgClass+'"alt="'+eventObj.ImageList[1].Alt+'" src="'+StoreLocator.imagePrefix+eventObj.ImageList[1].Url+'"/>';
		}
		imgDep.html(img);
		if(eventObj.ImageList.length == 2){
			imgDep.css('width',172+'px');
		}else{
			imgDep.css('width',70+'px');
		}
		var head=displayBlock.find('div.eventHeader');
		var hasAuthor=(eventObj.AuthorList.length==0)?false:true;
		var eventTitle='';
		if(eventObj.EventName){
			eventTitle =eventObj.EventName;
		}else if(hasAuthor==false && eventObj.ProductTitles.length==0){
			eventTitle = eventObj.EventType;
		}
		head.find('.eventName').html('<a'+eventLink+'>'+eventTitle+'</a>')
		if(hasAuthor){
			var authData='';
			for(var auth in eventObj.AuthorList){
				authData +=(auth==0)?'':',';
				authData += eventObj.AuthorList[auth].FirstName + ' '+eventObj.AuthorList[auth].LastName;
			}
			head.find('.productInfo').html('<a'+eventLink+'>'+authData+'</a>')
		}
		
		if(eventObj.ProductTitles.length!=0){
			for(var prod in eventObj.ProductTitles){
				if(eventObj.ProductTitles[prod].IsMain==1){
					head.find('.productTitle').html('<a'+eventLink+'>'+eventObj.ProductTitles[prod].Title+'</a>')			
				}
			}
		}
		
		displayBlock.find('span.eventTime').html(eventObj.EventTime);
		displayBlock.find('span.eventDetails').html((eventObj.EventGenre)?' ('+eventObj.EventGenre+')':'');
		displayBlock.find('a.moreEvent').attr({href:(StoreLocator.location+'/event/'+ eventObj.EventID)});
		displayBlock.find('td.close img').click(function(){
			displayBlock.hide();
			StoreLocator.pauseHover=false;
		});
		displayBlock.find('ul.flatBox li').each(function(){
			if($(this).text().indexOf('Share') != -1){
				$(this).html('<span class="shareAnyLink">'+StoreLocator.location+'/event/'+eventObj.EventID+'|||'+eventTitle + '|||'+eventObj.EventType+'</span>');
				generateShareAnyLink($('.shareAnyLink',this).get());
				//$(this).html(generateShareLink('Event '+eventObj.EventID, StoreLocator.location+'/event/'+eventObj.EventID));
			}else if($(this).text().indexOf('Email a Friend')!= -1){
				$('a',this).attr('href','http://my.barnesandnoble.com/tellafriend/EmailScreen.aspx?inputType=EventID&contentValue='+eventObj.EventID+'&contentType=StoreEvent&step=Load').click();
				$('#overlay_emailAFriend').remove();
				delete($.global.EmailAFriend);
				$.global.EmailAFriend = new $.EmailAFriend();
			}else if($(this).hasClass('calendarRem')){
				if(isOnline){
					$(this).remove();
				}else if($(this).text().indexOf('|')== -1){
					var calContr = $('span.addToCalendar a',this);
					var calHref = calContr.attr('href').replace('~eventId~',eventObj.EventID);
					calContr.attr('href',calHref);
				}
			}
		});

	}
	

	
	
	return {appendTo:function(x){return displayBlock.appendTo(x)},
			setKey:function(k){myKey=k},
			access:function(){return displayBlock},
			'setMax':setMax,
			'setPos':setPos,
			'next':next,
			'display':display,
			'prev':prev,
			'setEvent':setEvent};
}
	

