function gce_ajaxify(target, feed_ids, max_events, title_text, type){
	//Add click event to change month links
	jQuery('#' + target + ' .gce-change-month').click(function(){
		//Extract month and year
		var month_year = jQuery(this).attr('name').split('-', 2);
		//Add loading text to table caption
		jQuery('#' + target + ' caption').html("<h2 style='margin-top: 0px; padding-top: 0px; text-align: right;'>Loading...</h2>");
		updateCufonText();
		//Send AJAX request
		jQuery.get(GoogleCalendarEvents.ajaxurl,{
			action:'gce_ajax',
			gce_type:type,
			gce_feed_ids:feed_ids,
			gce_title_text:title_text,
			gce_widget_id:target,
			gce_max_events:max_events,
			gce_month:month_year[0],
			gce_year:month_year[1]
		}, function(data){
			//Replace existing data with returned AJAX data
			if(type == 'widget'){
				jQuery('#' + target).html(data);
			}else{
				jQuery('#' + target).replaceWith(data);
			}
			gce_tooltips('#' + target + ' .gce-has-events');
			updateCufonText();
		});
	});
}

function gce_tooltips(target_items){
	var sidebar = jQuery("#sidebar");
	jQuery(target_items).each(function(){
		jQuery(this).bind("click",function() {
			var allSelected = jQuery(".gce-has-events.selected");
			allSelected.removeClass("selected");
			jQuery(this).addClass("selected");
			sidebar.html(jQuery(this).children(".gce-event-info").html());
			var title = jQuery("#sidebar .gce-tooltip-title"),
				newTitle = jQuery("<h3 />",{
					"class"	:	"calendar",
					text	:	title.text(),
					style	:	"font-size: 20px; color:#828593;"
				});
			title.replaceWith(newTitle);
			updateCufonText();
   			return false;
		});
		//Add qtip to all target items
		/*jQuery(this).qtip({
			content: jQuery(this).children('.gce-event-info'),
			position: { corner: { target: 'center', tooltip: 'bottomLeft' }, adjust: { screen: true } },
			hide: { fixed: true, delay: 100, effect: { length: 0 } },
			show: { solo: true, delay: 0, effect: { length: 0 } },
			style: { padding: "0", classes: { tooltip: 'gce-qtip', tip: 'gce-qtip-tip', title: 'gce-qtip-title', content: 'gce-qtip-content', active: 'gce-qtip-active' }, border: { width: 0 } }
		});*/
	});
}
function updateCufonText() {
	
	// This is the CUFON FONT target. All elements are targeted individually for complete control. Delete or add as you wish., 
   Cufon.replace("h1, h2, h3, h4, h5, h6, span.port_4_title, a.cycle_cta, .sc_button, blockquote, .portfolio_item_4_col span.portfolio_title, a.blog_button, a.tagline_button, .testimonial_quote", {hover: true});
}

jQuery(document).ready(function(){
	gce_tooltips('.gce-has-events');
});
