﻿/*
*	jQuery.reclick
*	Copyright (c) 2008 Petr Staníček (pixy@pixy.cz)
*	February 2009
*
*	requires jQuery.cookie.js plugin
*	target elements must have an ID

Store clicks example:

	jQuery('#menu .tabs').storeclick('tabs');

=> on click creates cookie: reclick#tabs = ID of clicked element
(if the target has no ID, no reclick is stored)

Revoke clicks usage:

	jQuery.reclick('tabs');

=> clicks element of stored ID

*/

jQuery.fn.storeclick = function(reclickName,cookieExpires,cookiePath) {
	if (cookieExpires==undefined) cookieExpires = 60;	// days
	if (cookiePath==undefined) cookiePath = '/';		// valid for entire web
	var cName = 'reclick#' + reclickName;
	return this.each( function() {
		jQuery(this).bind('click', function(){
			var id = this.id;
			if (id) jQuery.cookie(cName,id,{expires:cookieExpires,path:cookiePath});
			});
		});
	}

jQuery.reclick = function(reclickName) {
	var cName = 'reclick#' + reclickName;
	var id = jQuery.cookie(cName);
	if (id) jQuery('#'+id).click();
	}

