/*
 * jQuery Plugin : jConfirmAction
 * 
 * by Hidayat Sagita
 * http://www.webstuffshare.com
 * Licensed Under GPL version 2 license.
 *
 */
(function($){

	jQuery.fn.jConfirmAction = function (options) {
		
		// Some jConfirmAction options (limited to customize language) :
		// question : a text for your question.
		// yesAnswer : a text for Yes answer.
		// cancelAnswer : a text for Cancel/No answer.
		var theOptions = jQuery.extend ({
			question: "Are You Sure ?",
			yesAnswer: "Yes",
			cancelAnswer: "Cancel",
			functionname: ""
		}, options);
		
		return this.each (function () {
			
			$(this).bind('click', function(e) {

				e.preventDefault();
				thisHref = $(this).attr('href');
				thisName = $(this).attr('name');
				
				if($(this).next('.jconfirm_question').length <= 0) {
					var marginleft = -87 - $(this).width()/2;
					$(this).after('<div class="jconfirm_question" style="margin-left:'+marginleft+'px;">'+theOptions.question+'<br/> <span class="jconfirm_yes">'+theOptions.yesAnswer+'</span><span class="jconfirm_cancel">'+theOptions.cancelAnswer+'</span></div>');
				}
				
				$(this).next('.jconfirm_question').animate({opacity: 1}, 300);
				
				$('.jconfirm_yes').bind('click', function(){
					if (theOptions.functionname=="") {
						window.location = thisHref;
					} else {
						eval(theOptions.functionname+'("'+thisName+'");');
					}
				});
		
				$('.jconfirm_cancel').bind('click', function(){
					$(this).parents('.jconfirm_question').fadeOut(300, function() {
						$(this).remove();
					});
				});
				
			});
			
		});
	}
	
})(jQuery);
