(function($){

var Core = {
	ondomready: function(){
	// page functions go here
		Core.hideEvents();
		Core.rewriteEvents();
		$(document).ready(function() {
			$("#home_hero").cycle({
				fx: "fade",
				timeout: 4000,
				pause: 1
			});
		});
		$("#pageflip").hover(function() { //On hover...
			$("#pageflip img , .msg_block").stop()
				.animate({ //Animate and expand the image and the msg_block (Width + height)
					width: '197px',
					height: '209px'
				}, 500);
			} , function() {
			$("#pageflip img").stop() //On hover out, go back to original size 50x52
				.animate({
					width: '70px',
					height: '72px'
				}, 220);
			$(".msg_block").stop() //On hover out, go back to original size 50x50
				.animate({
					width: '70px',
					height: '70px'
				}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
		});	
	},
	
	rewriteEvents: function() {
		var i= 0;
		$(".gce-feed-1, .gce-feed-2").each(function() {
				//if (i>25) alert(i++); else i++;
		
			$(this).find("a").attr("target", "_blank");
			
			var title = $.trim($(this).find(".gce-list-event").html());
			
			
			
			var date = $.trim($(this).parent().parent().children(".gce-list-title").html());
			var dateObj = $(this).parent().parent().children(".gce-list-title");
			//alert(date);
			
			
			identifier = "Starts:";
			var start = $(this).find("span:contains('"+identifier+"')").parent().html();
			var startObj = $(this).find("span:contains('"+identifier+"')").parent();
			start = $.trim(start.replace("<span>"+identifier+"</span>", ""));
			
			
			
			//alert(date + " -> " + start);
			
			identifier = "Ends:";
			var end = $(this).find("span:contains('"+identifier+"')").parent().html();
			var endObj = $(this).find("span:contains('"+identifier+"')").parent();
			end = $.trim(end.replace("<span>"+identifier+"</span>", ""));
			
			arEnd = end.split(" - ");
			endDate = $.trim(arEnd[0]);
			endTime = $.trim(arEnd[1]);
			
			
			identifier = "Location:";
			var locationObj = $(this).find("span:contains('"+identifier+"')").parent();
			if (locationObj.length >0) {
				var location = $(this).find("span:contains('"+identifier+"')").parent().html();
				location = $.trim(location.replace("<span>"+identifier+"</span>", ""));
			} else {
				
			}
			
			
			identifier = "Description:";
			var descriptionObj = $(this).find("span:contains('"+identifier+"')").parent();
			if (descriptionObj.length >0) {
				var description = $(this).find("span:contains('"+identifier+"')").parent().html();
				description = $.trim(description.replace("<span>"+identifier+"</span>", ""));
			}
			
			
			var url = $.trim($(this).find("span:contains('"+identifier+"')").parent().find("a:last").html());

			
			if (date == endDate) {
				if (start != "12:00 am") {
					startObj.html("<span>Time: </span>" + start + " - " + endTime);
					endObj.hide();
				} else {
					startObj.hide();
				}
			} else {
				dateObj.html(date + " - " + endDate);
				startObj.hide();
				endObj.hide();
			}
			
			if (url != "") {
				// has a link
				$(this).children(".gce-list-event").html("<a class='gce-list-event' href='"+url+"' target='_blank'>"+title+"</a>");
			}
		
			if (start == "12:00 am") {
//				alert("go");
			}
			
			
		});
	},
	
	hideEvents: function() {
		$(".gce-feed-1 p a:contains('More details...')").parent().hide();
		$(".gce-feed-2 p a:contains('More details...'), .gce-feed-2 div a:contains('More details...')").parent().hide();
	}

}

window.Core = Core;

$(document).ready(function(){Core.ondomready()});

})(jQuery);

