(function($){
	$.fn.popuptool = function(options){
		
		var defaults =	{
			leftPos: 0,
			topPos: 0,
			btnClose: '.btnClose',
			triggerType: 'click'
		}
		
		var opt = $.extend(defaults, options);
		
		var obj = $(this);
		
		for (var a = 0; a < obj.length; a++){
			$(obj.eq(a).attr('href')).show();
		}
		
		if (opt.triggerType == "click"){
			obj.click(function(e){
				e.preventDefault();
				
				var thisObj = $(this);
				var poplink = $(this).attr('href');
				var offset = $(this).offset();
				
				$(poplink).show().css({
					'position': 'absolute',
					'z-index': 500,
					'left': offset.left + (opt.leftPos),
					'top': offset.top + (opt.topPos)
				});
				
				$(poplink).find(opt.btnClose).click(function(){
					$(this).parent().hide();
				});
				
				$(window).resize(function(){
					var offset = thisObj.offset();
					$(poplink).css({
						'position': 'absolute',
						'z-index': 100,
						'left': offset.left + (opt.leftPos),
						'top': offset.top + (opt.topPos)
					});
				});
			});
		} else if (opt.triggerType == "rollover"){
			obj.hover(function(e){
				e.preventDefault();
							
				var thisObj = $(this);
				var poplink = $(this).attr('href');
				var offset = $(this).offset();
				
				$(poplink).show().css({
					'position': 'absolute',
					'z-index': 500,
					'left': offset.left + (opt.leftPos),
					'top': offset.top + (opt.topPos)
				});
				
				$(poplink).find(opt.btnClose).click(function(){
					$(this).parent().hide();
				});
				
				$(window).resize(function(){
					var offset = thisObj.offset();
					$(poplink).css({
						'position': 'absolute',
						'z-index': 100,
						'left': offset.left + (opt.leftPos),
						'top': offset.top + (opt.topPos)
					});
				});
			}, function(){
				
			});
		}
		
	}
})(jQuery);
