
	var pageInitialized	= false;
	var documentLoaded	= false;
	var activeEvent		= {
		"series"	: "",
		"month" 	: 0,
		"year"		: 2009,
		"days"		: [1900]
	}


	$(window).load(function() {
		$("#seriesBar").accordion({
			autoheight: false,
			clearStyle: true
		});
		documentLoaded	= true;
	});


	function flashCheckDocumentLoad() {
		return documentLoaded;
	}


	function eventInfo(eventID) {
		$.getJSON("/api/services/events.cfc?method=getEventInfo&eventID=" + eventID + "&key=" + Math.floor(Math.random() * 10000), function(data){
			if (!data.ERROR) {
				var eventInformation	 = "";
					
					//alert info --->>
					$.each(data.ALERTS, function(i) {
						var alertStartDate	= new Date(data.ALERTS[i].STARTDATE + " 00:00:00");
						var alertEndDate = new Date(data.ALERTS[i].ENDDATE + " 23:59:59");
						if ((alertStartDate <= today) && (alertEndDate >= today)) {
							//dateStr = (alertStartDate == alertEndDate)? data.ALERTS[i].STARTDATE : data.ALERTS[i].STARTDATE + " - " + data.ALERTS[i].ENDDATE; 
							dateStr = (today.getMonth()+1) + "/" + today.getDate() + "/" + today.getFullYear();
							eventInformation	+=	("<p><span class='alertDate'>" + dateStr + "</span>&nbsp;&nbsp;<span class='alertMessage'>"+ data.ALERTS[i].MESSAGE +"</span></p>");
						}
					});
					// end alert info --->>
					
					eventInformation	+= ("<h3>" + data.NAME + "</h3>");
					//if (data.SPONSOR != "") {
					//	eventInformation	+= ("<p class='eventSponsor'>" + data.SPONSOR + "</p>");
					//}
					eventInformation	+= ("<p class='eventSummary'>" + data.SUMMARY + "</p>");
					if ((data.SEASON == 5) && (data.SERIES == "Classical") ) {
						eventInformation	+= ("<p class='eventDescription'>Want to attend this performance?  Purchase it now, before tickets go on sale to the general public, as part of one of our numerous season packages!</p><p class='eventDescription'>As a subscriber you will enjoy numerous benefits, including your same seat for all performances, unlimited-free ticket exchanges, and a deep discount over single ticket prices.</p>");
					}
					else if ((data.SEASON == 5) && (data.SERIES == "CSOvations") ) {
						eventInformation	+= ("<p class='eventDescription'>As a subscriber you will enjoy numerous benefits, including your same seat for all performances, unlimited-free ticket exchanges, and a deep discount over single ticket prices.</p>");
					}
					else {
						eventInformation	+= ("<p class='eventDescription'>" + data.DESCRIPTION + "</p>");
					}
					if (data.VENUE != "") {
						eventInformation	+= ("<p class='eventVenue'><strong>Venue: </strong><span>" + data.VENUE + "</span> | <a href='/' class='map-me'>Map</a></p>"); // Don't remove the span or 'map-me' class.
					}

					var allowSalesMessage	= false;

					//if (data.TICKETS != "") {
						$.each(data.DATES, function(i) {
							var checkEventDate	= new Date(data.DATES[i].YEAR, (data.DATES[i].MONTH - 1), data.DATES[i].DAY, data.DATES[i].HOUR, data.DATES[i].MINUTE, 00);
							if ((data.TICKETS[i] != "") && (checkEventDate >= today)) {
								if (data.SEASON == 5) { // We're hiding season 5 ticket purchase for the time being. Eliminate this if statement to bring it back.
									eventInformation	+= ("<p class='tickets'><strong>" + data.DATES[i].FULLSTARTDATE + "</strong></p>");
								}
								else {
									allowSalesMessage	= true;
									// Order System is Up.
									eventInformation	+= ("<p class='tickets'><a href='" + data.TICKETS[i] + "' title='Buy Tickets' target='_blank'><img src='/images/b_buy_tickets.png' align='absmiddle' alt='Buy Tickets.'/></a> <strong>" + data.DATES[i].FULLSTARTDATE + "</strong></p>");

									// Order System is Down.
									//eventInformation	+= ("<p class='tickets'><span style='font-size: 15px;'>Call to Order: (614) 228-8600</span><br/><br/><strong>" + data.DATES[i].FULLSTARTDATE + "</strong></p>");
								}
							} else if(checkEventDate == today) {
								eventInformation	+= ("<p class='tickets'><a href='/BuyTicketsInfo.cfm' title='Buy Tickets' target='_blank'><img src='/images/b_buy_tickets.png' align='absmiddle' alt='Buy Tickets.'/></a> <strong>" + data.DATES[i].FULLSTARTDATE + "</strong></p>");
							}
							else {
								eventInformation	+= ("<p class='tickets'><strong>" + data.DATES[i].FULLSTARTDATE + "</strong></p>");
							}
						});
					//}

					// Sales Message
					/*if ((allowSalesMessage) && (data.NAME != "Ben Folds")) {
						eventInformation	+= ("<p><em style='font-size: 10px'><strong>Buy now and save 10%</strong><br />Offer ends 9/5/09. Discounted prices appear at time of purchase. Not valid on pre-purchased tickets.</em></p>");
					} */

					if ((data.SPONSORLOGO != "") && ((data.SERIES == "Classical") || ((data.SEASON != 5) && (data.SERIES == "POPS")))) {
						eventInformation	+= ("<p id='sponsorLogo'>");
						eventInformation	+= ("<p class='eventSponsor'>Sponsored by</p>");
						eventInformation	+= ("<a href='" + data.SPONSORURL + "' target='_blank'><img src='/images/sponsor/" + data.SPONSORLOGO + "' alt=''/></a>");
						if (eventID == 146) {
							eventInformation	+= ("<br /><br />");
							eventInformation	+= ("<a href='http://www.aep.com/' target='_blank'><img src='/images/sponsor/aep.png' alt=''/></a>");
						}
						eventInformation	+= ("</p>");
					}
					else {
						if ((data.SPONSOR != "") && (data.SERIES == "Classical")) {
							eventInformation	+= ("<p class='eventSponsor'>" + data.SPONSOR + "</p>");
						}
					}

					if ((data.SERIES == "Picnic") || (data.SERIES == "Popcorn")) {
						eventInformation	+= ("<p id='sponsorLogo2'>");
						eventInformation	+= ("<p class='eventSponsor'>Series Sponsor</p>");
						eventInformation	+= ("<img src='/images/sponsor/nationwide.png' alt=''/>");
						eventInformation	+= ("</p>");
					}
						
					if (eventID == 148) {
						eventInformation	+= ("<p id='sponsorLogo2'>");
						eventInformation	+= ("<p class='eventSponsor'>Supporting Sponsor</p>");
						eventInformation	+= ("<img src='/images/sponsor/johnstone.png' alt=''/>");
						eventInformation	+= ("</p>");
					}

					if ((eventID == 174) || (eventID == 144) || (eventID == 145)) {
						eventInformation	+= ("<p id='sponsorLogo2'>");
						eventInformation	+= ("<p class='eventSponsor'>Supporting Sponsor</p>");
						eventInformation	+= ("<a href='http://www.aep.com/' target='_blank'><img src='/images/sponsor/aep.png' alt=''/></a>");
						eventInformation	+= ("</p>");
					}
					
					if (eventID == 139) {
						eventInformation	+= ("<p class='eventDescription'><span class='specialEventTitle'>Food drive supporting the Mid-Ohio Foodbank</span><br/>");
						eventInformation	+= ("Attendees who bring one or more non-perishable items to donate to the Mid-Ohio Foodbank will receive an exclusive  CSO download card that can be redeemed online for free downloads of select music from the concert!</p>");
					}
					
					if (eventID == 149) {
						eventInformation	+= ("<p id='sponsorLogo2'>");
						eventInformation	+= ("<p class='eventSponsor'>Supporting Sponsor</p>");
						eventInformation	+= ("<img src='/images/sponsor/germainLexus.png' alt=''/>");
						eventInformation	+= ("</p>");
					}
					if (eventID == 150) {
						eventInformation	+= ("<p id='sponsorLogo2'>");
						eventInformation	+= ("<p class='eventSponsor'>Supporting Sponsor</p>");
						eventInformation	+= ("<a href='http://www.steptoe-johnson.com/' target='_blank'><img src='/images/sponsor/steptoe.png' alt=''/></a>");
						eventInformation	+= ("</p>");
					}
					if (eventID == 151) {
						eventInformation	+= ("<p id='sponsorLogo2'>");
						eventInformation	+= ("<p class='eventSponsor'>Supporting Sponsor</p>");
						eventInformation	+= ("<a href='http://www.schneiderdowns.com/' target='_blank'><img src='/images/sponsor/schneider_logo.png' alt=''/></a>");
						eventInformation	+= ("</p>");
					}
					
					if (data.SERIES == "Picnic") {
						eventInformation	+= ("<p id='sponsorLogo2'><hr/>");
						eventInformation	+= ("<br/>Make it a perfect evening by allowing our preferred caterer, Vito's Catering, to delight you and your guests with artful cuisine and excellent service.<br/><br/>");
						eventInformation	+= ("<a href='http://www.vitoscatering.com/menus/picnic_with_the_pops_vitos2010.pdf' target='_blank'><img src='/images/sponsor/vitos.png' alt='' border='0'/></a>");
						eventInformation	+= ("<br/>The deadline for placing an order is by noon on Wednesday before each weekend event.<br/><a href='http://www.vitoscatering.com/menus/picnic_with_the_pops_vitos2010.pdf' target='_blank'>Download full menu</a> or call (614) 459-3377");
						eventInformation	+= ("</p>");
					}

				$("#eventInfo").html(eventInformation).slideDown("fast");
				updateSeriesIndicator(data.SERIES);

				if (data.DATES.length > 0) {
					currentMonth	= new Date(data.DATES[0].YEAR, (data.DATES[0].MONTH - 1), 1);	// Don't change this variable name. It's used in calendar.js.
					buildCalendar(currentMonth);

					activeEvent.series	= data.SERIES;
					activeEvent.month	= currentMonth.getMonth();
					activeEvent.year	= currentMonth.getFullYear();
					activeEvent.days	= new Array();
					for (var i = 0; i < data.DATES.length; i++) {
						if ((data.DATES[i].MONTH - 1) == currentMonth.getMonth()) {
							activeEvent.days[i]	= data.DATES[i].DAY;
						}
					}
				}

			} else {
				$("#eventInfo").html("&nbsp;");
				alert(data.ERRORMESSAGE);
			}
		});
		return false;
	}


	function getFlashMovie(movieName) {
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		return (isIE) ? window[movieName] : document[movieName];
	}


	function retrieveNextSeriesEvent(series) {
		$.getJSON("/api/services/events.cfc?method=retrieveNextSeriesEvent&series=" + series.toLowerCase() + "&key=" + Math.floor(Math.random() * 10000), function(data){
			if (!data.ERROR) {
				eventInfo(data.ID);
				getFlashMovie("imageSlider").updateImage(data.ID);
			} else {
				alert(data.ERRORMESSAGE);
			}
		});
	}


	function updateSeriesIndicator(series) {
		$("#seriesBar div a").each(
			function(i) {

				var updateWith	= this.childNodes[0].src.replace("on", "on");
				$("#" + this.childNodes[0].id).attr("src", updateWith);

				if (this.rel == series.toLowerCase()) {
					$("#seriesBar").accordion("activate", i);
					var updateWith	= this.childNodes[0].src.replace("off", "on");
					$("#" + this.childNodes[0].id).attr("src", updateWith);
					if (pageInitialized) {
						if (series == "Concerts for Kids") {
							series = "kids";
						}
						$("#column2").css({
							"background-image"	: "url(/images/bg_" + series.toLowerCase() + ".jpg)",
							"background-repeat"	: "repeat-x"
						});
					}
					pageInitialized	= true;
				}
			}
		);
	}


	function highlightEvents(month, year) {
		$.getJSON("/api/services/events.cfc?method=retrieveEventsForMonth&month=" + month + "&year=" + year + "&key=" + Math.floor(Math.random() * 10000), function(data){
			if (!data.ERROR) {
				if (data.DATES.length > 0) {
					for (var highlightEventDateIndex = 0; highlightEventDateIndex < data.DATES.length; highlightEventDateIndex++) {
						switch(data.DATES[highlightEventDateIndex].SERIES.toLowerCase()) {
							case "classical":
								highlightColor	= "#949494";
								break;
							case "special":
								highlightColor	= "#949494";
								break;
							case "pops":
								highlightColor	= "#949494";
								break;
							case "csovations":
								highlightColor	= "#949494";
								break;
							case "picnic":
								highlightColor	= "#949494";
								break;
							case "popcorn":
								highlightColor	= "#949494";
								break;
							case "concerts for kids":
								highlightColor	= "#949494";
								break;
							default:
								highlightColor	= "#949494";
						}
						var cellContent	= '<a href="" onclick="return focusOnEvent(' + data.DATES[highlightEventDateIndex].ID + ');" title="View Event.">' + data.DATES[highlightEventDateIndex].DAY + '</a>';
						$("#calendarDay-" + data.DATES[highlightEventDateIndex].DAY).html(cellContent);
						$("#calendarDay-" + data.DATES[highlightEventDateIndex].DAY).css({ "background-color" : highlightColor });
						$("#calendarDay-" + data.DATES[highlightEventDateIndex].DAY).css({ "color" : "#FFFFFF" });
					}

					if ((activeEvent.month == currentMonth.getMonth()) && (activeEvent.year == currentMonth.getFullYear())) {
						switch(activeEvent.series.toLowerCase()) {
							case "classical":
								highlightColor	= "#F74902";
								break;
							case "special":
								highlightColor	= "#C44398";
								break;
							case "pops":
								highlightColor	= "#5D8E57";
								break;
							case "csovations":
								highlightColor	= "#F99C31";
								break;
							case "picnic":
								highlightColor	= "#0072C6";
								break;
							case "popcorn":
								highlightColor	= "#EC008C";
								break;
							case "concerts for kids":
								highlightColor	= "#98DDF8";
								break;
							default:
								highlightColor	= "#111111";
						}
						for (var i = 0; i < activeEvent.days.length; i++) {
							$("#calendarDay-" + activeEvent.days[i]).html(activeEvent.days[i]);
							$("#calendarDay-" + activeEvent.days[i]).css({ "background-color" : highlightColor });
							$("#calendarDay-" + activeEvent.days[i]).css({ "color" : "#FFFFFF" });
						}
					}
				}

			} else {
				//alert(data.ERRORMESSAGE);
			}
		});
	}


	function focusOnEvent(eventID) {
		getFlashMovie("imageSlider").updateImage(eventID);
		eventInfo(eventID);
		return false;
	}
