function closePopups()
{
	$('.popup-dim-bg').fadeOut(500);
	$('.popup').fadeOut(500);
}

(function($) {
	//Attach this new method to jQuery  
	$.fn.extend({
		//This is where you write your plugin's name  
		popup: function(options) {  
			var defaults = {
				onconfirm: function(){return true;},
				oncancel: function(){return true;},
				width: 445
			};
			var options =  $.extend(defaults, options);

			//Iterate over the current set of matched elements  
			return this.each(function() {
				var opt = options;
				var obj = $(this);
				
				if( ! $('.popup-dim-bg').length )
					$('body').append('<div class="popup-dim-bg"></div>');
				$('.popup-dim-bg')
					.fadeTo(1, 0.5)
					.css({
						'height' : $(document).height(),
						'width' : $(document).width()
					})
					.fadeIn(500)
					.click(function() {
						$(this).fadeOut(500);
						obj.fadeOut(500);
					});
				
				obj.find('input').focus();

				obj.css({
					'left' : ($(window).width() - obj.width())/2,
					'top' : Math.min(200, ($(window).height() - obj.height())/2),
					'width': opt.width + 'px'
				}).fadeIn(500);

				obj.find('.popup-content').css({
					'width': (opt.width - 2) + 'px'
				});
				obj.find('.popup-bottom').css({
					'width': (opt.width - 22) + 'px'
				});
				
				obj.find('.popup-confirm').unbind('click').click(function() {
					if( opt.onconfirm(this) )
					{
						$('.popup-dim-bg').fadeOut(500);
						obj.fadeOut(500);
					}
					return false;
				});

				obj.find('.popup-cancel').unbind('click').click(function() {
					if( opt.oncancel(this) )
					{
						$('.popup-dim-bg').fadeOut(500);
						obj.fadeOut(500);
					}
					return false;
				});

			});
		}
	});
})(jQuery);


/* Facebook prompt style popup */
(function($) {
	//Attach this new method to jQuery  
	$.fn.extend({
		//This is where you write your plugin's name  
		popup_fb: function(options) {  
			var defaults = {
				onconfirm: function(){return true;},
				oncancel: function(){return true;},
				onclose: function(){return true;}
			};
			var options =  $.extend(defaults, options);

			//Iterate over the current set of matched elements  
			return this.each(function() {
				var opt = options;
				var obj = $(this);

				obj.find('.popup-confirm').click(function() {
					if( opt.onconfirm(this) )
					{
						obj.slideUp(200);
					}
				});

				obj.find('.popup-cancel').click(function() {
					if( opt.oncancel(this) )
					{
						obj.slideUp(200);
					}
				});
				
				obj.find('.popup-close').click(function() {
					if( opt.onclose(this) )
					{
						obj.slideUp(200);
					}
				});

			});
		}
	});
})(jQuery);
