/*-----------------------------------------
 
 copyright 2011 by mmc:agentur
 
 Version: 1.0
 
 Author: David Rerych
 
 Author URI: http://www.mmc-agentur.at
 
 -------------------------------------------*/

var ie7 = ($.browser.msie && ($.browser.version <= 7)) ? true : false;



$(document).ready(function(){
	
	
	
	// $('#search_field').mmcFormDefaults();
	
	/* Header Carousel	*/
	headerCarousel();
	
	$('#header_internal .vorteile_wrap .show_vorteile').click(function(){
		$(this).parent()
		.find('.carousel_wrap, .show_vorteile').hide()
		.parent().find('.vorteile_list').show();
	});
	
	/* Vorteile Carousel	*/
	VorteileCarousel();
	
	/* Sidebar Carousel	*/
	SidebarCarousel();
	
	/* freundschaftswerbung und anmeldung */
        initGeschenk();

	$('.product_carousel').each(function(){
		var $carousel = $(this);
		if ($carousel.find('li').length > 3) {
			$carousel.append('<div class="prev" /><div class="next" /><div class="pagination"><div /></div>');
			$('.carousel', $carousel).mmcCarousel({
				visible: 3,
				scroll: 2,
				btnNext: $('.next', $carousel),
				btnPrev: $('.prev', $carousel),
				circular: false,
				jumpToOtherEnd: false,
				buildPager: $('.pagination div', $carousel),
				speed: 700
			});
		}
	});
	
	
	/* Akkordions */
	$('#content .accordion').each(function(){
		$('.acc_header', this).toggle(
			function() {
				$(this).removeClass('closed').next().slideDown(300,'linear',function(){
					//updateIFrameHeight();
				});
				return false;
			},
			function() {
				$(this).addClass('closed').next().slideUp(300,'linear',function(){
					//updateIFrameHeight();
				});
				return false;
			}
		).addClass('closed').next().hide();
	});
	
	
	/*
	if ($('body').hasClass('tabs_autogenerate')) {
		$('#main_content').before('<div class="tabcontainer"><div class="tabs"><ul></ul></div></div>');
		var $tabs = $('.tabcontainer .tabs ul');
		var tablinks = '';
		$('.content_part').each(function(){
			var $this = $(this);
			var tabtitle = $this.find('.tabtitle').text();
			tablinks += '<li><span><span><span>'+tabtitle+'</span></span></span></li>';
		});
		$tabs.append(tablinks);
	//}
	//if ($('body').hasClass('tabs_autogenerate')) {
		$('li', $tabs).click(function(){
			var i = $(this).index();
			$(this).addClass('active').siblings().removeClass('active');
			$('.content_part').eq(i).show().siblings('.content_part').hide();
			return false;
		});
		$('li', $tabs).first().click();
		$('body').addClass('tabs_initialized');
	}
	*/
	
	
	// Resizing of parent iFrame
	
	$('#page_wrap').bind('resize',function(){
		updateIFrameHeight();
	});
	
	
	$('.product-category .product_list').mmcPagination({
		itemsPerPage: 6
	});
	
	
	var zind = 1000;
	$('.com-basket-item').each(function(){
		$(this).css({'z-index':zind--});
	});
	
	$('.com-input-qty').inputQtySelect({
		start: 1,
		stop: 10,
		callback: function(val){
			log(val);
			$(this).parents('form').submit();
		}
	}).parents('form').find('[type="submit"]').remove();
	
	
	/*var $header_visual = $('.header_visual');
	if ($header_visual.find('div').length > 1) {
		var $pager = $('<div class="header_visual_pagination" />').insertAfter($header_visual);
		$header_visual.cycle({
			pager: $pager,
			timeout: 7000,
			speed: 2000
		});
	}*/
	
	
	// inputfelder, die nur numerische werte values zulassen
  $(".v_int").keydown(function (event) {
    if ((event.keyCode >= 48 && event.keyCode <= 57)       // 0-9 normal
       || (event.keyCode >= 96 && event.keyCode <= 105)) { // 0-9 numpad
     // check textbox value now and tab over if necessary
    } else if (
       event.keyCode != 8 &&  // backspace
       event.keyCode != 46 && // delete
       event.keyCode != 13 && // return
       event.keyCode != 37 && // left arrow
       event.keyCode != 39 && // left arrow
       event.keyCode != 27 && // escape
	   event.keyCode != 9)    // tab
    {
      event.preventDefault();
    }
    // else the key should be handled normally
    var v = parseInt($(this).attr("value"));
    $(this).attr("value", ((isNaN(v))? '' : v));
  }); 

	
	
  // Freundschaftswerbung TabNav auf step2 setzen
  if($('#js_step2').length == 1) {
    $('.tabcontainer li:eq(0)').removeClass('active');
    $('.tabcontainer li:eq(1)').addClass('active');
  }
	
	//updateIFrameHeight();

	counterPixelInit();
	
});


function headerCarousel() {
	
	$('#header_internal .vorteile .vorteile_list').hide();
	$('.freundschaftswerbung_forms #geschenk li.selected');
	var $header_carousel = $('#header_internal .vorteile .carousel_wrap ul');
	if ($header_carousel.find('li').length > 1) {
		var $prev = $('<div class="prev"></div>').insertAfter($header_carousel);
		var $next = $('<div class="next"></div>').insertAfter($prev);
		
		$header_carousel.cycle({
			timeout: 10000,
			speed: 1000,
			fx: 'scrollHorz',
			after: onAfter,
			before: onBefore,
			next: $next,
			prev: $prev, 
			cleartypeNoBg: true
		});
	}

	function onAfter(currSlideElement, nextSlideElement, options, forwardFlag){
		$header_carousel.find('li span').fadeIn();		
	}
	function onBefore(currSlideElement, nextSlideElement, options, forwardFlag){
		$(currSlideElement).find('span').fadeOut();
		$(nextSlideElement).find('span').hide();
	}
	
	
	
}


function SidebarCarousel() {
	
	$('#sidebar .present_carousel').css('height', '255px');
	var checked_index = $('form #geschenk li.selected').index();
	checked_index = (checked_index >= 0)? checked_index : 0;
	var $sidebar_carousel = $('#sidebar .present_carousel ul');
	if ($sidebar_carousel.find('li').length > 1) {
		var $prev = $('<div class="prev"></div>').insertAfter($sidebar_carousel);
		var $next = $('<div class="next"></div>').insertAfter($prev);
		var $pager = $('<div class="present_carousel_pagination" />').insertAfter($next);
		
		$sidebar_carousel.cycle({
			timeout: 0,
			speed: 1000,
			fx: 'scrollHorz',
			after: onAfter,
			before: onBefore,
			next: $next,
			prev: $prev,
			pager: $pager, 
			//cleartypeNoBg: true, 
			startingSlide: checked_index, 
			cleartype: !$.support.opacity
		});
	}

	function onAfter(currSlideElement, nextSlideElement, options, forwardFlag){
		$sidebar_carousel.find('li h3, li p').fadeIn();
		var curr_index = options.currSlide;
		log(curr_index);
		$('form #geschenk li').removeClass('selected').find('input').removeAttr('checked');
		$('form #geschenk li').eq(curr_index).addClass('selected')
                  .find('input').attr('checked', 'checked');
	}
	function onBefore(currSlideElement, nextSlideElement, options, forwardFlag){
		$(currSlideElement).find('h3, p').fadeOut();
		$(nextSlideElement).find('h3, p').hide();
	}
	
}


function VorteileCarousel() {
	var $sidebar_carousel = $('#content .clubvorteile_carousel ul');
	if ($sidebar_carousel.find('li').length > 1) {
		var $prev = $('<div class="prev"></div>').insertAfter($sidebar_carousel);
		var $next = $('<div class="next"></div>').insertAfter($prev);
		var $pager = $('<div class="header_carousel_pagination" />').insertAfter($next);
		
		$sidebar_carousel.cycle({
			timeout: 10000,
			speed: 1000,
			fx: 'scrollHorz',
			after: onAfter,
			before: onBefore,
			next: $next,
			prev: $prev,
			pager: $pager, 
			cleartypeNoBg: true, 
			cleartype: !$.support.opacity
		});
	}

	function onAfter(currSlideElement, nextSlideElement, options, forwardFlag){
		$sidebar_carousel.find('li h2, li h3, li p, li span').fadeIn();	
	}
	function onBefore(currSlideElement, nextSlideElement, options, forwardFlag){
		$(currSlideElement).find('h2, h3, p, span').fadeOut();
		$(nextSlideElement).find('h2, h3, p, span').hide();
	}
	
	
	
}


function updateIFrameHeight(){
	
	var parentIFrame;

/*
	var arrFrames = window.parent.document.getElementsByTagName('iframe');
	for (var i = 0; i < arrFrames.length; i++) {
		var iframe = arrFrames[i];
		var cDoc = (typeof iframe.contentDocument != 'undefined') ? iframe.contentDocument : iframe.contentWindow.document;
		if (cDoc === document) {
			parentIFrame = arrFrames[i];
		}
	}
*/

	try {
		var parentIFrameContainer = window.parent.document.getElementById('container');
		parentIFrame = parentIFrameContainer.getElementsByTagName('iframe')[0];
		parent.window.resizeIframe(parentIFrame);
	} catch(err) {
		log(err);
	}
	
}

/*
XD.receiveMessage(
	function(message){
		//log(message.data);
		
		var data = new Object();
		var data_segments = message.data.split('&');
		for (var i=0; i<data_segments.length; i++) {
			var segment = data_segments[i].split("=");
			data[segment[0]] = segment[1];
			//log(segment[0]+' = '+data[segment[0]]);
		}
		
		var url = decodeURIComponent(data.url);
		
		//log('empfange '+url);
		
		if (window.location != url) {
			window.location = url;
		}
	},
	'http://www.nivea.at'
);
*/

(function( $ ){
	var methods = {
	    init : function( options ) {
			return this.each(function(){
				var $this = $(this);
				var defaults = {
					itemsPerPage: 6,
					paginationTarget: 'after',
					currentPage: 0,
					visibleNextToActive: 2
				};
				var options = $.extend(true, defaults, options);
				options.numberOfPages = Math.ceil($this.children().length / options.itemsPerPage);
				$this.data('options',options);
				if (options.numberOfPages > 1) {
					methods.buildPagination.call($this);
					methods.showPage.call($this,options.currentPage);
				  var height = $this.height();
          $this.height(height);
				}
				
			});
		},
		showPage : function( pageNumber ) {
			return this.each(function(){
				$this = $(this);
				var options = $this.data('options');
				if (!isNaN(pageNumber) && (pageNumber > -1) && (pageNumber < options.numberOfPages)) {
					$this.children().hide();
					var fromItem = pageNumber * options.itemsPerPage;
					var toItem = fromItem + options.itemsPerPage;
					$this.children().slice(fromItem, toItem).show();
					options.currentPage = pageNumber;
					$this.data('options',options);
					methods.updatePagination.call($this);
				}
			});
		},
		buildPagination : function( ) {
			return this.each(function(){
				$this = $(this);
				var options = $this.data('options');
				var paginationHtml = '<div class="pagination_wrap"><div class="pagination"><a href="#" class="prev">Previous Page</a><ol>';
				for(var i = 0; i<options.numberOfPages; i++) {
					paginationHtml += '<li><a href="#">'+ (i+1) +'</a></li>';
				}
				paginationHtml += '</ol><a href="#" class="next">Next</a></div></div>';
			
				if (options.paginationTarget == 'after') {
					options.$pagination = $(paginationHtml).insertAfter($this);
				} else if ($(options.paginationTarget).length > 0) {
					options.$pagination = paginationHtml.appendTo(paginationTarget);
				}
				options.$pagination.find('li a[href]').click(function(e){
					e.preventDefault();
					e.stopPropagation();
					var pgNo = $(this).text()-1;
					methods.showPage.call($this, pgNo);
					return false;
				});
				options.$pagination.find('.prev, .next').click(function(e){
					e.preventDefault();
					e.stopPropagation();
					var direction = $(this).hasClass('next') ? 1 : -1;
					var pgNo = options.currentPage + 1*direction;
					methods.showPage.call($this,pgNo);
					return false;
				});
				$this.data('options',options);
			});
		},
		updatePagination : function( ) {
			return this.each(function(){
				$this = $(this);
				var options = $this.data('options');
				if (typeof options.$pagination != 'undefined') {
					$p = options.$pagination;
					$p.find('.ellipsis').remove();
					$pLi = $p.find('li');
					$pLi
						.eq(options.currentPage).addClass('active')
						.siblings().removeClass('active');
					if (options.numberOfPages > 9) {
						$pLi.hide();
						
						var vnta = options.visibleNextToActive;
						var vInclA = vnta*2 + 1; // visible incl. active
						var firstVisible = options.currentPage-vnta;
						var lastVisible = firstVisible + vInclA;
						if (options.currentPage < (2+vnta+1)) {
							firstVisible = 0;
							lastVisible = 2 + vInclA; // 2 == first Link (always visible) and one ellipsis
						}
						if (options.currentPage > $pLi.length - 1 - (2+vnta+1)) {
							lastVisible = $pLi.length;
							firstVisible = $pLi.length - 2 - vInclA;  // 2 == last Link (always visible) and one ellipsis
						}
						$pLi.slice(firstVisible,lastVisible).show();
						if (!$pLi.first().next().is(':visible')) {
							$pLi.first().after('<li class="ellipsis"><a style="cursor: default;">...</a></li>');
						}
						if (!$pLi.last().prev().is(':visible')) {
							$pLi.last().before('<li class="ellipsis"><a style="cursor: default;">...</a></li>');
						}
						options.$pagination.find('li:first-child, li:last-child').show();
					}
					if (options.currentPage <= 0) {
						options.$pagination.find('.prev').addClass('disabled');
					} else {
						options.$pagination.find('.prev').removeClass('disabled');
					}
					if (options.currentPage >= options.numberOfPages-1) {
						options.$pagination.find('.next').addClass('disabled');
					} else {
						options.$pagination.find('.next').removeClass('disabled');
					}					
				}
			});
		}
		
		
		
	};
	$.fn.mmcPagination = function( method ) {
	    // Method calling logic
	    if ( methods[method] ) {
	      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
	    } else if ( typeof method === 'object' || ! method ) {
	      return methods.init.apply( this, arguments );
	    } else {
	      $.error( 'Method ' +  method + ' does not exist on jQuery.buildPagination' );
	    }  
	};
})( jQuery );


(function( $ ){
	var zIndex = 1000;
	var methods = {
	    init : function( o ) {
			return this.each(function(){
				var $this = $(this);
				log(o.start);
				
				var defaults = {
					start: 0,
					stop: 13,
					callback: false
				};				
				
				var opt = $.extend({}, defaults, o);
				
				$this.data('opt',opt);

				methods.buildQtySelect.call($this);
				var opt = $this.data('opt');
				opt.$pseudoSelect.width($this.outerWidth()-2).find('a[href]').click(function(){
					var val = $(this).text();
					opt.$pseudoSelect.find('li[aria-haspopup="true"]>a>span').text(val);
					$this.val(val);
					if (opt.callback) {
						opt.callback.call($this,val);
					}
					return false;
				});
			});
		},
		buildQtySelect : function( ) {
			return this.each(function(){
				var $this = $(this);
				var opt = $this.data('opt');
				var markup = '<ul role="navigation" class="related qty_select" style="z-index: '+ zIndex-- +';position: relative;"><li aria-haspopup="true"><a><span>'+$this.val()+'</span></a><div><ul>';

				for (var i=opt.start; i<=opt.stop; i++) {
					markup += '<li><a href="#"><span>'+i+'</span></a></li>';
				}
				markup += '</ul><span class="decoration-nw"></span><span class="decoration-ne"></span><span class="decoration-se"></span><span class="decoration-sw"></span><span class="decoration-n"></span><span class="decoration-e"></span><span class="decoration-s"></span><span class="decoration-w"></span></div><span class="decoration-nw"></span><span class="decoration-ne"></span><span class="decoration-se"></span><span class="decoration-sw"></span><span class="decoration-n"></span><span class="decoration-e"></span><span class="decoration-s"></span><span class="decoration-w"></span></li></ul>';
				opt.$pseudoSelect = $(markup).insertAfter($this);
				$this.hide();
				$this.data('opt',opt);
			});
		}
	};
	$.fn.inputQtySelect = function( method ) {
	    // Method calling logic
	    if ( methods[method] ) {
	      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
	    } else if ( typeof method === 'object' || ! method ) {
	      return methods.init.apply( this, arguments );
	    } else {
	      $.error( 'Method ' +  method + ' does not exist on jQuery.inputQtySelect' );
	    }  
	};
})( jQuery );







/* counterpixel request */
function sendRequest(url,button)
{
	/*jQuery.ajax({
	    type: "GET",
	    url: url+button,
	    success: function(content){
			return content;
		}
	});*/
	
	//url = cleanSitePath(url);
	var timestamp = Number(new Date());
	//$("body").append("<IMG SRC='"+ url + button +"&tstamp="+ timestamp +"' HEIGHT=0 WIDTH=0>");
	
	$("body").append('<iframe src="'+ url + button +'" height="0" width="0" frameborder="0" style="border:0;height:0;width:0"></iframe>');
}



function counterPixelInit() {


	 function getSitePath() 
	 { 
	     var path=window.location.pathname;
	     
		 var path_temp = cleanSitePath(path);
		 path = path_temp;
		 
		 /*
		 var counterpixelpath="";
	     
	     if (counterpixelpath.length>0) {
	     	if (counterpixelpath[0] != '/') counterpixelpath = '/'+counterpixelpath;
	     	return counterpixelpath;
	     }
	     */
	     
	     if (path.indexOf("?")) {
	     	var parts=path.split("?");
	     	path=parts[0];
	     }
		 
		 
	     
	     return path;
	 }
	 
	 function cleanSitePath(path) {
	      // entfernen von etwaigen doppelslashes
	     var path_temp = path.replace(/\/\//i, "/");
	     path = path_temp;
	
	     // entfernen von etwaigen no_cache
	     var path_temp = path.replace(/\/no_cache\//i, "/");
	     path = path_temp;
	     
	     // clubrelaunch mit club ersetzen
		 var path_temp = path.replace(/\/clubrelaunch\//i, "/club/");
	     path = path_temp;
	     
	     return path;
	 }	 
	 
	 

	var insertMe = getSitePath();
	
	insertMe = insertMe.replace(/(\.html|\.htm)/g, '');

	var url = "http://counterpixel.nivea.at/cgi-bin/pageimp.exe?/nivea/at/ext/local"+insertMe+"";
	var url2 = "http://counterpixel1.nivea.at/cgi-bin/pageimp.exe?/nivea/at/ext/local"+insertMe+"";
	//var location = window.location.href;
	
	

    
    // Omniture trackNOPV
    
    function trackNOPV(buttonName) {
        try {
           Omniture.trackNOPV(buttonName);
        } catch(e) {
            
        }
    }
    
    // Omniture External Links
    
    $('a[target="_blank"]').click(function(){
        try {
           Omniture.trackExternalLink($(this).attr('href'));
        } catch(e) {
            
        }    
    });    
	
	
	
	$("#sidebar .teaser .jcarousel-prev").click(function(){
		sendRequest(url,"sidebar-carousel/previous.nopv");
		sendRequest(url2,"sidebar-carousel/previous.nopv");
		trackNOPV('sidebar-carousel-previous');
	});
	$("#sidebar .teaser .jcarousel-next").click(function(){
		sendRequest(url,"sidebar-carousel/next.nopv");
		sendRequest(url2,"sidebar-carousel/next.nopv");
		trackNOPV('sidebar-carousel-next');
	});	
	$("#sidebar .teaser .pagination").click(function(){
		sendRequest(url,"sidebar-carousel/pagination.nopv");
		sendRequest(url2,"sidebar-carousel/pagination.nopv");
		trackNOPV('sidebar-carousel-pagination');
	});		
	
	
	$("#small-teasers .jcarousel-prev").click(function(){
		sendRequest(url,"big-carousel/previous.nopv");
		sendRequest(url2,"big-carousel/previous.nopv");
		trackNOPV('big-carousel-previous');
	});
	$("#small-teasers .jcarousel-next").click(function(){
		sendRequest(url,"big-carousel/next.nopv");
		sendRequest(url2,"big-carousel/next.nopv");
		trackNOPV('big-carousel-next');
	});		
	$("#small-teasers .pagination").click(function(){
		sendRequest(url,"sidebar-carousel/pagination.nopv");
		sendRequest(url2,"sidebar-carousel/pagination.nopv");
		trackNOPV('big-carousel-pagination');
	});	
	
	
	$(".product_carousel .prev").click(function(){
		sendRequest(url,"product-carousel/previous.nopv");
		sendRequest(url2,"product-carousel/previous.nopv");
		trackNOPV('product-carousel-previous');
	});
	$(".product_carousel .next").click(function(){
		sendRequest(url,"product-carousel/next.nopv");
		sendRequest(url2,"product-carousel/next.nopv");
		trackNOPV('product-carousel-next');
	});			
	$(".product_carousel .pagination a").click(function(){
		sendRequest(url,"product-carousel/pagination.nopv");
		sendRequest(url2,"product-carousel/pagination.nopv");
		trackNOPV('product-carousel-pagination');
	});
	

	$(".header_visual_pagination a").click(function(){
		sendRequest(url,"header-slideshow/pagination.nopv");
		sendRequest(url2,"header-slideshow/pagination.nopv");
		trackNOPV('header-slideshow-pagination');
	});
	

	$(".product-category .pagination ol li a").click(function(){
		var i = $(this).parent().index()+1;
		sendRequest(url,"product-category/pagination-page-"+i+".nopv");
		sendRequest(url2,"product-category/pagination-page-"+i+".nopv");
		trackNOPV('product-category-pagination_page-'+i);
	});
	$(".product-category .pagination .prev").click(function(){
		sendRequest(url,"product-category/prev.nopv");
		sendRequest(url2,"product-category/prev.nopv");
		trackNOPV('product-category-previous');
	});	
	$(".product-category .pagination .next").click(function(){
		sendRequest(url,"product-category/next.nopv");
		sendRequest(url2,"product-category/next.nopv");
		trackNOPV('product-category-next');
	});

	$(".clubvorteile_carousel .next").click(function(){
		sendRequest(url,"club-vorteile/next.nopv");
		sendRequest(url2,"club-vorteile/next.nopv");
		trackNOPV('club-vorteile-next');
	});
	
	$(".clubvorteile_carousel .prev").click(function(){
		sendRequest(url,"club-vorteile/prev.nopv");
		sendRequest(url2,"club-vorteile/prev.nopv");
		trackNOPV('club-vorteile-previous');
	});
	
	$(".vorteile_wrap .next").click(function(){
		sendRequest(url,"club-vorteile/next.nopv");
		sendRequest(url2,"club-vorteile/next.nopv");
		trackNOPV('club-vorteile-next');
	});
	
	$(".vorteile_wrap .prev").click(function(){
		sendRequest(url,"club-vorteile/prev.nopv");
		sendRequest(url2,"club-vorteile/prev.nopv");
		trackNOPV('club-vorteile-previous');
	});
	
	$('.vorteile_wrap .show_vorteile').click(function(){
	    trackNOPV('club-vorteile-showAtOnce');
	});
	
	
	$(".present_carousel .next").click(function(){
		sendRequest(url,"geschenk/next.nopv");
		sendRequest(url2,"geschenk/next.nopv");
		trackNOPV('geschenk-next');
	});
	
	$(".present_carousel .prev").click(function(){
		sendRequest(url,"geschenk/prev.nopv");
		sendRequest(url2,"geschenk/prev.nopv");
		trackNOPV('geschenk-prevous');
	});
	
	$(".present_carousel_pagination a").click(function(){
		var i = $(this).index()+1;
		sendRequest(url,"geschenk/pagination-page-"+i+".nopv");
		sendRequest(url2,"geschenk/pagination-page-"+i+".nopv");
		trackNOPV('geschenk-pagination_page-'+i);
	});
	

	$('.accordion .acc_header').toggle(
		function(){
			var headerTxt = cleanCounterpixelString($.trim($(this).find('h2').clone().find('.date').remove().end().text()));
			sendRequest(url,"accordion/"+headerTxt+"/open.nopv");
			sendRequest(url2,"accordion/"+headerTxt+"/open.nopv");
			trackNOPV('accordion-'+headerTxt+'-open');
		},
		function(){
			var headerTxt = cleanCounterpixelString($.trim($(this).find('h2').clone().find('.date').remove().end().text()));
			sendRequest(url,"accordion/"+headerTxt+"/close.nopv");
			sendRequest(url2,"accordion/"+headerTxt+"/close.nopv");
			trackNOPV('accordion-'+headerTxt+'-close');			
		}
	);


}

function cleanCounterpixelString(str)
{
	str = str.
		replace(/ü/, "ue").
		replace(/ö/, "oe").
		replace(/ä/, "ae").
		replace(/Ü/, "Ue").
		replace(/Ä/, "Ae").
		replace(/Ö/, "Oe").
		replace(/ß/, "ss").
		replace(/[^a-zA-Z0-9]+/g, "");
	return str;
}

function initGeschenk()
{
  if($('.present_carousel')) {
    var m = $('.present_carousel ul').html();
    if($('.fsw_step2')) {
      m = ''; // geschenk fuer Freund default ist redaktionell eingepflegt
    }
    $('#geschenk .js_fetch').each(function(){
      m += '<li>' + $(this).html() + '</li>';
    });
    $('.present_carousel ul').html(m);
    SidebarCarousel();
    //alert(m);
  }
}

