function fbhoroscopes_share(params) {
	var the_url = 'http://www.tarot.com/astrology/daily-horoscope/'+params.sign_name.toLowerCase()+'-horoscope/';
	var todays_date = new Date();
	var months = ['Jan','Feb','Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec'];
	var days   = ['Sun','Mon','Tues','Wed','Thu','Fri','Sat'];
	var date_string = days[ todays_date.getDay() ] + ", " + 
	                  months[ todays_date.getMonth() ] + " " + 
	                  todays_date.getDate() + ", " +
	                  todays_date.getFullYear();
	var attachment = {
		title: 'Your ' + params.sign_name + ' horoscope for today from Tarot.com',
		media: [{
			type: 'image',
			src:  'http://gfx.tarot.com/images/astrology/sun-signs/90x90/' +params.sign+ '.gif',
			href: the_url
		}],
		description: params.text,
		properties: {Sign: params.sign_name},
		name: params.sign_name + ' Horoscope: ' + date_string,
		href: the_url,
		caption: 'www.tarot.com'
	};
	var action_links = [
		{
			text: 'View your horoscope',
			href: the_url
		}
	];
	FB.Connect.streamPublish(attachment.title, attachment, action_links, params.uid, '', function(){
		// this is a no-op for now
	});
}

function fbhoroscopes_init(fb_api_key, wrapper_div_id) {
	FB.init(fb_api_key, '/facebook/xd_receiver.htm');
	var sel = '#' + wrapper_div_id;
	var _show = function(elem) {
		var more = $(".more a", elem);
		more.text('Less').attr('title','Hide full horoscope');
		$(".horo .short", elem).animate({height:'hide',opacity:'hide'}, 250);
		$(".horo .full", elem).animate({height:'show',opacity:'show'}, 250);
		$(elem).addClass('expanded');
	};
	var _hide = function(elem) {
		var more = $(".more a", elem);
		more.text('More').attr('title','Show full horoscope');
		$(".horo .short", elem).animate({height:'show',opacity:'show'}, 250);
		$(".horo .full", elem).animate({height:'hide',opacity:'hide'}, 250);
		$(elem).removeClass('expanded');
	};
	$(sel+" .friend-list .more a").click(function(e){
		var c=$(this).parents(".friend");
		if (c.hasClass('expanded')) {
			_hide(c);
		} else {
			$(sel+" .friend").not(c).each(function(){
				if ($(this).hasClass('expanded')) {
					_hide(this);
				}
			});
			_show(c);
		}
		e.preventDefault();
	});
	

	$(sel+" div.page:first").css('display','block');
	var current_page = 0;
	var flipping = false;

	var change_to_page = function(new_page) {
//		window.console.log("bombar", $(sel+" div.page").length);
		if (new_page == current_page || $(sel+" div.page").length < 2) {
			return;
		}
		var last_page = $(sel+" div.page").length - 1;
		
		var reverse = false;
		if      (new_page < 0) { new_page = last_page; reverse = true; }
		else if (new_page > last_page) { new_page = 0; reverse = true; }
		
		
		var o_start=0, o_end=265, n_start=-265, n_end=0;
		if (new_page > current_page) {
			o_end   = -265;
			n_start = 265;
		}
		if (reverse) {
			if ( o_end == -265 ) {
				o_end   = 265;
				n_start = -265;
			} else {
				o_end   = -265;
				n_start = 265;
			}
		}
		flipping = true;
		var _box = $(sel+' .friend-list').css({});
		var _old = $('.page', _box).eq(current_page);
		var _new = $('.page', _box).eq(new_page);

		var _go = function(){
			_box.css({position: 'relative', height: 265});
			_old.css({position: 'absolute', top:o_start});
			_new.css({position: 'absolute', display: 'block', top:n_start});
			_old.animate({top:o_end}, 250);
			_new.animate({top:n_end}, 250, function(){
				_old.css({display:'none',position:'static'});
				_new.css({position:'static'});
				_box.css({height:'auto'});
				current_page = new_page;
				flipping = false;
			});
		}

		if (_old.find(".friend.expanded").length > 0) {
			_old.find(".friend.expanded").each(function(){ _hide(this); });
			window.setTimeout(_go, 250);
		} else {
			_go();
		}
	}
	

	if ( $(sel+" div.page").length > 1) {
		$(sel+" a.scroll-up").click(function(e){
			if (flipping){ return; }
			change_to_page(current_page-1);
			e.preventDefault();
		});
		$(sel+" a.scroll-down").click(function(e){
			if (flipping){ return; }
			change_to_page(current_page+1);
			e.preventDefault();
		});
	} else {
		$(sel+" div.buttons a").click(function(e){ e.preventDefault(); }).attr('title','').css('cursor','default');
		$(sel+" div.buttons").addClass('buttons-inactive');
	}

	$(sel+" .heading").click(function(){
		var disclose = $('.disclose', this);
		if (disclose.hasClass('disclose-hidden')) {
			$(".friend-list, .buttons, .sub-heading", sel).animate({height:'show',opacity:'show'}, 250);
			disclose.removeClass('disclose-hidden');
		} else {
			$(".friend-list, .buttons, .sub-heading", sel).animate({height:'hide',opacity:'hide'}, 250);
			disclose.addClass('disclose-hidden');
		}
	});

	$(sel+" .friend").hover(function(){
		$(this).addClass('friend-hover');
	},
	function(){
		$(this).removeClass('friend-hover');
	});
}

