jq(function() {
	jq('.quick_tip').cluetip({ 
		sticky: true, 
		mouseOutClose: true, 
		arrows: true, 
		local: true,
		closePosition: 'title', 
		closeText: '<img src="/images/qtip/cross.gif" alt="close" />',
		fx: { open: 'fadeIn', openSpeed: 'normal' }
	});
	
  set_brochure_list_state();
  	
	jq('.tipped').cluetip({ 
		sticky: true, 
		mouseOutClose: true, 
		arrows: true, 
		local: true,
		closePosition: 'title', 
		closeText: '<img src="/images/qtip/cross.gif" alt="close" />',
		onShow: function() { jq('.brochure_list:last').show() },
		fx: { open: 'fadeIn', openSpeed: 'normal' }
	}).click(function() {
		var community_name = jq(this).parents('div.community_name').find('h2 a').html().strip(),
				b_list         = jq('#brochure_list .brochure_list'),
				brochure_ids   = jq('#brochure_ids'),
				ids_array      = brochure_ids.val() ? brochure_ids.val().split(',') : [];
					
		// add, del
		if ( this.checked == true ) {
			if ( ids_array.indexOf(this.id) == -1 ) {
				ids_array.push(this.id);
				brochure_ids.val(ids_array.toString());
				if ( jq('.empty').length )
					jq('.empty').remove();
				jq('.brochure_list').append("<li class="+this.id+">" + community_name + "</li>");
			}
		} else {
			var i = ids_array.indexOf(this.id);
			if ( i != -1 ) {
				ids_array.splice(i, 1);
				brochure_ids.val(ids_array.toString());
				jq('li.'+this.id).remove();
				if ( !ids_array.length )
					jq('.brochure_list').append('<li class="empty">There are no Brochures in your list.</li>');
			}
		}
		
    // update query string for multi-brochure request
		jq('#quick_request_btn a').get(0).search = 'brochure_ids=' + jq('#brochure_ids').val();
	});
});