/*--------------------------------------------------------------
 *	project: Vorwerk, 2010
 *	created: 2010-02-22
 *	last changed: 2010-05-05
 *	author: Patricia Ross, triplesense
 --------------------------------------------------------------- */

// WICHTIG: jQuery statt jQuery verwenden (wegen Magento)

// global for interval calls; store interval ids
var _animateOnMap = []

function initEnhancements(){
	// activate functions
	jQuery.fn.css3workarounds();
	jQuery.fn.tooltipTitle();
	jQuery.fn.zebraTable();
	jQuery.fn.faqToggle();
	jQuery.fn.toggleDetails();
	jQuery.fn.lightbox();
	jQuery.fn.animateImages();
	jQuery.fn.initTabs();
	jQuery.fn.imagegallery({autostart:true});
	jQuery.fn.animateOnMap();
	jQuery.fn.disableSubmit();

	// activate equal height for teaser with separator
	jQuery('.home .teaser.image-text.thumb-left.no-bg').equalHeight();
	jQuery('.overview .teaser.image-text.thumb-left.no-bg').equalHeight();
	jQuery('.detailpage-subnav .teaser.image-text.thumb-left.no-bg').equalHeight();
	jQuery('.detailpage-tabnav .teaser.image-text.thumb-left.no-bg').equalHeight();
	jQuery('.col-50 .teaser.text-only.no-bg').equalHeight();
	jQuery('.col-33 .teaser.text-only.no-bg').equalHeight();
	jQuery('.col-25 .teaser.text-only.no-bg').equalHeight();	
}

jQuery(document).ready(function() {	
	initEnhancements()
});

/* -------------------------------------------------------------
 *	Disable input button after form submit
 * ------------------------------------------------------------- */
jQuery.fn.disableSubmit = function() {
	$("form").submit(function() {
		var myform = $(this);
		if (myform.attr("submittstate") == "1")
			return false;
		myform.attr("submittstate", "1");
	})
}

/* -------------------------------------------------------------
 *	Helper functions for the animations
 * ------------------------------------------------------------- */
 
/* only for ten-oclock animation and AIO */
function showLabel() {
  var thispin = this
   
  // special for 10 OC
  if(jQuery('.ten-oclock').length != 0){
    //console.log('## 10 OC');
    jQuery(thispin).css({'zIndex': '120'});
     jQuery(this).find('.btn-arrow').stop();
  }
  

  var pinID = jQuery(this).attr('id');
  //console.log(pinID + ' showing label');
  
  jQuery(this).find('.btn-arrow').stopPulse();
  // provide widt in span.pin-width
  var tW = jQuery(this).find('.pin-width').text();
  // if not providet calc width
  if(!tW) {tW = jQuery(this).width();}

  //jQuery(this).find('.btn-label').stop();
  //jQuery(".content .pin .info-box").stop();
  //jQuery('.all-in-one .btn-arrow').data('pulseForbidden',false);
  
  // ckeck if in zoom in 10 OC
  if(!jQuery(thispin).hasClass('zoomed-in')){

    jQuery(this).find('.btn-label').stop().animate({'width': tW}, 400, function () {

        //console.log(pinID + ' is open');
        jQuery(thispin).css({'zIndex': '120'});
        jQuery(thispin).addClass('label-visible');
        
        
        jQuery('.info-box').stop(true,true);
        //jQuery(thispin).removeClass('is-running');
    });
  
  }

}

/* only for ten-oclock animation */
function hideLabel(options) {
  //jQuery('.all-in-one .btn-arrow').stop().data('pulseForbidden',true);
  var thispin = this;
  var tID = jQuery(thispin).attr('id');
  //jQuery(thispin).addClass('is-running');
//	if (jQuery(this).hasClass("hover")) {
	//console.log('hiding labels')
  

  
  // special for 10 OC
  if(jQuery('.ten-oclock').length != 0){
    jQuery(this).find('.btn-arrow').pulse();   
  } else if(options && options.pulse){
    jQuery(this).find('.btn-arrow').pulse();	    	
  }

  //console.log(tID + ' hiding labels');
  
  //jQuery(this).find('.btn-label').stop();
  //jQuery(".content .pin .info-box").stop();
  // was 300
 

  
  jQuery(this).find('.btn-label').stop().animate({'width': '0'}, 450, function() {

    jQuery(thispin).css({'zIndex': '113'});
    jQuery(thispin).removeClass('label-visible');
    jQuery(thispin).find('.btn-arrow').css({'zIndex': '112'});
    //console.log(tID + ' is closed');
    //jQuery(thispin).removeClass('is-running');
    
    // check if it is current:
    // no hiding
    
    if(jQuery('.ten-oclock').length == 0){
      if(jQuery(thispin).hasClass('last-pin')) {
        //console.log('last pin found');
        // open infobox now
        jQuery('.content .pin .info-box').stop().slideDown(450);
        jQuery('.pin.active').find(".btn-arrow").attr("src","fileadmin/templates/global/images/global/icons/img_pfeil_runter.png");
        jQuery('.pin.active').css({'zIndex': '115'});
        jQuery('.pin.active').find('.btn-arrow').css({'zIndex': '116'});
        jQuery('.content .pin .info-box').css({'zIndex': '114'});
        
      }
    }
    
    
    
    
  });
//	}
} 



function resetAll() {

  //console.log('******RESET ALL ******');
  jQuery('.content .pin .info-box').stop(true,true);
  jQuery('.btn-arrow').attr('src','fileadmin/templates/global/images/global/icons/img_pfeil_rechts_big.png');
  jQuery('.pin').css({'zIndex': '70'});
  jQuery('.btn-arrow').css({'zIndex': '71'});
  //jQuery('.content .pin').removeClass('active');
  //console.log('******RESET DONE ******');
  return true;
   
}
 
function showBox(thispin) {
  //console.log('showBox');
  var resetDone = resetAll();

  jQuery('.btn-label').stop(true,true);
  
  if (jQuery(thispin).parents().find(".ten-oclock").length ==  0) {
		var thispin = this;
	}
	
  var tID = jQuery(this).attr('id');
	//console.log(tID + ' --------------------- in show box');
	
	
  
  jQuery(this).addClass('active');
  
	
	/* fill box with content */ 
	jQuery('.content .all-in-one .info-box h3, .content .ten-oclock .info-box h3').text(jQuery(thispin).find('.headline').text());
	jQuery('.content .all-in-one .info-box img, .content .ten-oclock .info-box img').attr('src',jQuery(thispin).find('img.box-thumb').attr('src'));
	jQuery('.content .all-in-one .info-box p.detail-text, .content .ten-oclock .info-box p.detail-text').text(jQuery(thispin).find('.text').text());
	jQuery('.content .all-in-one .info-box p.more a, .content .ten-oclock .info-box p.more a').attr('href',jQuery(thispin).find('.link').text());
	
	jQuery(thispin).append(jQuery('.content .all-in-one .info-box, .content .ten-oclock .info-box'));
	
  
	jQuery(thispin).find('.btn-arrow').data('pulseForbidden',true);
	jQuery('.content .all-in-one .pin').each(function(i,el){
		//hideLabel.apply($(el), [{pulse:false}]);
    hideLabel.apply($(el));
    
	});
	
  
  var counter = 1;
  var intIncrement = 200;
  jQuery('.content .all-in-one .pin .btn-arrow').each( function(i,el) {

    if(!jQuery(this).parent().hasClass('active')) {
      jQuery(this).data('pulseForbidden',false);
      var tempTimer = counter*intIncrement;
      setTimeout( function() {
			
        jQuery(el).pulse();
        }, tempTimer);
      
      //jQuery(this).pulse();
      counter++;

    } 
  });
  
  
  
  
  
}

function hideBox() {
  //console.log('hideBox');
  jQuery('.pin .btn-label').stop(true,true);
  //jQuery('.pin.active').find('.btn-label').stop();
  jQuery('.content .all-in-one').find('.info-box').stop(true,true);
	
	var thispin = this;
  var tID = jQuery(this).attr('id');
	 
  jQuery(thispin).find('.btn-arrow').data('pulseForbidden',false);
  
  
  // revert open state
  jQuery(".content .pin .info-box").stop().slideUp(450,function() {
		
    jQuery(this).parent().find('.btn-arrow').attr('src','fileadmin/templates/global/images/global/icons/img_pfeil_rechts_big.png');
                                                         
    jQuery(".content .all-in-one .pin").each(function(i,el) {
			showLabel.apply($(el))
		//	jQuery(this).show().stop().animate({"width": jQuery(this).parent().width()},300);
		});
		/* reset z-index */
		jQuery(thispin).css({'zIndex': '70'})
		jQuery(thispin).find('.btn-arrow').css({'zIndex': '71'});
    jQuery(thispin).removeClass('active');
		//jQuery(thispin).remove(jQuery(thispin).find("info-box"));
	}); 
  
  
  

}



function showBox10OC(thispin){
  //console.log('fired: showBox10OC');
  if (jQuery(thispin).parents().find(".ten-oclock").length ==  0) {
		var thispin = this;
	}
	
  var tID = jQuery(thispin).attr('id');	
  jQuery(this).addClass('active');
  
	/* fill box with content */ 
	jQuery('.content .ten-oclock .info-box h3').text(jQuery(thispin).find('.headline').text());
	jQuery('.content .ten-oclock .info-box img').attr('src',jQuery(thispin).find('img.box-thumb').attr('src'));
	jQuery('.content .ten-oclock .info-box p.detail-text').text(jQuery(thispin).find('.text').text());
	//jQuery('.content .ten-oclock .info-box p.more a').attr('href',jQuery(thispin).find('.link').text());
  
  // spc german bx in 10 OC
  if(tID == 'p6' && jQuery('.ten-oclock').length !=  0 ) {
    jQuery('.content .ten-oclock .info-box img.i2').attr('src',jQuery(thispin).find('img.box-thumb2').attr('src'));
    jQuery('.content .ten-oclock .info-box p.detail-text2').text(jQuery(thispin).find('.text2').text());
 
  } else {

    jQuery('.content .ten-oclock .info-box img.i2').attr('src','');
    jQuery('.content .ten-oclock .info-box p.detail-text2').text('');
  }
  
  
  jQuery('.content .ten-oclock > .info-box').clone().appendTo(thispin);
  
  setHandler();
  
  
	jQuery(thispin).find('.btn-arrow').data('pulseForbidden',true);
  jQuery(".content .pin.zoomed-in .info-box").stop().slideDown(300);

}

function hideBox10OC(thispin){
  //console.log('hideBox10OC');
  //alert('hide box');
  jQuery('.pin .btn-label').stop(true,true);
  //jQuery('.content').find('.info-box').stop(true,true);
	
	var thispin = this;
  var tID = jQuery(this).attr('id');
	 
  jQuery(thispin).find('.btn-arrow').data('pulseForbidden',false);
  
  // revert open state
    jQuery('.zoomed-in .info-box').stop().slideUp(350,function() {
    jQuery('.zoomed-in .info-box').remove();
    zoomOutMap(this);
  }); 

}


function zoomInMap(pin) {

  jQuery(pin).find('.btn-arrow').data('pulseForbidden',true);
  
	jQuery('.content .ten-oclock .pin').hide();
  jQuery('.zoomed-in').find('.btn-arrow').attr('src','fileadmin/templates/global/images/global/icons/img_pfeil_runter.png');
	jQuery('.content .ten-oclock .pin .btn-label').stop().css({'width': '0px'});

  
  jQuery('.btn-arrow').stopPulse();
  jQuery(pin).find('img.country').clone().appendTo('.content .ten-oclock');
  

	
	jQuery('.content .ten-oclock .countries').animate({'width': '130%', 'height': '130%', 'left': '-70px'}, 500, function() {
		jQuery('.content .ten-oclock .countries').fadeOut(500);	
		jQuery('.content .ten-oclock > .country').fadeIn(200);
    //jQuery('.content .ten-oclock .info-box').stop(true,true);
    
    var zoomedTop = jQuery(pin).find('.c-top-zoomed').text() + 'px';
    var zoomedLeft = jQuery(pin).find('.c-left-zoomed').text() + 'px';

    jQuery(pin).css({'top':zoomedTop , 'left':zoomedLeft});
		jQuery(pin).show();
    jQuery('.content .ten-oclock .backlink').show(); 
    showBox10OC(pin);

	});

}

function zoomOutMap(pin) {
  
  jQuery('.content .ten-oclock .pin').hide();
  jQuery('.zoomed-in').find('.btn-arrow').attr('src','fileadmin/templates/global/images/global/icons/img_pfeil_rechts_big.png');
  
  var posTop = jQuery('.zoomed-in').find('.c-top').text() + 'px';
  var posLeft = jQuery('.zoomed-in').find('.c-left').text() + 'px';
  jQuery('.zoomed-in.pin').css({'top':posTop , 'left':posLeft});
  jQuery('.content .ten-oclock .backlink').hide(); 
 
  // country
  jQuery('.content .ten-oclock > .country').fadeOut(500);
  jQuery('.content .ten-oclock .countries').fadeIn(400, function() {
    
    jQuery('.content .ten-oclock .countries').animate({'width': '100%', 'height': '100%', 'left': '0px'}, 600, function() {

      jQuery('.zoomed-in').removeClass('zoomed-in');
      jQuery('.content .ten-oclock > .country').remove();
      
      jQuery('.content .ten-oclock .pin').show();
      jQuery('.btn-arrow').data('pulseForbidden',false);
      jQuery('.content .ten-oclock .pin .btn-arrow').pulse();
      
    
    });	
      
  
  });
  
}


/* -------------------------------------------------------------
 *	All-In-One and ten o'clock Animation
 * ------------------------------------------------------------- */
jQuery.fn.animateOnMap = function() {
	

	var hoverConfigAIO = {
    interval : 80,
		timeout : 0,
		over : showBox,
		out: hideBox
	}
	
	var hoverConfigTO = {
    interval : 80,
		timeout : 0,
		over : showLabel,
		out: hideLabel
	}
  
  
  /* register events */
	jQuery('.content .all-in-one .pin .btn-label, .content .ten-oclock .pin .btn-label').css({'width': 0});
  jQuery('.content .all-in-one .pin').hoverIntent(hoverConfigAIO);
  jQuery('.content .ten-oclock .pin').hoverIntent(hoverConfigTO);
	
	/* append arrow image in js to avoid duplicate content in html */
	jQuery('.content .all-in-one .pin, .content .ten-oclock .pin').each(function() {
		jQuery(this).append("<img class='btn-arrow' alt='Arrow' title='' src='fileadmin/templates/global/images/global/icons/img_pfeil_rechts_big.png' width='35' height='35' />");
	});
	
  
  // all in one
	jQuery('.content .all-in-one .info-box .close').click(function() {
    var clicked = jQuery(this).parent().parent().attr('id');
    // slide up
    hideBox(clicked);

	})
  
  // 10 OC
	jQuery('.content .ten-oclock .info-box .close').click(function() {
    //console.log('--> ' + clicked);
    // slide up
    hideBox10OC();
		//zoomOutMap();

	})
  
  jQuery('.content .ten-oclock .backlink a').click(function(event) {
    //console.log('--> ' + clicked);
    // slide up
    event.preventDefault();
    hideBox10OC();
		//zoomOutMap();

	})

  
  
  

	
  // puls btns
	jQuery('.content .all-in-one .pin .btn-arrow').pulse();
	jQuery('.content .ten-oclock .pin .btn-arrow').pulse();
	
	jQuery('.content .ten-oclock .pin').click(function() {
    
    if (!jQuery(this).hasClass('zoomed-in')) {
      jQuery(this).addClass('zoomed-in');
			zoomInMap(this);

		}
    
    
	})
  
  
  jQuery('.content .all-in-one .pin').each(function(i,el){
		setTimeout( function() {
			showLabel.apply($(el))
		}, (i*500)+400);
	})
  

}


function setHandler(){


jQuery('.content .ten-oclock .pin .info-box .close').click(function() {

    //console.log('--> ' + clicked);
    hideBox10OC();
		//zoomOutMap();

	})

}

/* -------------------------------------------------------------
 *	Styling
 * ------------------------------------------------------------- */
// CSS3 Workarounds for IE
jQuery.fn.css3workarounds = function() {
	jQuery('.breadcrumb li:nth-child(2)').addClass('first-link');
	jQuery('h2:first-child').addClass('first');
};

// Zebra-Tables
jQuery.fn.zebraTable = function() {
	jQuery('table').each( function() {
		if (jQuery(this).attr('class') !== 'no_zebra' ) jQuery(this).find('tbody tr:even').addClass('row-even');
	} );
};

// Equal Height
jQuery.fn.equalHeight = function () {
	var height		= 0;
	var maxHeight	= 0;

	// Store the tallest element's height
	this.each(function () {
		height		= jQuery(this).outerHeight();
		maxHeight	= (height > maxHeight) ? height : maxHeight;
	});

	// Set element's min-height to tallest element's height
	return this.each(function () {
		var t			= jQuery(this);
		var minHeight	= maxHeight - (t.outerHeight() - t.height());
		var property	= jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

		t.css(property, minHeight + 'px');
	});

};


/* -------------------------------------------------------------
 *	Tooltip 
 * ------------------------------------------------------------- */
jQuery.fn.tooltipTitle = function() {

	jQuery(".tooltip-title[title]").tooltip({
		effect: 'fade',
		position: "top center",
		offset: [-5, 0]
	});

};


/* -------------------------------------------------------------
 *	Lightboxes/Overlay
 * ------------------------------------------------------------- */
jQuery.fn.lightbox = function() {

	// default Lightbox/Overlay
	jQuery("a[rel]").overlay({
		mask: '#595552', 
		top: 124,
		preload: false,
		fixed: false,
		//for external sites
		onBeforeLoad: function() { 
		 // grab wrapper element inside content 
		 var wrap = this.getOverlay().find(".external-content"); 		 
		 // load the page specified in the trigger 
		 wrap.load(this.getTrigger().attr("href")); 
		 }
	});

};

/* -------------------------------------------------------------
 *	FAQ-Accordion
 * ------------------------------------------------------------- */
jQuery.fn.faqToggle = function() {
	// handle by TYPO3 specialelemnt / udo 05.05.2010
	//jQuery('.faq dt').addClass('inactive');
	//jQuery('.faq dd').hide();
	
	// FAQ-Accordion
	jQuery('.faq dt a').click( function(e) {
		var parent = jQuery(e.target).parent();
		parent.toggleClass('inactive');
        parent.next().toggle();
		return false;
    } );
};


/* -------------------------------------------------------------
 *	General Form-Accordion
 * ------------------------------------------------------------- */
jQuery.fn.toggleDetails = function() {
	if (jQuery(".form-optional").find("div.error").length > 0) {
		$(this).show();
		$(".form-details").toggleClass('inactive');
	} else jQuery(".form-details").next().hide();
	jQuery(".form-details").click(function(e) {
		e.preventDefault();
		$(this).toggleClass('inactive');
		$(this).next().toggle();
	})
}


/* -------------------------------------------------------------
 *	Image Gallery
 * ------------------------------------------------------------- */
jQuery.fn.imagegallery = function(options) {
	if(typeof window.imagegalleries == 'undefined'){
		window.imagegalleries = [];		
	}
	jQuery('.image-gallery').each(function(i,gallery){
		if(!jQuery(gallery).is('.initated')){
			
			// Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			jQuery(gallery).addClass('initated')
			jQuery(gallery).addClass('gallery-'+ i)
			jQuery(gallery).attr('rel', window.imagegalleries.length)
			var newgallery = {gallery: null, markup: jQuery(gallery)}
			window.imagegalleries.push(newgallery)
			
			jQuery(gallery).find('.gallery-content').css('display', 'block');
			var onMouseOutOpacity = 0.6;
			jQuery(gallery).find('.navigation ul.thumbs li').opacityrollover({
				mouseOutOpacity:   onMouseOutOpacity,
				mouseOverOpacity:  1.0,
				fadeSpeed:         'fast',
				exemptionSelector: '.selected'
			});
			
			// Initialize Advanced Galleriffic Gallery
			newgallery.gallery = jQuery(gallery).find('.navigation').galleriffic({
				delay:                     4000,
				numThumbs:                 8,
				preloadAhead:              0,
				enableTopPager:            false,
				enableBottomPager:         true,
				maxPagesToShow:            6,
				imageContainerSel:         '.gallery-'+ i +' .slideshow',
				controlsContainerSel:      '.gallery-'+ i +' .controls',
				captionContainerSel:       '.gallery-'+ i +' .caption-container',
				loadingContainerSel:       '.gallery-'+ i +' .loader',
				renderSSControls:          false, // play/pause
				renderNavControls:         false, // prev/next photo
				playLinkText:              'Play Slideshow',
				pauseLinkText:             'Pause Slideshow',
				prevLinkText:              '&lsaquo;',
				nextLinkText:              '&rsaquo;',
				nextPageLinkText:          '&rsaquo;&rsaquo;',
				prevPageLinkText:          '&lsaquo;&lsaquo;',
				enableHistory:             false,
				enableKeyboardNavigation:  false, // Specifies whether keyboard navigation is enabled
				autoStart:                 options.autostart,
				syncTransitions:           false,
				defaultTransitionDuration: 800,
				onSlideChange:             function(prevIndex, nextIndex) {
					// 'this' refers to the gallery, which is an extension of jQuery('#gallery-thumbs')
					this.find('ul.thumbs').children()
						.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
						.eq(nextIndex).fadeTo('fast', 1.0);
				},
				onPageTransitionOut:       function(callback) {
					this.fadeTo('fast', 0.0, callback);
				},
				onPageTransitionIn:        function() {
					this.fadeTo('fast', 1.0);
				}
			});
		}
	})
	
};


/* -------------------------------------------------------------
 *	Horizontal Slider (FAQ)
 * ------------------------------------------------------------- */
// Horizontal Slider that shows dynamic FAQ content below the slider on Click 
jQuery.fn.horizontalslider = function() {

	// Alle vorhandenen Scroller sonderbehandeln
	handlescrollerhorizontal("#faqslider");
	
	
	/* -------------------------- FAQ -------------------------- */
	// get "product-*"-classname of one item and show corresponding div 
	showQuestions = function(selector) {
		var faqid = "."+jQuery(selector).attr("class").match(/product-\w*/)[0];
		if (jQuery(faqid).length>0) {
			jQuery(".faq-questions").hide();
			jQuery(faqid).fadeIn();
		}
		return false;		
	};
	// show faq questions of initially activated item (pageload)
	showQuestions(jQuery(".horizontal-slider .active"));
	
	
	// show content of a clicked item
	jQuery(".horizontal-slider .item").click(function() {
        jQuery('.horizontal-slider .item').removeClass("active");
        jQuery(this).addClass("active");
		showQuestions(this);
	});
};



// Alle Scroller so umblättern, das sie den aktuell aktivierten (geklickten) Wert anzeigen 
function handlescrollerhorizontal(scroller_select) {
	
	jQuery(scroller_select).scrollable({
		keyboard: false,
		circular: false
	});
	
	if(myscrollerhorizontal = jQuery(scroller_select).data("scrollable")) {
		var pagenum=0;
		jQuery('.horizontal-slider .page').each(function(c1, pagediv) {
			jQuery.each(pagediv.children, function(c2, itemdiv) {
				var found = itemdiv.className.search(/active/);
				if(found != -1) {
					pagenum=c1;
				}  	  
			});
		});
		myscrollerhorizontal.move(pagenum, 0);
	}
  
};

/* -------------------------------------------------------------
 * Generic Horizontal Slider with dynamic Content
 * -------------------------------------------------------------
 * @param {String} slider_id	CSS ID of the slider div
 * @param (String) item_class	CSS classname of each slider item
 * @param (String) items_div	CSS classname pattern to match with item detail div
 * @param (String) items_div	CSS classname of each slider item detail div
 * @param (String) customfunc	(optional) custom function to be applied after each slider switch
 */
// Generic Horizontal Slider that shows dynamic content below the slider on Click
jQuery.fn.horizontalslider_dynamiccontent = function(slider_id, item_class, items_div, customfunc) {
	
	// Alle vorhandenen Scroller sonderbehandeln
	handlescrollerhorizontal(slider_id);
	
	var sliderobj = jQuery(slider_id);

	/* -------------------------- Items -------------------------- */
	// get classname of one item and show corresponding items div 
	showItems = function(selector) {

		var item_class_regex = new RegExp(item_class+'\\w*');
		var item_id = "."+jQuery(selector).attr("class").match(item_class_regex)[0];

		/* store active item class via data() */
		sliderobj.data('active_class',item_id);
		
		if (jQuery(item_id).length>0) {
			/* After hiding the items div... */
			jQuery(items_div).hide();
			/* Apply custom function */
			if (jQuery.isFunction(customfunc)) { customfunc(); }
			/* And show it */
			jQuery(item_id).fadeIn();
		}
		return false;
	};

	// show item-content of initially activated item (pageload)
	showItems(jQuery(".horizontal-slider .active"), item_class, items_div);
	// show item-content of a clicked item
	jQuery(".horizontal-slider .item").click(function() {
        jQuery('.horizontal-slider .item').removeClass("active");
        jQuery(this).addClass("active");
		showItems(this);
	});
	
};


/* -------------------------------------------------------------
 *	Vorwerk Worldwide: Functions to handle brands and countries
 * ------------------------------------------------------------- */
jQuery.fn.handleBrandCountries = function() {
	

	/* Shows/hides a country group (consisting of countries) depending on the number of visible country items */
	function toggleCountryGroup(display,activeclass) {
		jQuery('.countries'+activeclass).each(function() {
			jQuery(this).find('.country-group').each(function() {
				var $countrygroup = $(this);
				var count_visible_items	= $countrygroup.find('li:visible').length;
				/* console.log(count_visible_items); */
				if (display == 'hide') {
					/* console.log($countrygroup); */
					if (count_visible_items == 0) {
						$countrygroup.slideUp();
					}
				} else {
					$countrygroup.slideDown();
				}
			});
		});
	}
	
	/* Shows/hides address items within all lightboxes based on filter (company|distributor) */
	function toggleLightboxAdresses(display,itemclass) {
		var address_item = jQuery('.worldwide .lightbox .address.'+itemclass);
		if (display == 'hide') {
			address_item.hide();
		} else {
			address_item.show();
		}
	}
	
	jQuery('.filter input:checkbox').click(function() {
		var $this = jQuery(this);
		var radio_checked = $this.is(':checked');

		/* prevent unchecking both checkboxes */
		if (jQuery('.filter input:checkbox').not(':checked').length == 2) { return false; }

		var activeclass = jQuery('#brandslider').data('active_class'); /* .brand-1 etc. */

		/* console.log(jQuery('.countries'+activeclass+' .country-group ul li.'+$this.attr('class'))); */
		
		items = jQuery('.countries'+activeclass+' .country-group ul li').filter(function(index) {
			/* only grab items that contain 1 class-value (company|distributor)  */
			/* console.log('classname='+this.className); */
			var regex = new RegExp($this.attr('class'));
			if (this.className.match($this.attr('class'))) {
				/* console.log(this.className.match(regex)); */
				if (this.className.split(" ").length == 1) {
					return true;
				}
			} else { return false; }
		});
		
		/* console.log(items); */
		
		if (items.length>0) {
			if (radio_checked) {
				items.fadeIn(function() {
					toggleCountryGroup('show',activeclass);
					toggleLightboxAdresses('show',$this.attr('class'));
				});
			} else {
				items.fadeOut(function() {
					toggleCountryGroup('hide',activeclass);
					toggleLightboxAdresses('hide',$this.attr('class'));
				});
			}
		}
	});

}



/* -------------------------------------------------------------
 *	Vertical Slider
 * ------------------------------------------------------------- */
jQuery.fn.verticalslider = function() {

	// Alle vorhandenen Scroller sonderbehandeln
	handlescrollervertical("#tabnavslider");
	
	// link to href of h4
	jQuery('.vertical-slider .item').click(function() {
        jQuery('.vertical-slider .item').removeClass("active");
        jQuery(this).addClass("active");
		location.href = jQuery('h4 a',this).attr("href");
		return false;
	});

};

// Alle Scroller so umblättern, das sie den aktuell aktivierten (geklickten) Wert anzeigen 
function handlescrollervertical(scrollervertical_select) {
	
	jQuery(scrollervertical_select).scrollable({
		keyboard: false,
		vertical: true,
		circular: false
	});
	
	if(myscrollervertical = jQuery(scrollervertical_select).data("scrollable")) {
		var pagenum=0;
		jQuery('.vertical-slider .page').each(function(c1, pagediv) {
			jQuery.each(pagediv.children, function(c2, itemdiv) {
			var found = itemdiv.className.search(/active/);
				if(found != -1) {
					pagenum=c1;
				}  	  
			});
		});
		myscrollervertical.move(pagenum, 0);
	}
  
};


/* -------------------------------------------------------------
 *	Scrollable Content
 * ------------------------------------------------------------- */
// Horizontal Slider that does not show any content below the Slider on Click
jQuery.fn.horizontalslider_noextracontent = function() {

	jQuery(".horizontal-content-slider").scrollable({
		keyboard: false,
		circular: false
	});

};


/* -------------------------------------------------------------
 *	Javascript IMG
 * ------------------------------------------------------------- */
var error="Das Copyright diese Bildes liegt bei Vorwerk. Bitte lesen Sie unseren Copyright-Hinweis im Impressum."
function disableclick(e) {
if (document.all) {
  if (event.button==2||event.button==3) {
      if (event.srcElement.tagName=="IMG"){
      alert(error);
      return false;
      }
  }
}
else if (document.layers) {
    if (e.which == 3) {
    alert(clickmessage);
    return false;
    }
}
else if (document.getElementById){
    if (e.which==3&&e.target.tagName=="IMG"){
    alert(error)
    return false
    }
  }
}


function disqualify(){
  for(i=0;i<document.images.length;i++){
    document.images[i].onmousedown=disableclick;
  }
}


if (document.all){
document.onmousedown=disableclick
}
else if (document.getElementById){
document.onmouseup=disableclick
}
else if (document.layers){
  //disqualify()
}

/* Image animation */
function loopThroughImages(options){
	var imagecontainer = options.container;

	if(!imagecontainer.is('.animating')){	
		imagecontainer.addClass('animating')
		imagecontainer.attr('rel', options.count)
		
		var firstimage = imagecontainer.find('img')[0]
		var speed = 900/imagecontainer.find('img').length;
		function showPreviousImg(currImg){
			$(currImg).fadeIn(0).delay(speed).fadeOut(0,function(){
				if($(currImg).prev('img').length>0){			
					showPreviousImg($(currImg).prev('img'))
				}else{
					imagecontainer.attr('rel', parseInt(imagecontainer.attr('rel'))-1)
					if(imagecontainer.is('.mouseover') && parseInt(imagecontainer.attr('rel'))==0){
						imagecontainer.attr('rel', 1)
					} 
					if(parseInt(imagecontainer.attr('rel'))==0){
						$(currImg).fadeIn(0)
						imagecontainer.removeClass('animating')	
					}else{
						showNextImg($(currImg).next('img'))
					}
				}
		   })
		}
		
		function showNextImg(currImg){
			$(currImg).fadeIn(0).delay(speed).fadeOut(0,function(){
				if($(currImg).next('img').length>0){			
					showNextImg($(currImg).next('img'))
				}else{
					showPreviousImg($(currImg).prev('img'))
				}
		   })					
		}
		showNextImg(firstimage)
	}
}

jQuery.fn.animateImages = function() {
	$('.images.animated').each(function(i,presentation){
											 
			var p = $(presentation)
			var pimgs = $(presentation).find('img');
			var loopindex = 0;
			var iteration = 0;
			var maxiterations =20;
			var initialanimation = true;
			var initialanimations = 3;
			var initialanimationCount = 0;
			
			if(!p.is('.initiated')){
				p.addClass('initiated')
				loopThroughImages({
					container: p,
					count: 3
				})
			}
			p.mouseenter(function(){
				p.addClass('mouseover')
				loopThroughImages({
					container: p,
					count: 1
				})
			})
			p.mouseleave(function(){
				p.removeClass('mouseover')
			})
		})
}


/* tab dynamic enhancements */
jQuery.fn.initTabs = function() {
/*
	var curcontent= $('.content .inner-content').html();
	$('.content .inner-content').append(jQuery('<div class="stacked-content" rel="mega-tabs"><div class="stack ready initial active">'+  curcontent +'</div>'))
	$('.stacked-content').find('.initial').find('.product-presentation .images').removeClass('initiated').removeClass('animating')
	$('.stacked-content').find('.mega-tabs').remove()
	jQuery.fn.animateImages();
	jQuery.fn.imagegallery({autostart:true});
	$('.content .inner-content').children().each(function(i,el){
		if(!$(el).is('.stacked-content')){
			if($(el).find('.mega-tabs').length==0){
				$(el).remove()
			}
		}
	})

	jQuery('.mega-tabs a').each(function(i, tab){
		jQuery(tab).attr('rel',i)
		jQuery(tab).attr('rel',i)
		if(jQuery(tab).parents('li').is('.active')){
			jQuery(tab).addClass('initial')
			jQuery('.stacked-content').find('.initial').attr('rel',i)
		}else{
			jQuery('.stacked-content').append(jQuery('<div class="stack" rel="'+ i +'"></div>'))	
		}
		
		jQuery(tab).click(function(event){
								   
			event.preventDefault();
			var curtab = jQuery(this)
			jQuery('.mega-tabs li').removeClass('active')
			curtab.parents('li').addClass('active')
			
			var stacks = jQuery('.stacked-content');										  
			var stackcontainer = stacks.find('.stack[rel='+ curtab.attr('rel') +']');
			if(!stackcontainer.is('.ready')){
				stackcontainer.addClass('loading');
				jQuery.get(curtab.attr('href'), function(data) {
					stackcontainer.append(jQuery(data).find('.inner-content').children());
					stackcontainer.find('.mega-tabs').remove();
					jQuery.fn.animateImages();
					jQuery.fn.imagegallery({autostart:false});
 					stackcontainer.removeClass('loading');					
					stackcontainer.addClass('ready')
				});
			}
			
			stacks.find('.stack.active').removeClass('active');
			stackcontainer.addClass('active')
		})						  
	})
	
	jQuery('.mega-tabs a').each(function(i, tab){
		var curtab = jQuery(tab)
		var stacks = jQuery('.stacked-content');										  
		var stackcontainer = stacks.find('.stack[rel='+ curtab.attr('rel') +']');
		
		if(!stackcontainer.is('.ready')){	
			stackcontainer.addClass('loading');
			jQuery.get(curtab.attr('href'), function(data) {
					stackcontainer.append(jQuery(data).find('.inner-content').children());
					stackcontainer.find('.mega-tabs').remove();
					jQuery.fn.animateImages();
					jQuery.fn.imagegallery({autostart:false});
					stackcontainer.removeClass('loading');
					stackcontainer.addClass('ready')
			});
		}
	})
 */
}



