/*
 * jQuery Tools 1.2.5 - The missing UI library for the Web
 *
 * [overlay, toolbox.expose]
 *
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 *
 * http://flowplayer.org/tools/
 *
 * File generated: Mon Feb 28 02:33:34 GMT 2011
 */
(function(a) {
	function t(d, b) {
		var c = this, j = d.add(c), o = a(window), k, f, m, g = a.tools.expose
				&& (b.mask || b.expose), n = Math.random().toString().slice(10);
		if (g) {
			if (typeof g == "string")
				g = {
					color : g
				};
			g.closeOnClick = g.closeOnEsc = false;
		}
		var p = b.target || d.attr("rel");
		f = p ? a(p) : d;
		if (!f.length)
			throw "Could not find Overlay: " + p;
		d && d.index(f) == -1 && d.click(function(e) {
			c.load(e);
			return e.preventDefault();
		});
		a.extend(c, {
			load : function(e) {
				if (c.isOpened())
					return c;
				var h = q[b.effect];
				if (!h)
					throw 'Overlay: cannot find effect : "' + b.effect + '"';
				b.oneInstance && a.each(s, function() {
					this.close(e);
				});
				e = e || a.Event();
				e.type = "onBeforeLoad";
				j.trigger(e);
				if (e.isDefaultPrevented())
					return c;
				m = true;
				g && a(f).expose(g);
				var i = b.top, r = b.left, u = f.outerWidth( {
					margin : true
				}), v = f.outerHeight( {
					margin : true
				});
				if (typeof i == "string")
					i = i == "center" ? Math.max((o.height() - v) / 2, 0)
							: parseInt(i, 10) / 100 * o.height();
				if (r == "center")
					r = Math.max((o.width() - u) / 2, 0);
				h[0].call(c, {
					top : i,
					left : r
				}, function() {
					if (m) {
						e.type = "onLoad";
						j.trigger(e);
					}
				});
				g && b.closeOnClick && a.mask.getMask().one("click", c.close);
				b.closeOnClick && a(document).bind("click." + n, function(l) {
					a(l.target).parents(f).length || c.close(l);
				});
				b.closeOnEsc && a(document).bind("keydown." + n, function(l) {
					l.keyCode == 27 && c.close(l);
				});
				return c;
			},
			close : function(e) {
				if (!c.isOpened())
					return c;
				e = e || a.Event();
				e.type = "onBeforeClose";
				j.trigger(e);
				if (!e.isDefaultPrevented()) {
					m = false;
					q[b.effect][1].call(c, function() {
						e.type = "onClose";
						j.trigger(e);
					});
					a(document).unbind("click." + n).unbind("keydown." + n);
					g && a.mask.close();
					return c;
				}
			},
			getOverlay : function() {
				return f;
			},
			getTrigger : function() {
				return d;
			},
			getClosers : function() {
				return k;
			},
			isOpened : function() {
				return m;
			},
			getConf : function() {
				return b;
			}
		});
		a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),
				function(e, h) {
					a.isFunction(b[h]) && a(c).bind(h, b[h]);
					c[h] = function(i) {
						i && a(c).bind(h, i);
						return c;
					};
				});
		k = f.find(b.close || ".close");
		if (!k.length && !b.close) {
			k = a('<a class="close"></a>');
			f.prepend(k);
		}
		k.click(function(e) {
			c.close(e);
		});
		b.load && c.load();
	}
	a.tools = a.tools || {
		version : "1.2.5"
	};
	a.tools.overlay = {
		addEffect : function(d, b, c) {
			q[d] = [ b, c ];
		},
		conf : {
			close : null,
			closeOnClick : true,
			closeOnEsc : true,
			closeSpeed : "fast",
			effect : "default",
			fixed : !a.browser.msie || a.browser.version > 6,
			left : "center",
			load : false,
			mask : null,
			oneInstance : true,
			speed : "normal",
			target : null,
			top : "10%"
		}
	};
	var s = [], q = {};
	a.tools.overlay.addEffect("default", function(d, b) {
		var c = this.getConf(), j = a(window);
		if (!c.fixed) {
			d.top += j.scrollTop();
			d.left += j.scrollLeft();
		}
		d.position = c.fixed ? "fixed" : "absolute";
		if ( $.browser.msie ) {
			this.getOverlay().css(d).show();
		}
		else
		{
			this.getOverlay().css(d).fadeIn(c.speed, b);
		}
	}, function(d) {
		if ( $.browser.msie ) {
			this.getOverlay().hide();
		}
		else
		{
			this.getOverlay().fadeOut(this.getConf().closeSpeed, d);	
		}
	});
	a.fn.overlay = function(d) {
		var b = this.data("overlay");
		if (b)
			return b;
		if (a.isFunction(d))
			d = {
				onBeforeLoad : d
			};
		d = a.extend(true, {}, a.tools.overlay.conf, d);
		this.each(function() {
			b = new t(a(this), d);
			s.push(b);
			a(this).data("overlay", b);
		});
		return d.api ? b : this;
	};
})(jQuery);
(function(b) {
	function k() {
		if (b.browser.msie) {
			var a = b(document).height(), d = b(window).height();
			return [
					window.innerWidth || document.documentElement.clientWidth
							|| document.body.clientWidth, a - d < 20 ? d : a ];
		}
		return [ b(document).width(), b(document).height() ];
	}
	function h(a) {
		if (a)
			return a.call(b.mask);
	}
	b.tools = b.tools || {
		version : "1.2.5"
	};
	var l;
	l = b.tools.expose = {
		conf : {
			maskId : "exposeMask",
			loadSpeed : "slow",
			closeSpeed : "fast",
			closeOnClick : true,
			closeOnEsc : true,
			zIndex : 9998,
			opacity : 0.8,
			startOpacity : 0,
			color : "#333333",
			onLoad : null,
			onClose : null
		}
	};
	var c, i, e, g, j;
	b.mask = {
		load : function(a, d) {
			if (e)
				return this;
			if (typeof a == "string")
				a = {
					color : a
				};
			a = a || g;
			g = a = b.extend(b.extend( {}, l.conf), a);
			c = b("#" + a.maskId);
			if (!c.length) {
				c = b("<div/>").attr("id", a.maskId);
				b("body").append(c);
			}
			var m = k();
			c.css( {
				position : (c.fixed ? "fixed" : "absolute"),
				top : 0,
				left : 0,
				width : ($.browser.msie ? m[0]-1 : m[0]),
				height : m[1],
				display : "none",
				opacity : a.startOpacity,
				zIndex : a.zIndex
			});
			a.color && c.css("backgroundColor", a.color);
			if (h(a.onBeforeLoad) === false)
				return this;
			a.closeOnEsc && b(document).bind("keydown.mask", function(f) {
				f.keyCode == 27 && b.mask.close(f);
			});
			a.closeOnClick && c.bind("click.mask", function(f) {
				b.mask.close(f);
			});
			b(window).bind("resize.mask", function() {
				b.mask.fit();
			});
			if (d && d.length) {
				j = d.eq(0).css("zIndex");
				b.each(d, function() {
					var f = b(this);
					/relative|absolute|fixed/i.test(f.css("position"))
							|| f.css("position", "relative");
				});
				i = d.css( {
					zIndex : Math.max(a.zIndex + 1, j == "auto" ? 0 : j)
				});
			}
			c.css( {
				display : "block"
			}).fadeTo(a.loadSpeed, a.opacity, function() {
				b.mask.fit();
				h(a.onLoad);
				e = "full";
			});
			e = true;
			return this;
		},
		close : function() {
			if (e) {
				if (h(g.onBeforeClose) === false)
					return this;
				if ($.browser.msie){
					c.hide(g.closeSpeed, function() {
						h(g.onClose);
						i && i.css( {
							zIndex : j
						});
						e = false;
					});
				}
				else
				{
					c.fadeOut(g.closeSpeed, function() {
						h(g.onClose);
						i && i.css( {
							zIndex : j
						});
						e = false;
					});
					
				}
				b(document).unbind("keydown.mask");
				c.unbind("click.mask");
				b(window).unbind("resize.mask");
			}
			return this;
		},
		fit : function() {
			if (e) {
				var a = k();
				c.css( {
					width : a[0],
					height : a[1]
				});
			}
		},
		getMask : function() {
			return c;
		},
		isLoaded : function(a) {
			return a ? e == "full" : e;
		},
		getConf : function() {
			return g;
		},
		getExposed : function() {
			return i;
		}
	};
	b.fn.mask = function(a) {
		b.mask.load(a);
		return this;
	};
	b.fn.expose = function(a) {
		b.mask.load(a, this);
		return this;
	};
})(jQuery);


/// Add Effekt to show the Productbox
$.tools.overlay.addEffect("drop", function(css, done) {

	// use Overlay API to gain access to crucial elements
	var conf = this.getConf();

	// determine initial position for the overlay
	if (conf.fixed)  {
	   css.position = 'fixed';
	} else {

	   css.position = 'absolute';
	}
	// get mouse position right after the click
	mouseX = vars.mouseX;

	//the overlay content
	overlayContext = this.getOverlay();
	// the clicked button
	triggerContext = this.getTrigger();

	// find and store request url for this request and changes in adddirectly.js
	requestUrl = triggerContext.attr("href");
	overlayContext.data('requestUrl', requestUrl);

	// load contents
	overlayContext.find(".jh-c_overlayContentWrapper_addToChart").load(
		requestUrl,
		function(responseText, textStatus, XMLHttpRequest) {
			
			if (textStatus!='error'){
				// position the Layer
				overlayContext.find("#numberOfItems").attr('id','numberOfItemsSmallView');
				
				//responseText = responseText.replace('id="numberOfItems"','id="numberOfItemsSmallView"');
				positionLayer.init(triggerContext,overlayContext,$('#exposeMask'),'exposeMask');
				var posObject = triggerContext;
				var pos = triggerContext.offset();
				var clicked_pos_left = pos.left;
				var Arrow_Style_bottom = document.getElementById('jh-s_pfeil_direct_chart_bottom').style;
				var Arrow_Style_top    = document.getElementById('jh-s_pfeil_direct_chart_top').style;
	
	
				masterLeft = $('#jh-s_master').offset().left;
				pos.left = masterLeft+20;
	
				// wenn der Box unterhalb der Warenkorb button kommt
				if ((pos.top - overlayContext.height())<0){
					pos.top += 20;
					scrollToPos = pos.top-120;
					document.getElementById("jh_s_overlay_body_cartdirect").style.borderTop = '0px';
					Arrow_Style_bottom.display = 'none';
					Arrow_Style_top.display = '';
				}
				else{
					// wenn der Box oberhalb der Warenkorb button kommt
					document.getElementById('jh_s_overlay_body_cartdirect').style.borderTop = '4px solid #D0D7DD';
					$('#jh_mt_s_overlay_top_l_cartdirect').css({'background':'none'});
					pos.top -= overlayContext.height();
					scrollToPos = pos.top-20;
					Arrow_Style_top.display = 'none';
					Arrow_Style_bottom.display = '';
				}
	
				pos.top -= 55;
				// position the arrow
				var newvalueTop = (mouseX - (masterLeft+20+60));
	
				// make sure the arrow never leaves the Box
				if (newvalueTop<30){ newvalueTop = 30;};
				if (newvalueTop>650){ newvalueTop = 650;};
	
				// reposition top and bottom arrow
				Arrow_Style_bottom.marginLeft =  newvalueTop + 'px';
				Arrow_Style_top.marginLeft = newvalueTop + 'px';
				pos.position = 'absolute';
	
				//position the productbox
				overlayContext.css(pos);
	
				// show the product box for we have to position the layer first see effect
				overlayContext.show();
	
				//for the IE cannot deal with transparent PNGs no fading for the IE
				// animate the Produkt box with the nice bump to it
				if ( $.browser.msie ) {
	
					overlayContext.animate({ top: '+=55'}, 400, 'drop',function()
					{
						$('html,body').animate({scrollTop: scrollToPos}, 'fast',function(){
							// start variant scroller
							var variantenScr_Popup = new variantenScrollerContainer('jh-c_product_variant_mainframe_popup');
							variantenScr_Popup.init(true,'addToChart.' + addToChart.ajaxEventName,'jh-c_product_variant_mainframe_popup');
							// prepare and start product box routines
							addToChart.init();
						});
					});
				}
				else
				{
					overlayContext.animate({ top: '+=55',  opacity: 1}, 400, 'drop',function()
					{
						$('html,body').animate({scrollTop: scrollToPos}, 'fast',function(){
							// start variant scroller
							var variantenScr_Popup = new variantenScrollerContainer('jh-c_product_variant_mainframe_popup');
							variantenScr_Popup.init(true,'addToChart.' + addToChart.ajaxEventName,'jh-c_product_variant_mainframe_popup');
							// prepare and start product box routines
							addToChart.init();
	
						});
					});
				}
				done.call();
			}
		}
	);
// position the overlay and show it
/* closing animation */
}, function(done) {
	   if ( !$.browser.msie ) {
	      this.getOverlay().animate({top:'-=55', opacity:0}, 300, 'drop', function() {
	         $(this).hide();
	         done.call();
	      });
	   }
	   else
	   {
		   this.getOverlay().hide();
		   done.call();
	   }
}
);

