function Sticky()
{
	stickyObj  = this;
		
	this.attachEvents();
}

Sticky.prototype.attachEvents = function()
{
	jQuery('.item_right .sticky a').click(function(event)
	{
     	stickyObj.sticky(event.target);
		return false;
	});

	jQuery('.unsticky a').click(function(event)
	{
		wrap = event.target.parentNode.parentNode.parentNode;
		
     	stickyObj.unsticky(wrap);
		return false;
	});
};

Sticky.prototype.sticky = function(target)
{
	itemWrap = jQuery(target.parentNode.parentNode.parentNode);
	stickied = itemWrap.clone();
	itemWrap.hide();

	currentSticky = jQuery('.sticky.current');
	
	if (currentSticky.length > 0)
	{
		this.unsticky(jQuery('.sticky.current').get(0));	
	}  
	
	aTag = stickied.find('.sticky a');
	
	aTag.html('&#x2193; unsticky this!').unbind().click(function(event)
	{
		wrap  = event.target.parentNode.parentNode.parentNode;
		stickyObj.unsticky(wrap);
		return false;
	});

	stickied.attr('id', itemWrap.attr('id')+'_sticky');
	stickied.addClass('sticky').addClass('current');
	jQuery("#left_side").prepend(stickied);

	jQuery("body").ScrollTo();
	
	x_sticky(itemWrap.attr('id').replace('activity_',''), function(result)
	{
	}); 
};

Sticky.prototype.unsticky = function(wrap)
{
	unstickyWrap = jQuery(wrap);
	activityId  = unstickyWrap.attr('id').replace('_sticky', '');

	unsticky = jQuery('#'+activityId);
	unsticky.slideDown();

	unstickyWrap.slideUp(function()
	{
		unstickyWrap.remove();
	});
	
	x_unsticky(activityId.replace('activity_', ''), function(result)
	{
	}); 
};

jQuery(document).ready(function()
{
	sticky = new Sticky();
});
