if(jQuery) (function($) {
	$.tooltip = {
		defaults: {
			xOffset: -20,
			yOffset: -15,
			format: false // gibt an ob der tooltip text bei einem / formatiert werden soll
		},
		publicVariable: [],
		format: function(useClass, text) {
			var format = new String();
			format += '<div class="jq-box ' + useClass + '" style="position:absolute; float:left; display:none;">'
			format += '<table cellpadding="0" cellspacing="0" border="0"><tbody>'
			format += '<tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr>'
			format += '<tr><td class="l"></td>'
			format += '<td class="c">'
			format += '<div class="err"><p>' + text + '</p></div></td>'
			format += '<td class="r"></td></tr>'
			format += '<tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr>'
			format += '</tbody></table></div>';
			return format;
		}
	};
	$.infotip = {
		defaults: {
			xOffset: 30,
			yOffset: 35
		},
		publicVariable: [],
		format: function(useClass, text) {
			var format = new String();
			format += '<div class="jq-box ' + useClass + '" style="float:left; display:none;">'
			format += '<table cellpadding="0" cellspacing="0" border="0"><tbody>'
			format += '<tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr>'
			format += '<tr><td class="l"></td>'
			format += '<td class="c">'
			format += '<div class="err"><p>' + text + '</p></div><a class="close"></a></td>'
			format += '<td class="r"></td></tr>'
			format += '<tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr>'
			format += '</tbody></table></div>';
			return format;
		}
	};
	// Prototype Methods
	$.fn.extend({
		showFix: function() {
			if($.browser.msie) {
				$(this).stop().css('display', 'block');
			} else {
				$(this).stop().animate({opacity:1}, 'fast', function(){$(this).show();});
			}
		},
		hideFix: function() {
			if($.browser.msie) {
				$(this).stop().css('display', 'none');
			} else {
				$(this).stop().animate({opacity:0}, 'fast', function(){$(this).hide();});
			}
		},
		tooltip: function(options) {
			var options = $.extend( {}, $.tooltip.defaults, options );
			var $tbox = $('.jq-tbx.tooltip');
			var $content = $tbox.find('.c P');
			return this.each(function() {
				var $this = $(this);
				// Support for the Metadata Plugin
				var o = $.metadata ? $.extend( {}, options, $this.metadata() ) : options;
				// nur wenn ein title existiert events setzen
				if (this.title != "") {
					$this.hover(function(e) {
						this.c = this.title;
						this.memo = this.title;
						this.title = "";
						if (o.format) {
							var str = this.c.split('/');
							if (str[1] != null)
								this.c = '<strong>'+str[0]+'</strong> / '+str[1];
							if (str[2] != null)
								this.c += '<p>'+str[2]+'</p>';
						}
						setPosition(e);
						$content.html(this.c);
						$tbox.showFix();//$tbox.stop().animate({opacity:1}, 'fast', function(){$tbox.show();});
					}, function(e) {
						this.title = this.memo;
						$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
					});
					$this.bind("mousemove",function(e) {
						setPosition(e);
					});
					function setPosition(e) {
						return $tbox
							.css("top",(e.pageY - $.tooltip.defaults.yOffset) + "px")
							.css("left",(e.pageX + $.tooltip.defaults.xOffset) + "px");
					};
				}
			});
		},
		infotip: function() {
			var options = $.extend( {}, $.infotip.defaults, options );
			var $tbox = $('.jq-ibx');
			var $content = $tbox.find('.c P');
			return this.each(function() {
				var $this = $(this);
				// Support for the Metadata Plugin
				var o = $.metadata ? $.extend( {}, options, $this.metadata() ) : options;
				
				$this.click(function(e) {
					if ($this.hasClass('active')) {
						$this.removeClass('active');
						this.title = this.c;
						$('body').unbind('mousedown');
						$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
					} else {
						var c = this.c = this.title;
						this.title = "";
						setPosition(e);
						$content.html(this.c);
						$this.addClass('active');
						$tbox.showFix();//$tbox.stop().animate({opacity:1}, 'fast', function(){$tbox.show();});
						/*
						$('body').bind('mousedown', function(event) {
							this.title = this.c;
							$this.removeClass('active');
							$(this).unbind('click');
							$('body').unbind('mousedown');
							$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
						});*/
						$tbox.find('.close').click(function() {
							$this.attr('title', c);
							$this.removeClass('active');
							$(this).unbind('click');
							$('body').unbind('mousedown');
							$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
						});
					}
				});
				function setPosition(e) {
					var offset = $this.offset();
					return $tbox
						.css("top",(offset.top - $this.height()/2) + "px")
						.css("left",(offset.left + $this.width() + $.infotip.defaults.xOffset) + "px");
				};
			});
		},
		// Technische Daten
		infotipClick: function() {
			var options = $.extend( {}, $.infotip.defaults, options );
			var $tbox = $('.jq-ibx');
			var $content = $tbox.find('.c P');
			var $icons = $('#product-icons');//.html();
			var $this = $(this).parent();
			// Support for the Metadata Plugin
			var o = $.metadata ? $.extend( {}, options, $this.metadata() ) : options;
			$icons.show();
			$content.html($icons);
			var doClick = function() {
				if ($this.hasClass('active')) {
					$this.removeClass('active');
					$('body').unbind('mousedown');
					$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
				} else {
					this.title = "";
					setPosition();
					//$content.html("");
					//$content.html($icons);
					$('.product-icons IMG').tooltip();
					$this.addClass('active');
					$tbox.showFix();//$tbox.stop().animate({opacity:1}, 'fast', function(){$tbox.show();});
					/* */
					$('body').bind('mousedown', function(event) {
						$this.removeClass('active');
						$(this).unbind('click');
						$('body').unbind('mousedown');
						$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
					});
					$tbox.find('.close').click(function() {
						$this.removeClass('active');
						$(this).unbind('click');
						$('body').unbind('mousedown');
						$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
					});
				}
			};
			function setPosition() {
				var offset = $this.offset();
				return $tbox
					.css("top",(offset.top - $this.height()/2) + $.infotip.defaults.yOffset + 5 + "px");
					//.css("margin-left",($this.width() + $.infotip.defaults.xOffset) + "px");
					//.css("left",(offset.left + $this.width() + $.infotip.defaults.xOffset) - 20 + "px");
			};
			doClick();
			//return false;
		},
		genericTip: function(options) {
			var options = $.extend( {}, $.infotip.defaults, options );
			var $tbox = $('.jq-gbx');
			var $inner = $tbox.find('.c P');
			var $content = $(options.content);
			var $this = $(this).parent();
			$content.show();
			$inner.html($content);
			var doClick = function() {
				if ($this.hasClass('active')) {
					$this.removeClass('active');
					$('body').unbind('mousedown');
					$tbox.hideFix();
				} else {
					this.title = "";
					setPosition();
					$('.product-icons IMG').tooltip();
					$this.addClass('active');
					$tbox.showFix();
					$('body').bind('mousedown', function(event) {
						$this.removeClass('active');
						$(this).unbind('click');
						$('body').unbind('mousedown');
						$tbox.hideFix();
					});
					$tbox.find('.close').click(function() {
						$this.removeClass('active');
						$(this).unbind('click');
						$('body').unbind('mousedown');
						$tbox.hideFix();
					});
				}
				return false;
			};
			function setPosition() {
				var offset = $this.offset();
				return $tbox
					.css("top",(offset.top - $this.height()/2) + $.infotip.defaults.yOffset - 25 + "px");
					//.css("margin-left",($this.width() + $.infotip.defaults.xOffset) + "px");
					//.css("left",(offset.left + $this.width() + $.infotip.defaults.xOffset) - 20 + "px");
			};
			$(this).click(doClick);
			//return false;
		},
		imgtip: function(options) {
			var options = $.extend( {}, $.tooltip.defaults, options );
			var $tbox = $('.jq-imgbx');
			var $content = $tbox.find('.c P');
			return this.each(function() {
				var $this = $(this);
				// Support for the Metadata Plugin
				var o = $.metadata ? $.extend( {}, options, $this.metadata() ) : options;
				$this.hover(function(e) {
					//this.c = $(this).find('IMG').clone();
					this.c = $(this).clone();
					setPosition(e);
					$content.html(this.c);
					$tbox.showFix();//$tbox.stop().animate({opacity:1}, 'fast', function(){$tbox.show();});
				}, function(e) {
					//this.c.empty();
					$tbox.hideFix();//$tbox.stop().animate({opacity:0}, 'fast', function(){$tbox.hide();});
				});
				$this.bind("mousemove",function(e) {
					setPosition(e);
				});
				function setPosition(e) {
					return $tbox
						.css("top",(e.pageY - $.tooltip.defaults.yOffset) + "px")
						.css("left",(e.pageX + $.tooltip.defaults.xOffset) + "px");
				};
			});
		}
	});
	//Initialization Code
	$(function() { 
		$('body').append($.tooltip.format("jq-tbx tooltip","Default"));
		$('body.page-product .container').prepend($.infotip.format("jq-ibx","Default"));
		$('body.page-collection').append($.tooltip.format("jq-imgbx","Default"));
		$('.jqinfo').infotip();
		$('.jqtip').tooltip();
		
		$('body.page-product .container').prepend($.infotip.format("jq-gbx jq-downloads","Default"));
		$('#downloads').genericTip({content:'#product-downloads', xOffset: 30, yOffset: -35});
	});
})(jQuery);