/* hoverIntent.js */
(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
	
})(jQuery);
/* hoverIntent.js */


/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);
/* Superfish v1.4.8 - jQuery menu widget */

/* Warenkorb.js */
$(document).ready(function(){ 
	
	$("#basketItemsWrap li:first").hide();
	$("#slidingTopContent").hide();
	
	$("#slidingTopTrigger").live("click", function(event) {
      	$("#slidingTopContent").slideToggle("slow", function(){
			if ($("#slidingTopContent").is(":visible")) {
				$("#slidingTopFooterLeft").html('<img src="images/v2w/arrow-up.png" alt="Warenkorb ausblenden" /> <a href="no-js.htm" onclick="return false;" id="slidingTopTrigger">Warenkorb ausblenden</a>');
			} else {
				$("#slidingTopFooterLeft").html('<img src="images/v2w/arrow-down.png" alt="Warenkorb anzeigen" /> <a href="no-js.htm" onclick="return false;" id="slidingTopTrigger">Warenkorb anzeigen</a>');
			}
		});
    }); 
	

	$(".productPriceWrapRight a img").click(function() {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];

		
		if ($("#slidingTopContent").is(":visible")) {

			$("#notificationsLoader").html('<img src="images/v2w/loader.gif">');
		
			$.ajax({  
			type: "POST",  
			url: "inc/functions.php",  
			data: { productID: productIDVal, action: "addToBasket"},  
			success: function(theResponse) {
				
				if( $("#productID_" + productIDVal).length > 0){
					$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
					$("#productID_" + productIDVal).before(theResponse).remove();
					$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
					$("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
					$("#notificationsLoader").empty();
					
				} else {
					$("#basketItemsWrap li:first").before(theResponse);
					$("#basketItemsWrap li:first").hide();
					$("#basketItemsWrap li:first").show("slow");  
					$("#notificationsLoader").empty();			
				}
				
			}  
			}); 

		} else {
			
			$("#slidingTopContent").slideToggle("slow", function(){		
																 
				$("#slidingTopFooterLeft").html('<img src="images/v2w/arrow-up.png" alt="Warenkorb ausblenden" /> <a href="aaa.htm" onclick="return false;" id="slidingTopTrigger">Warenkorb ausblenden</a>');
				$("#notificationsLoader").html('<img src="images/v2w/loader.gif">');
			
				$.ajax({  
				type: "POST",  
				url: "inc/functions.php",  
				data: { productID: productIDVal, action: "addToBasket"},  
				success: function(theResponse) {
					
					if( $("#productID_" + productIDVal).length > 0){
						$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						$("#productID_" + productIDVal).before(theResponse).remove();
						$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						$("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
						$("#notificationsLoader").empty();
						
					} else {
						$("#basketItemsWrap li:first").before(theResponse);
						$("#basketItemsWrap li:first").hide();
						$("#basketItemsWrap li:first").show("slow");  
						$("#notificationsLoader").empty();			
					}
					
				}  
				}); 
				
				
				$("#slidingTopTrigger").fadeTo(4000, 1, function(){
					$("#slidingTopContent").slideToggle("slow", function(){
						$("#slidingTopFooterLeft").html('<img src="images/v2w/arrow-down.png" alt="Zeige Warenkorb" /> <a href="aaa.htm" onclick="return false;" id="slidingTopTrigger">Zeige Warenkorb</a>');												 
					});
					
				});

			});												 
		}
				
	});
	
	
	
	$("#basketItemsWrap li img").live("click", function(event) { 
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];	
	
		$("#notificationsLoader").html('<img src="images/v2w/loader.gif">');
	
		$.ajax({  
		type: "POST",  
		url: "inc/functions.php",  
		data: { productID: productIDVal, action: "deleteFromBasket"},  
		success: function(theResponse) {
			
			$("#productID_" + productIDVal).hide("slow",  function() {
				$(this).remove();
			});
			$("#notificationsLoader").empty();
		
		}
					
		});  	
		
	});

});
/* Warenkorb.js */

/* FancyZoom.js */
(function($){
	$.fn.fancyZoom = function(options){

	  var options   = options || {};
	  var directory = options && options.directory ? options.directory : 'images';
	  var zooming   = false;

	  if ($('#zoom').length == 0) {
	    var ext = $.browser.msie ? 'gif' : 'png';
	    var html = '<div id="zoom" style="display:none;"> \
	                  <table id="zoom_table" style="border-collapse:collapse; width:100%; height:100%;"> \
	                    <tbody> \
	                      <tr> \
	                        <td class="tl" style="background:url(' + directory + '/tl.' + ext + ') 0 0 no-repeat; width:20px; height:20px; overflow:hidden;" /> \
	                        <td class="tm" style="background:url(' + directory + '/tm.' + ext + ') 0 0 repeat-x; height:20px; overflow:hidden;" /> \
	                        <td class="tr" style="background:url(' + directory + '/tr.' + ext + ') 100% 0 no-repeat; width:20px; height:20px; overflow:hidden;" /> \
	                      </tr> \
	                      <tr> \
	                        <td class="ml" style="background:url(' + directory + '/ml.' + ext + ') 0 0 repeat-y; width:20px; overflow:hidden;" /> \
	                        <td class="mm" style="background:#E6D4ED; vertical-align:top; padding:10px;"> \
	                          <div id="zoom_content"> \
	                          </div> \
	                        </td> \
	                        <td class="mr" style="background:url(' + directory + '/mr.' + ext + ') 100% 0 repeat-y;  width:20px; overflow:hidden;" /> \
	                      </tr> \
	                      <tr> \
	                        <td class="bl" style="background:url(' + directory + '/bl.' + ext + ') 0 100% no-repeat; width:20px; height:20px; overflow:hidden;" /> \
	                        <td class="bm" style="background:url(' + directory + '/bm.' + ext + ') 0 100% repeat-x; height:20px; overflow:hidden;" /> \
	                        <td class="br" style="background:url(' + directory + '/br.' + ext + ') 100% 100% no-repeat; width:20px; height:20px; overflow:hidden;" /> \
	                      </tr> \
	                    </tbody> \
	                  </table> \
	                  <a href="#" title="Close" id="zoom_close" style="position:absolute; top:0; left:0;"> \
	                    <img src="' + directory + '/closebox.' + ext + '" alt="Close" style="border:none; margin:0; padding:0;" /> \
	                  </a> \
	                </div>';

	    $('body').append(html);

	    $('html').click(function(e){if($(e.target).parents('#zoom:visible').length == 0) hide();});
	    $(document).keyup(function(event){
	        if (event.keyCode == 27 && $('#zoom:visible').length > 0) hide();
	    });

	    $('#zoom_close').click(hide);
	  }

	  var zoom          = $('#zoom');
	  var zoom_table    = $('#zoom_table');
	  var zoom_close    = $('#zoom_close');
	  var zoom_content  = $('#zoom_content');
	  var middle_row    = $('td.ml,td.mm,td.mr');

	  this.each(function(i) {
	    $($(this).attr('href')).hide();
	    $(this).click(show);
	  });

	  return this;

	  function show(e) {
	    if (zooming) return false;
			zooming         = true;
			var content_div = $($(this).attr('href'));
	  	var zoom_width  = options.width;
			var zoom_height = options.height;

			var width       = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	  	var height      = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
	  	var x           = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
	  	var y           = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
	  	var window_size = {'width':width, 'height':height, 'x':x, 'y':y}

			var width              = (zoom_width || content_div.width()) + 60;
			var height             = (zoom_height || content_div.height()) + 60;
			var d                  = window_size;

			// ensure that newTop is at least 0 so it doesn't hide close button
			var newTop             = Math.max((d.height/2) - (height/2) + y, 0);
			var newLeft            = (d.width/2) - (width/2);
			var curTop             = e.pageY;
			var curLeft            = e.pageX;

			zoom_close.attr('curTop', curTop);
			zoom_close.attr('curLeft', curLeft);
			zoom_close.attr('scaleImg', options.scaleImg ? 'true' : 'false');

	    $('#zoom').hide().css({
				position	: 'absolute',
				top				: curTop + 'px',
				left			: curLeft + 'px',
				width     : '1px',
				height    : '1px'
			});

	    fixBackgroundsForIE();
	    zoom_close.hide();

	    if (options.closeOnClick) {
	      $('#zoom').click(hide);
	    }

			if (options.scaleImg) {
	  		zoom_content.html(content_div.html());
	  		$('#zoom_content img').css('width', '100%');
			} else {
			  zoom_content.html('');
			}

	    $('#zoom').animate({
	      top     : newTop + 'px',
	      left    : newLeft + 'px',
	      opacity : "show",
	      width   : width,
	      height  : height
	    }, 500, null, function() {
	      if (options.scaleImg != true) {
	    		zoom_content.html(content_div.html());
	  		}
				unfixBackgroundsForIE();
				zoom_close.show();
				zooming = false;
	    })
	    return false;
	  }

	  function hide() {
	    if (zooming) return false;
			zooming         = true;
		  $('#zoom').unbind('click');
			fixBackgroundsForIE();
			if (zoom_close.attr('scaleImg') != 'true') {
	  		zoom_content.html('');
			}
			zoom_close.hide();
			$('#zoom').animate({
	      top     : zoom_close.attr('curTop') + 'px',
	      left    : zoom_close.attr('curLeft') + 'px',
	      opacity : "hide",
	      width   : '1px',
	      height  : '1px'
	    }, 500, null, function() {
	      if (zoom_close.attr('scaleImg') == 'true') {
	    		zoom_content.html('');
	  		}
	      unfixBackgroundsForIE();
				zooming = false;
	    });
	    return false;
	  }

	  function switchBackgroundImagesTo(to) {
	    $('#zoom_table td').each(function(i) {
	      var bg = $(this).css('background-image').replace(/\.(png|gif|none)\"\)$/, '.' + to + '")');
	      $(this).css('background-image', bg);
	    });
	    var close_img = zoom_close.children('img');
	    var new_img = close_img.attr('src').replace(/\.(png|gif|none)$/, '.' + to);
	    close_img.attr('src', new_img);
	  }

	  function fixBackgroundsForIE() {
	    if ($.browser.msie && parseFloat($.browser.version) >= 7) {
	      switchBackgroundImagesTo('gif');
	    }
		}

	  function unfixBackgroundsForIE() {
	    if ($.browser.msie && $.browser.version >= 7) {
	      switchBackgroundImagesTo('png');
	    }
		}
	}
	})(jQuery);
/* FancyZoom.js */

// initialise plugins
jQuery(function(){
	jQuery('ul.sf-menu').superfish();
});

$(function() {
    // Versandkosten etc. einblenden
	$('#medium').fancyZoom({width:600, height:250, closeOnClick: true});
	$('#medium2').fancyZoom({width:600, height:250, closeOnClick: true});

	// Tabs
	$('#tabs').tabs();
	$('#tabs2').tabs();
	$('#tabs3').tabs();
	$('#tabs4').tabs();
	$('#tabs5').tabs();
	$('#tabs6').tabs();
});
