	(function($){

	$.fn.extend({

		//pass the options variable to the function
		polaroidOverlay: function(opt) {

			//Set the default values, use comma to separate the settings:
			var defaults = {
				overlayImage	:	'#centercolumn',
				stopElement		:	'#forfatter-info-wrapper',
				overlayClass	:	'polaroid-hover-zoom'
			}

			var options =  $.extend(defaults, opt);

			$(this).parent().each(function() {

				var el = document.createElement('div');
				$(el).css({
					'position'	: 'absolute',
					'z-index'	: 900,
					'zoom'	: 1,
					'display'	: 'none',
					'cursor'	: 'pointer',
					//'opacity'	: '0.0',
					'top'		: (($(this).height()-100)/2),
					'left'		: (($(this).width()-100)/2)
				}).attr('title','Klik på billedet for at se det i stor størrelse').append('<div class="polaroid-hover-back"></div><div class="'+options.overlayClass+'"></div>');

				/* Required for IE */
				$(this).append(el).css({
					'position'	: 'relative'
				});

				$(el).bind('click', function() {

					var myregexp = /handleOversize:'([^']+)'/i;
					var match = myregexp.exec($(this).prev().attr('rel'));

					if (match != null) {
						Shadowbox.open({
							options	: {
								handleOversize	: match[1],
								preserveAspectWhileResizing : 1,
								overlayColor : '#333333'
							},
							player	: 'img',
					        	content	: $(this).prev()[0].href,
					        	title		: $(this).prev().attr('title')
					    });
					}
					else {
						Shadowbox.open({
							options	: {
								handleOversize	: 'resize',
								preserveAspectWhileResizing : 1,
								overlayColor : '#333333'
							},
							player	: 'img',
					        	content	: $(this).prev()[0].href,
					        	title		: $(this).prev().attr('title')
					    });
					}

					return false;

				});

				$(this).bind('mouseenter',function() {
/*
					$(el).animate({
						'opacity': '1.0'
					},'fast');
*/
					$(el).show();
				}).bind('mouseleave',function() {
/*
					$(el).animate({
						'opacity': '0.0'
					},'fast');
*/
					$(el).hide();
				});

			})

		}
	});
})(jQuery);


/* Additional JS for creating tooltip. Not part of the above */

$(window).load(function() {
	$(".polaroidgtip").each(function() {
		$(this).simpletip({
			fixed: false,
			offset: [12,12],
			content: $(this).attr('title'),
			onBeforeShow: function(){
				var el = this.getParent();
				// Save title attribute
				$.data(el, 'title', el.attr('title'));
				// Clear title attribute
				el.attr('title','');
			},
			onHide: function(){
				var el = this.getParent();
				// Restore title attribute
				el.attr('title',$.data(el, 'title'));
			}
		});
	});
});


