$(document).ready(function () {
	/*
	 * Click Delegate to open ColorBox and display more event information
	 */
	$( '.featuredSelectable .event_info_block').live( 'click', function ( event ) {
		
		if ( !$( event.target ).is('img, a') && ua_isMobile !== true ) {
			var id = $(this).data('id');
			var url = baseUrl + 'events/info-dialog/id/' + id;
			renderInfoDialog(url);
		}
		else {
			window.location.href = $( this ).data( 'link' );
		}
	});
	
	/*
	 * Click delegate to open ColorBox and display more venue information
	 */
	$( '.featuredSelectable .venue_info_block').live( 'click', function ( event ) {
		if ( !$( event.target ).is('img, a') && ua_isMobile !== true ) {
			var id = $(this).data('id');
			var url = baseUrl + 'places/info-dialog/id/' + id;
			renderInfoDialog(url);
		}
		else {
			window.location.href = $( this ).data( 'link' );
		}
	});

	/*
	 * Click delegate to open ColorBox and display more people information
	 */
	$( '.featuredSelectable .people_info_block').live( 'click', function ( event ) {
		if ( !$( event.target ).is('img, a') && ua_isMobile !== true ) {
			var id = $(this).data('id');
			var url = baseUrl + 'people/info-dialog/id/' + id;
			renderInfoDialog(url);
		}
		else {
			window.location.href = $( this ).data( 'link' );
		}
	});

	// Given a list of users navigate to the users profile page on click
	$( '.featuredSelectable .user_info_block' ).live( 'click', function ( event ) {
		event.preventDefault();
		var username = $( this ).data('username');

		window.location.href = baseUrl + 'users/' + username;
	});

	/**
	 * Renders info colorbox for an object using the specified url.
	 * @param url the url of the content to fetch
	 */
	function renderInfoDialog(url) {

		$.fn.colorbox({
			initialWidth: '400px',
			initialHeight: '20px',
			width: '600px',
			href: url
		});
	}
});

