function autoSelect(selectTarget) {
 	if(selectTarget != null && ((selectTarget.childNodes.length == 1
      && selectTarget.childNodes[0].nodeName == "#text") || (selectTarget.tagName == "INPUT"
      && selectTarget.type == "text"))) {
  		if(selectTarget.tagName == 'TEXTAREA' || (selectTarget.tagName == "INPUT" && selectTarget.type == "text")) {
  			 selectTarget.select();
  		} else if(window.getSelection) { // FF, Safari, Opera
   			var sel = window.getSelection();
   			var range = document.createRange();
   			range.selectNode(selectTarget.firstChild);
   			sel.removeAllRanges();
   			sel.addRange(range);
  		} else { // IE
   			document.selection.empty();
   			var range = document.body.createTextRange();
   			range.moveToElementText(selectTarget);
   			range.select();
  		}
 	}
}
var browserInfo = navigator.userAgent; var browserType = browserInfo.indexOf('Safari'); var linkOffset; var eventVideoLink;
jQuery(document).ready(
	function() {		
		linkOffset = jQuery("p.linkToEvent > a").offset();
		jQuery("p.linkToEvent > a").click( function() {
			jQuery("input[name='selectedEventLink']").val("http://www.spac.org/calendar.php?calId=" + jQuery("a[class*='active']").attr("name"));
			jQuery("a.emailLink").attr("href", "mailto:?body=http://www.spac.org/calendar.php?calId=" + jQuery("a[class*='active']").attr("name"));
			jQuery("div#calEventLink").removeClass("noShow");
			var linkToEventPosition = jQuery('.linkToEvent').position();
			var linkToEventHeight = jQuery('.linkToEvent').height();
			jQuery("div#calEventLink").css("left", '-19px');
			jQuery("div#calEventLink").css("top", (linkToEventPosition.top + linkToEventHeight)+'px');
			if($("div#textReminderWrap").not('.noShow')) {
				$("div#textReminderWrap").addClass("noShow");
				$('#textReminderWrap').html('<a href="#" class="textReminderClose">&nbsp;</a>');
			}
		});
		jQuery("a.selectLink").click( function() { autoSelect(jQuery("input[name='selectedEventLink']").get(0)) });
		jQuery("a.closeLink").click( function() { jQuery("div#calEventLink").addClass("noShow"); });
		jQuery(".performancePiece").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
		jQuery(".arrowLeft").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
		jQuery(".arrowRight").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
		jQuery(".performanceInfo").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
		jQuery(".backToCalendar").children("p").children("a").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
		jQuery("#calendarSearch").children("a").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
		function setSideBar() {
			if (lastEventCell == null) {
				var lastEventCell = jQuery("#calendarMain").find(".selectedDay").find("a.activeConcertEvent, a.activeOperaEvent, a.activeDanceEvent, a.activeOrchestraEvent, a.activeFestivalEvent, a.activeOtherEvent, a.activeCabaretEvent, a.activeChamberEvent, a.activeWineFoodEvent, a.activeGenericEvent");
			}

			var eventCell = jQuery("a[name='"+jQuery(this).attr("name")+"']").eq(0);
			var calId = jQuery(this).attr("name");

			if (lastEventCell != null) {
				jQuery(lastEventCell).parent().parent("td").toggleClass("selectedDay");

				if (jQuery(lastEventCell).hasClass("concertBackground")) { jQuery(lastEventCell).toggleClass("activeConcertEvent"); }
				if (jQuery(lastEventCell).hasClass("operaBackground")) { jQuery(lastEventCell).toggleClass("activeOperaEvent"); }
				if (jQuery(lastEventCell).hasClass("danceBackground")) { jQuery(lastEventCell).toggleClass("activeDanceEvent"); }
				if (jQuery(lastEventCell).hasClass("orchestraBackground")) { jQuery(lastEventCell).toggleClass("activeOrchestraEvent"); }
				if (jQuery(lastEventCell).hasClass("festivalBackground")) { jQuery(lastEventCell).toggleClass("activeFestivalEvent"); }
				if (jQuery(lastEventCell).hasClass("otherBackground")) { jQuery(lastEventCell).toggleClass("activeOtherEvent"); }
				if (jQuery(lastEventCell).hasClass("cabaretBackground")) { jQuery(lastEventCell).toggleClass("activeCabaretEvent"); }
				if (jQuery(lastEventCell).hasClass("chamberBackground")) { jQuery(lastEventCell).toggleClass("activeChamberEvent"); }
				if (jQuery(lastEventCell).hasClass("wineFoodBackground")) { jQuery(lastEventCell).toggleClass("activeWineFoodEvent"); }
				if (jQuery(lastEventCell).hasClass("genericBackground")) { jQuery(lastEventCell).toggleClass("activeGenericEvent"); }
			}

			jQuery(eventCell).parent().parent("td").toggleClass("selectedDay");

			if (jQuery(eventCell).hasClass("concertBackground")) { jQuery(eventCell).toggleClass("activeConcertEvent"); }
			if (jQuery(eventCell).hasClass("operaBackground")) { jQuery(eventCell).toggleClass("activeOperaEvent"); }
			if (jQuery(eventCell).hasClass("danceBackground")) { jQuery(eventCell).toggleClass("activeDanceEvent"); }
			if (jQuery(eventCell).hasClass("orchestraBackground")) { jQuery(eventCell).toggleClass("activeOrchestraEvent"); }
			if (jQuery(eventCell).hasClass("festivalBackground")) { jQuery(eventCell).toggleClass("activeFestivalEvent"); }
			if (jQuery(eventCell).hasClass("otherBackground")) { jQuery(eventCell).toggleClass("activeOtherEvent"); }
			if (jQuery(eventCell).hasClass("cabaretBackground")) { jQuery(eventCell).toggleClass("activeCabaretEvent"); }
			if (jQuery(eventCell).hasClass("chamberBackground")) { jQuery(eventCell).toggleClass("activeChamberEvent"); }
			if (jQuery(eventCell).hasClass("wineFoodBackground")) { jQuery(eventCell).toggleClass("activeWineFoodEvent"); }
			if (jQuery(eventCell).hasClass("genericBackground")) { jQuery(eventCell).toggleClass("activeGenericEvent"); }					

			lastEventCell = eventCell;

			jQuery.ajax({
				type: "POST",
				url: "/includes/getCalSideBar.php",
				data: {
					"calId": calId
				},
				dataType: "json",
				success: function(data){
					var overlayGenreId = data.calGenreId;
					var eventWrapper = '<a href="#" class="closeEventOverlay">Close</a>';
					switch (data.calGenreId) {
						case '1' : { eventWrapper += "\n"; eventWrapper += '<h2 class="concertBackground">Live Nation Concerts</h2>'; break; }
						case '2' : { eventWrapper += "\n"; eventWrapper += '<h2 class="operaBackground">Opera Saratoga</h2>'; break; }
						case '3' : { eventWrapper += "\n"; eventWrapper += '<h2 class="danceBackground">New York City Ballet</h2>'; break; }
						case '4' : { eventWrapper += "\n"; eventWrapper += '<h2 class="orchestraBackground">The Philadelphia Orchestra</h2>'; break; }
						case '5' : { eventWrapper += "\n"; eventWrapper += '<h2 class="festivalBackground">Freihofer\'s Jazz Festival</h2>'; break; }
						case '6' : { eventWrapper += "\n"; eventWrapper += '<h2 class="otherBackground">Other / Special Events</h2>'; break; }
						case '7' : { eventWrapper += "\n"; eventWrapper += '<h2 class="cabaretBackground">Cabaret</h2>'; break; }
						case '8' : { eventWrapper += "\n"; eventWrapper += '<h2 class="chamberBackground">Saratoga Chamber Music Festival</h2>'; break; }
						case '10' : { eventWrapper += "\n"; eventWrapper += '<h2 class="wineFoodBackground">Wine &; Food Festival</h2>'; break; }
						default : { eventWrapper += "\n"; eventWrapper += '<h2 class="genericBackground">Other Events</h2>'; break; }							
					}
					eventWrapper += "\n"; eventWrapper += '<div id="eventDetails">';
					var eventDetails = '';
					eventDetails += '<a href="calendar.php?calId='+data.previousID+'" class="performanceInfo overlayNavButton leftOverlayNavButton" name="'+data.previousID+'">Previous Event</a>';
					eventDetails += '<a href="calendar.php?calId='+data.nextID+'" class="performanceInfo overlayNavButton rightOverlayNavButton" name="'+data.nextID+'">Next Event</a>';
					eventDetails += '<div class="clear">&nbsp;</div>';
					eventDetails += '<div class="eventInformation">';
					eventDetails += '<h1>' + data.calTitle + '</h1>' + "\n";
					if(data.calImage == '') { eventDetails += '<img src="/imgs/calendar/defaultEventImage.png" class="eventThumbnail" alt="SPAC-Saratoga Performing Arts Center" />'; }
					else { eventDetails += '<img src="/imgs_upload/cal_events/' + data.calImage + '" class="eventThumbnail" alt="' + data.calTitle + '" />'; }
					eventDetails += '<h3>' + data.calDate + '<br />' + "\n" + data.calTime + '</h3>' + "\n";
					eventDetails += '<p class="eventPrice">';
					if(data.lawnPrice == null || data.lawnPrice == "NULL" || data.lawnPrice == "" || data.lawnPrice == '0.00' || data.lawnPrice == '0.0' || data.lawnPrice == '0') {
						if((data.amphitheaterPriceLow == null || data.amphitheaterPriceLow == "NULL" || data.amphitheaterPriceLow == "" || data.amphitheaterPriceLow == '0.00' || data.amphitheaterPriceLow == '0.0' || data.amphitheaterPriceLow == '0') && (data.amphitheaterPriceHigh == null || data.amphitheaterPriceHigh == "NULL" || data.amphitheaterPriceHigh == "" || data.amphitheaterPriceHigh == '0.00' || data.amphitheaterPriceHigh == '0.0' || data.amphitheaterPriceHigh == '0')) {
							eventDetails += "&nbsp;";
						}
						else if(data.amphitheaterPriceLow == null || data.amphitheaterPriceLow == "NULL" || data.amphitheaterPriceLow == "" || data.amphitheaterPriceLow == '0.00' || data.amphitheaterPriceLow == '0.0' || data.amphitheaterPriceLow == '0') {
							eventDetails += '$'+data.amphitheaterPriceHigh;
						}
						else if(data.amphitheaterPriceHigh == null || data.amphitheaterPriceHigh == "NULL" || data.amphitheaterPriceHigh == "" || data.amphitheaterPriceHigh == '0.00' || data.amphitheaterPriceHigh == '0.0' || data.amphitheaterPriceHigh == '0') {
							eventDetails += '$'+data.amphitheaterPriceLow;
						}
						else if(data.amphitheaterPriceLow == data.amphitheaterPriceHigh) { eventDetails += '$'+data.amphitheaterPriceHigh; }
						else { eventDetails += '$'+data.amphitheaterPriceLow+' - $'+data.amphitheaterPriceHigh; }
					}
					else {
						if((data.amphitheaterPriceLow == null || data.amphitheaterPriceLow == "NULL" || data.amphitheaterPriceLow == "" || data.amphitheaterPriceLow == '0.00' || data.amphitheaterPriceLow == '0.0' || data.amphitheaterPriceLow == '0') && (data.amphitheaterPriceHigh == null || data.amphitheaterPriceHigh == "NULL" || data.amphitheaterPriceHigh == "" || data.amphitheaterPriceHigh == '0.00' || data.amphitheaterPriceHigh == '0.0' || data.amphitheaterPriceHigh == '0')) {
							eventDetails += '$'+data.lawnPrice;
						}

						else
						{

							if (!(data.amphitheaterPriceLow == null || data.amphitheaterPriceLow == "NULL" || data.amphitheaterPriceLow == "" || data.amphitheaterPriceLow == '0.00' || data.amphitheaterPriceLow == '0.0' || data.amphitheaterPriceLow == '0'))
							{
								if (data.amphitheaterPriceLow <= data.lawnPrice)
								{
									eventDetails += '$' + data.amphitheaterPriceLow;
								}
								else
								{
									eventDetails += '$' + data.lawnPrice;
								}
							}
							else
							{
								eventDetails += '$' + data.lawnPrice;
							}

							if(!(data.amphitheaterPriceLow == null || data.amphitheaterPriceLow == "NULL" || data.amphitheaterPriceLow == "" || data.amphitheaterPriceLow == '0.00' || data.amphitheaterPriceLow == '0.0' || data.amphitheaterPriceLow == '0') || !(data.lawnPrice == null || data.lawnPrice == "NULL" || data.lawnPrice == "" || data.lawnPrice == '0.00' || data.lawnPrice == '0.0' || data.lawnPrice == '0'))
							{
								eventDetails += ' - $' + data.amphitheaterPriceHigh;
							}
							else if(!(data.amphitheaterPriceHigh == null || data.amphitheaterPriceHigh == "NULL" || data.amphitheaterPriceHigh == "" || data.amphitheaterPriceHigh == '0.00' || data.amphitheaterPriceHigh == '0.0' || data.amphitheaterPriceHigh == '0'))
							{
								eventDetails += '$' + data.amphitheaterPriceHigh;
							}

						}

/*
						else if(data.lawnPrice == data.amphitheaterPriceHigh) { eventDetails += '$'+data.amphitheaterPriceHigh; }
						else if(data.lawnPrice == data.amphitheaterPriceLow) { eventDetails += '$'+data.amphitheaterPriceLow; }
						else { eventDetails += '$'+data.lawnPrice+' - $'+data.amphitheaterPriceHigh; }
*/
					}
					if(data.venueName != 'Other') { eventDetails += '<br />' + data.venueName; }
					eventDetails += '</p>';
					if(data.calTicketsLink != '') {
						eventDetails += '<p class="buyTickets';
						switch (data.calGenreId) {
							case '1': { eventDetails += ' concertTicketsBackground'; var eventProgramLink = ' concertText'; break; }
							case '2': { eventDetails += ' operaTicketsBackground'; var eventProgramLink = ' operaText'; break; }
							case '3': { eventDetails += ' danceTicketsBackground'; var eventProgramLink = ' danceText'; break; }
							case '4': { eventDetails += ' orchestraTicketsBackground'; var eventProgramLink = ' orchestraText'; break; }
							case '5': { eventDetails += ' festivalTicketsBackground'; var eventProgramLink = ' festivalText'; break; }
							case '6': { eventDetails += ' otherTicketsBackground'; var eventProgramLink = ' otherText'; break; }
							case '7': { eventDetails += ' cabaretTicketsBackground'; var eventProgramLink = ' cabaretText'; break; }
							case '8': { eventDetails += ' chamberTicketsBackground'; var eventProgramLink = ' chamberText'; break; } 
							case '10': { eventDetails += ' wineFoodTicketsBackground'; var eventProgramLink = ' wineFoodText'; break; } 
							default : { eventDetails += ' genericTicketsBackground'; var eventProgramLink = ' genericText'; break; }
						}
						eventDetails += '"><a href="'+data.calTicketsLink+'" id="buyTicketsHere">Buy Tickets</a></p>';
					}
					eventDetails += '<div class="eventSocialWrap"><p class="linkToEvent eventSocial"><img src="/imgs/calendar/smallGrayArrow.png" alt="Link to this Event" /><a href="javascript:void(0);">Link to this event</a></p>'; eventDetails += "\n";
					eventDetails += '<p class="textReminder eventSocial"><img src="/imgs/calendar/smallGrayArrow.png" alt="Text me a Reminder" /><a href="/includes/textReminder.php?calId='+data.calId+'">Text me a reminder</a></p>';				
					eventDetails += '<p class="eventSocial"><img src="/imgs/calendar/smallGrayArrow.png" alt="Share on Facebook" /><a href="http://www.facebook.com/share.php?u='+encodeURIComponent('http://www.spac.org/calendar.php?calId='+data.calId)+'&t='+encodeURIComponent(data.calTitle)+'">';
					eventDetails += 'Share <img src="/imgs/calendar/facebookIcon.png" alt="Share '+data.calTitle+' on Facebook" class="calendarFBShare" /></a></p>';
					eventDetails += "\n"; 
					eventDetails += '</div><div class="clear">&nbsp;</div></div>'; eventDetails += "\n";		
					var eventSideBar = eventWrapper + "\n"; eventSideBar += eventDetails; eventSideBar += "\n";
					
					if(data.performanceNote1 != '0' || data.performanceNote2 != '0' || data.performanceNote3 != '0' || data.performanceNote4 != '0') {
						if(data.calDescription != null && data.calDescription != '') { eventSideBar += '<div class="calendarEventDescriptionShort"><p class="performanceInfoHeader">Program</p>' + data.calDescription + '</div>'; }
						eventSideBar += '<div class="calendarEventProgramNotes"><p class="performanceInfoHeader">Program Notes</p>';
						if(data.performanceNote1 != '0') {
							eventSideBar += '<p class="performanceOverlayLink"><a href="#" id="'+data.performanceNote1+'" class="performancePiece'+eventProgramLink+'"><img src="/imgs/calendar/programNoteIcon.png" alt="'+data.performanceNote1Name+'" /><strong>'+data.performanceNote1Name;
							eventSideBar += '</strong> '+data.performanceNote1Credit;
							eventSideBar += '</a></p>';
						}
						if(data.performanceNote2 != '0') {
							eventSideBar += '<p class="performanceOverlayLink"><a href="#" id="'+data.performanceNote2+'" class="performancePiece'+eventProgramLink+'"><img src="/imgs/calendar/programNoteIcon.png" alt="'+data.performanceNote2Name+'" /><strong>'+data.performanceNote2Name;
							eventSideBar += '</strong> '+data.performanceNote2Credit;
							eventSideBar += '</a></p>';
						}
						if(data.performanceNote3 != '0') {
							eventSideBar += '<p class="performanceOverlayLink"><a href="#" id="'+data.performanceNote3+'" class="performancePiece'+eventProgramLink+'"><img src="/imgs/calendar/programNoteIcon.png" alt="'+data.performanceNote3Name+'" /><strong>'+data.performanceNote3Name;
							eventSideBar += '</strong> '+data.performanceNote3Credit;
							eventSideBar += '</a></p>';
						}
						if(data.performanceNote4 != '0') {
							eventSideBar += '<p class="performanceOverlayLink"><a href="#" id="'+data.performanceNote4+'" class="performancePiece'+eventProgramLink+'"><img src="/imgs/calendar/programNoteIcon.png" alt="'+data.performanceNote4Name+'" /><strong>'+data.performanceNote4Name;
							eventSideBar += '</strong> '+data.performanceNote4Credit;
							eventSideBar += '</a></p>';
						}
						eventSideBar += '</div>';
					}
					else {
						if(data.calDescription != null && data.calDescription != '') { eventSideBar += '<div class="calendarEventDescriptionWide"><p class="performanceInfoHeader">Program</p>' + data.calDescription + '</div>'; }
					}
					eventSideBar += '<div class="clear">&nbsp;</div>'; eventSideBar += "\n";
					if(data.videoLink != null && data.videoLink != '') {
						eventSideBar += '<div id="eventVideoWrap"><div class="eventVideoReplace"></div></div>';
						eventVideoLink = data.videoLink;
					}
					eventSideBar += '<div id="calEventLink" class="noShow">'+"\n";
					eventSideBar += '<p class="eventLinkTools"><a href="javascript:void(0);" class="emailLink">[Email Link]</a> <strong>|</strong> <a href="javascript:void(0);" class="selectLink">[Select Link]</a> <a href="javascript:void(0);" class="closeLink">&nbsp;</a></p>'+"\n";
					eventSideBar += '<input type="text" name="selectedEventLink" value="" />'+"\n";
					eventSideBar += '</div>'+"\n";
					eventSideBar += '<div id="textReminderWrap" class="noShow"><a href="#" class="textReminderClose">&nbsp;</a></div>'+"\n";
					eventSideBar += '<div id="programNoteWrap" class="noShow"><a href="#" class="closeProgramNote">Close Notes</a><h1></h1><div class="programNoteContent"></div></div>'+"\n";
					
					jQuery("#eventOverlay").html(eventSideBar);
					jQuery(".eventVideoReplace").oembed("http://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3D"+window.eventVideoLink+"&format=json&width=424");
					if ($.browser.version == 6.0 && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) { $("#eventDetails").supersleight(); }
					switch (data.calGenreId) {
						case '1' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("concertText"); break; }
						case '2' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("operaText"); break; }
						case '3' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("danceText"); break; }
						case '4' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("orchestraText"); break; }
						case '5' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("festivalText"); break; }
						case '6' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("otherText"); break; }
						case '7' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("cabaretText"); break; }
						case '8' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("chamberText"); break; }
						case '10' : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("wineFoodText"); break; }
						default : { jQuery("div.calendarEventDescription").children("p").children("a").children("strong").addClass("genericText"); break; }
					}
					jQuery("p.linkToEvent > a").click( function() {
						linkOffset = jQuery("p.linkToEvent > a").offset();
						jQuery("input[name='selectedEventLink']").val("http://www.spac.org/calendar.php?calId=" + jQuery("a[class*='active']").attr("name"));
						jQuery("a.emailLink").attr("href", "mailto:?body=http://www.spac.org/calendar.php?calId=" + jQuery("a[class*='active']").attr("name"));
						jQuery("div#calEventLink").removeClass("noShow");
						var linkToEventPosition = jQuery('.linkToEvent').position();
						var linkToEventHeight = jQuery('.linkToEvent').height();
						jQuery("div#calEventLink").css("left", '-19px');
						jQuery("div#calEventLink").css("top", (linkToEventPosition.top + linkToEventHeight)+'px');
						if($("div#textReminderWrap").not('.noShow')) {
							$("div#textReminderWrap").addClass("noShow");
							$('#textReminderWrap').html('<a href="#" class="textReminderClose">&nbsp;</a>');
						}
					});
					jQuery("a.selectLink").click( function() { autoSelect(jQuery("input[name='selectedEventLink']").get(0)) });
					jQuery("a.closeLink").click( function() { jQuery("div#calEventLink").addClass("noShow"); });
					jQuery(".performancePiece").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
					jQuery(".arrowLeft").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
					jQuery(".arrowRight").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
					jQuery(".performanceInfo").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
					jQuery(".backToCalendar").children("p").children("a").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
					jQuery("#calendarSearch").children("a").click(function() { jQuery("div#calEventLink").addClass("noShow"); });
					
					jQuery(".performanceOverlayLink").children("a").attr("href", "javascript:void(0);");
					jQuery(".performanceOverlayLink").children("a").click(function () {
						var oid = jQuery(this).attr("id");
						jQuery.ajax({
							type: "POST",
							url: "/includes/getOverlayContent.php",
							data: {
								"oid": oid
							},
							dataType: "json",
							success: function(data){
								$('#programNoteWrap').remove();
								$('#eventDetails').append('<div id="programNoteWrap" class="noShow"><a href="#" class="closeProgramNote">Close Notes</a><h1></h1><div class="programNoteContent"></div></div>');
					
								jQuery("div#programNoteWrap > h1").html(data.title);
								if(data.photo1 != '') {
									jQuery("div.programNoteContent").html('<img src="/imgs_upload/cal_overlays/' + data.photo1tn + '" alt="' + data.title + '" />');
								}
								jQuery("div.programNoteContent").append(data.performanceInfo);
								if(data.videoEmbed != '') { 
									if(data.videoDescription != '') { jQuery("div.programNoteContent").append('<embed src="' + data.videoEmbed + '" type="application/x-shockwave-flash" width="320" height="240" allowscriptaccess="always" allowfullscreen="true" wmode="opaque"></embed>' + data.videoDescription); }
									else { jQuery("div.programNoteContent").append('<embed src="' + data.videoEmbed + '" type="application/x-shockwave-flash" width="320" height="240" allowscriptaccess="always" allowfullscreen="true" wmode="opaque"></embed><p>&nbsp;</p>'); }
								}
								if(data.audioClip != '') {
									jQuery("div.programNoteContent").append('<div id="musicPlayer"></div>');
									jQuery('#musicPlayer').flash( { 
									  src: '/flash/mp3player.swf', width: 319, height: 45, swliveconnect: "true", id: "mp3player",
									  flashvars: { mp3File: '/explore/audio/' + data.audioFile + '', mp3Tag: '' + data.audioTitle + '' }
									}, { version: 8 });
								}
								jQuery("div#programNoteWrap").hide().removeClass("noShow");
								var programNoteOffset = jQuery(".eventInformation > h3").position();
								jQuery("div#programNoteWrap").css("top", programNoteOffset.top+"px");
								var programLeftHeight = jQuery(".calendarEventDescriptionShort").height();
								var programRightHeight = jQuery(".calendarEventProgramNotes").height();
								var programNoteHeight;
								if(programLeftHeight > programRightHeight) { programNoteHeight = programLeftHeight + 178; }
								else if(programLeftHeight < programRightHeight) { programNoteHeight = programRightHeight + 178; }
								jQuery("div#programNoteWrap").css("height", programNoteHeight+"px");
								jQuery("div.programNoteContent").css("height", (programNoteHeight - 50)+"px");
								jQuery("div#programNoteWrap").show();
								jQuery("div.programNoteContent").bind('jsp-initialised', function(event, isScrollable) {
									switch(overlayGenreId) {
										case '1': {
											jQuery("div.jspDrag").addClass("concertScrollBackground");										
											break;
										}
										case '2': {
											jQuery("div.jspDrag").addClass("operaScrollBackground");
											break;
										}
										case '3': {
											jQuery("div.jspDrag").addClass("danceScrollBackground");
											break;
										}
										case '4': {
											jQuery("div.jspDrag").addClass("orchestraScrollBackground");
											break;
										}
										case '5': {
											jQuery("div.jspDrag").addClass("festivalScrollBackground");
											break;
										}
										case '6': {
											jQuery("div.jspDrag").addClass("otherScrollBackground");
											break;
										}
										case '7': {
											jQuery("div.jspDrag").addClass("cabaretScrollBackground");
											break;
										}
										case '8': {
											jQuery("div.jspDrag").addClass("chamberScrollBackground");
											break;
										}
										case '10': {
											jQuery("div.jspDrag").addClass("wineFoodScrollBackground");
											break;
										}
										default: {
											jQuery("div.jspDrag").addClass("genericScrollBackground");
											break;
										}
									}
								}).jScrollPane({showArrows: false, autoReinitialise: true});
							},
							error: function(){
								alert("There was an error completing the request for the overlay");
							}
						});
					});
				},
				error: function(){
					alert("There was an error completing the request");
				}
			});

			jQuery.fancybox({
				'transitionIn' : 'fade',
				'transitionOut' : 'fade',
				'speedIn' : 500, 
				'speedOut' : 200, 
				'titleShow' : false,
				'overlayOpacity' : 0.6,
				'overlayColor' : '#000',
				'hideOnContentClick' : false,
				'type' : 'inline',
				'padding' : 10,
				'href' : '#eventOverlay',
				'scrolling' : 'auto',
				'margin' : 20,
				'onComplete' : overflowTweak
			});
					
			return false;
		}
		function overflowTweak() {
			jQuery('div').filter(function(){ return $(this).parents('#fancybox-content').length }).css('overflow', 'visible');
		}
		//define right arrow AJAXy use
		jQuery(".arrowRight").click(function() {
			jQuery.ajax({
				type: "POST",
				url: "/includes/getMainCalContent.php",
				data: {
					"useAjax": true,
					"month": (parseInt(month, 10) + parseInt(1, 10)),
					"year": year
				},
				dataType: "json",
				success: function(data){
					jQuery("#calendarHeader h1 > span").html(data.year);
					jQuery("#calendarHeader h2").html(data.month_fancy);

					jQuery("table > tbody").html(data.html);

					month = data.month;
					year = data.year;
				},
				error: function(){
					alert("There was an error completing the request");
				}
			});

			return false;
		});

		//reset left arrow AJAXy use
		jQuery(".arrowLeft").click(function() {
			jQuery.ajax({
				type: "POST",
				url: "/includes/getMainCalContent.php",
				data: {
					"useAjax": true,
					"month": (parseInt(month, 10) - parseInt(1, 10)),
					"year": year
				},
				dataType: "json",
				success: function(data){
					jQuery("#calendarHeader h1 > span").html(data.year);
					jQuery("#calendarHeader h2").html(data.month_fancy);

					jQuery("table > tbody").html(data.html);

					month = data.month;
					year = data.year;
				},
				error: function(){
					alert("There was an error completing the request");
				}
			});

			return false;
		});

		//reset left arrow for AJAXy use
		jQuery(".arrowLeft").parent().attr("href", "#");

		//reset right arrow for AJAXy use
		jQuery(".arrowRight").parent().attr("href", "#");

		//make cal event ready for AJAXy use
		jQuery("#calendarEvent > a").attr("href", "#");

		jQuery("a.performanceInfo").live("click", setSideBar)
});
