$(function(){
	
	read_more_text = '<p>Click ‘Read More’ to go to the About Events page.</p>';
	eai_text = '<p>From this page, if you would like to be involved, fill out the text box and click ‘Express An Interest’. We will contact you with further details.</p>'
	
	// info button
	$("#home-categories .category-info").click(function(e) {
		e.preventDefault();
		
		// get popup text from img title & construct content
		var popup_text = '';
		popup_text += '<p>' + $(this).attr('title') + '</p>' + read_more_text;
		if($(this).parent().find('div.category a').text() == 'Find Out More'){
		// find out more event types don't have view events so info button shows eai text
			popup_text += eai_text;
		}
		popup_text += '<p><a href="' + $(this).attr('href') + '" class="rl rl-green">Read more</a>';
		if ( $(this).parent().find("a").text() == 'View Events' ) popup_text += ' <a href="' + $(this).parent().find("a").attr("href") + '" class="rl rl-green">View events</a>';
		popup_text += ' <a href="#" class="unblockui rl">Close</a>';
		popup_text += '</p>';
		
		// populate popup
		$("div.popup").html(popup_text);
		
		// apply button styles as per global.js
		$(".rl").each(function(){
			nnevent.roundbutton($(this));
		});
			
		// initiate blockUI
		/* , css: { width: '500px', left: '35%'} */
		$.blockUI( {message: $("div.popup")} );
	})
	
	// find out more
	$("#home-categories .category a").click(function(e) {
		if($(this).text() == 'Find Out More'){
			e.preventDefault();
			
			// get popup text from img title & construct content
			var popup_text = '';
	
			popup_text += '<p>' + $(this).attr('title')+ '</p>' + read_more_text + eai_text + '<p><a href="' + $(this).attr('href') + '" class="rl rl-green">Read more</a> <a href="#" class="unblockui rl">Close</a></p>'
			
			// populate popup
			$("div.popup").html(popup_text);
			
			// apply button styles as per global.js
			$(".rl").each(function(){
				nnevent.roundbutton($(this));
			});
				
			// initiate blockUI
			$.blockUI( {message: $("div.popup"), css: { width: '30%', left: '35%'}} );
		}
	})

	$("#home-categories li div, #home-feedback li div").hover(
		function() { $(this).parent().addClass("rl-over")} ,
		function() { $(this).parent().removeClass("rl-over")}
	).click(function(){
		if($(this).find(" a").text() != 'Find Out More'){
			window.location = $(this).find("a").attr("href");
		}else{
			$(this).find("a").triggerHandler("click");
		}
	});
	
	// Area dropdown
	var url = $('#all-submit a').attr('href');
	$('#local_area').change(function(){
		$('#all-submit a').attr('href', (url + '/' + $('#local_area :selected').val()) );
	});
	$('#all-select').removeClass('hidden');
	$('#all-submit span').text('Get Involved!');
	// ee auto selects members chosen area so update submit button
	if ( $('#local_area :selected').val() != ''){
		$('#all-submit a').attr('href', (url + '/' + $('#local_area :selected').val()) );
	}
})
