jQuery(document).ready(function() {
		jQuery("a[rel^='prettyPhoto']").prettyPhoto({
				padding: 30,
				opacity: 0.5
		});
		
		var imgParent = jQuery('.osp_gallery').parent();
		
		var imgHeight = jQuery('.osp_gallery').height();
		
		if (imgHeight > imgParent.height())
		{
			var heightToSet = imgHeight + 12;
			var elemToSetHeight = imgParent;
			var elem = imgParent.next(); 
			var i = 0;
			while (!elem.is("table") && i < 5)
			{
				if (!elem.is("style") && !elem.is("script"))
				{
					heightToSet = heightToSet - elemToSetHeight.height();
					if(heightToSet < 0)
						break;
					elemToSetHeight = elem;
				}
				elem = elem.next();
				++i;
			}
			if (elem.is("table"))
			{
				elemToSetHeight.css('height', heightToSet);
			}
		}
		
		jQuery('.osp_gallery').click(function() {
				jQuery("a[rel^='prettyPhoto']:first").trigger('click');
		}).wrap('<div style="float:right; position: relative; width: 197px; border: none; margin: 0px; padding: 0px;"></div>').after('<div id="osp_gallery_overlay" style="filter: alpha(opacity=75); opacity: 0.75; position: absolute; left: 11px; bottom: 20px; width: 175px; height: 30px; border-top: 1px solid #fff; background-color: #fff; z-index: 5;"></div>').after('<div style="position: absolute; bottom: 20px; width: 100%; height: 25px; padding-top: 10px; text-align: center; color: #444; background-color: transparent; cursor: pointer; font-weight: bold; z-index: 10;" id="osp_gallery_link">Bildergalerie öffnen</div>');
		jQuery('#osp_gallery_link').click(function() {
				jQuery("a[rel^='prettyPhoto']:first").trigger('click');
		});
		
		if(jQuery.browser.msie && jQuery.browser.version.search(/^7/) != -1)
		{
			jQuery("#osp_gallery_overlay").css('left', '21px');
			jQuery("#osp_gallery_link").css('left', '11px');
		}
		if(jQuery.browser.msie && jQuery.browser.version.search(/^6/) != -1)
		{
			jQuery("#osp_gallery_overlay").css('left', '21px');
			jQuery("#osp_gallery_link").css('left', '11px');
		}
}
);


