/*	JS for MarcCain Relaunch 2011
	Authors: Daniel Sattler, David Steeb, Julian Lochstampfer, Benjamin Mack
*/

var isIE7 = (navigator.appVersion.indexOf("MSIE 7.") === -1) ? false : true;
var isIE8 = (navigator.appVersion.indexOf("MSIE 8.") === -1) ? false : true;
var isIE9 = (navigator.appVersion.indexOf("MSIE 9.") === -1) ? false : true;
var isPad = navigator.userAgent.match(/iPad/i) != null;
var isPhone = navigator.userAgent.match(/iPhone/i) != null;


	// sliding forward (1) or backward (0) of company-slider
var companySliderCurrentPosition = 0
var companySliderItemCount = 0
var companySliderStopAnimation = 0
var itemWidth = 0
var newBannerMargin = 0
var maxBannerMargin = 0
var sliderFadeTime = 800
var sliderWaitTime = 3000


	// You can set some min-height of the page. If left-menu is bigger then this min-hight, 
	// the new min-height is set with the height of the left-menu
var html = {
	'minHeight': 0,
	'totalHeight': 0
};

// global variables
var randomVideoTeaserTimeout = 0;
var isRandomVideoPlaying = false;
var durations = {
    'buttonHover': 400,
    'hoverMainMenu': 300,
    'campainListViewHover': 500,
    'imageMapHover': 400,
    'imageMapHoverOut': 300,
    'fadeInLayerPvDetail': 350,
    'campaignFadeInOutButton': 400,
    'zoomFade': 350
};

	// we set this to the current window width in rescale-function (to avoid duplicate processing)
var windowWidthLastRun = 0;
var windowHeightLastRun = 0;




/**
 * does some various form-related logic
 */
var b13forms =  {

		// input logic
	initInputFieldsWithTitle: function() {
		$('input[type=text]').each(b13forms.fillInputWithTitle);
		$('input[type=text]').blur(b13forms.fillInputWithTitle);
		$('input[type=text]').blur(function() {
			$(this).parent('.formRow').removeClass('isActive');
		});
		$('input[type=text]').bind('click focus', b13forms.removeTitleFromInput);
		$('input[type=text]').bind('click focus', function() {
			$(this).parent('.formRow').addClass('isActive');
		});
		$('form').bind('submit', function() {
/* 			$('input[type=text]').each(b13forms.removeTitleFromInput); */
			$(this).find('input[type=text]').each(b13forms.removeTitleFromInput);
		});
	},

		// fill input field with corresponding title-field
	fillInputWithTitle: function() {
		if ($(this).attr('title') && ($(this).val() === '' || $(this).val() === $(this).attr('title'))) {
			$(this).val($(this).attr('title'));
			$(this).addClass('inputDefaultValue');
			if ($(this).hasClass('inputTitleColor')) {
				$(this).css({color: '#aaa' });
			}
		}
	},

		//remove value from input if default-value
	removeTitleFromInput: function() {
		if ($(this).hasClass('inputDefaultValue') && $(this).val() === $(this).attr('title')) {
			$(this).val('');
			$(this).removeClass('inputDefaultValue');
			if ($(this).hasClass('inputTitleColor')) {
				$(this).css({color: '#666' });
			}
		}
	}


};


/**
 * calculates the min-height of the page according to the mainmenu
 */
b_calcMinHeight = function(){
	var leftColHeight = 0;
	leftColHeight += $('.logoWrap').height();
	leftColHeight += $('.searchWrap').height();
	leftColHeight += $('#mainMenu').height();
	leftColHeight += $('#metaNavigation').height() + 30;

	if (html.minHeight < leftColHeight) {
		html.minHeight = leftColHeight;
	}
};



/** 
 * check the heights of the various elements to resize the sidebars
 * 4 cases:
 * the main-menu is bigger than the body (content) and the window
 * the window is bigger than the body (content) and the mainmenu
 * the body (content) is bigger than the window and the mainmenu
 * the campaignList gets shown and the .campaignList is bigger than the html.totalHeight
 */
b_calcAllHeights = function(isStartpage){
	$('#mainContent').height('auto');
	$('body').height('auto');
	$('.checkoutContent').removeAttr('style');
	html.totalHeight = html.minHeight;

	if (html.totalHeight < $(window).height()-2) {
		html.totalHeight = $(window).height()-2;
	}
	if (html.totalHeight < $('body').height()) {
		html.totalHeight = $('body').height() - 1;
	}
	
	if ($('.campaignList').height() > html.totalHeight) {
			// set html.totalHeight to the height() of .campaignList minus 1 pixel to ensure 
			// we never see 2 white pixels als "border-bottom-look-alike"
		html.totalHeight = $('.campaignList').height() -1;
	}

	if (html.totalHeight < $(window).height()){
			// writes the totalheight to the body for scrolling
		$('body').height(html.totalHeight);
			// writes the totalheight to the maincontent for hiding a scroller, 
			// if the image is big as the window an has border-bottom: 1px #fff
		$('#mainContent').height(html.totalHeight);
	}
	
		// check if IE-7 and set the body-height only in some few cases
		// all other browsers: do nothing.
	if (isIE7) {
			// sets the height of the body only, if the html.totalHeight is bigger than the window.
			// used, to position the footoer on the bottom of the page
		if (html.totalHeight < $(window).height()){
			$('body').height(html.totalHeight);
			$('#mainContent').height(html.totalHeight);
		}
		if (isStartpage) {
			$('body').height(html.totalHeight);
			$('#mainContent').height(html.totalHeight);
		}
	}
	else {
			// writes the totalheight to the body for scrolling
		$('body').height(html.totalHeight);
			// writes the totalheight to the maincontent for hiding a scroller, 
			// if the image is big as the window an has border-bottom: 1px #fff
		$('#mainContent').height(html.totalHeight);
	}
	
		// writes the totalheight to the sidebars for the *bolow-divs
	$('.rightColInnerWrap').height(html.totalHeight);
	$('.leftColInnerWrap').height(html.totalHeight);
	
/* alert(html.totalHeight + ' ' + $('.checkoutContent').outerHeight()) */
		// writes the height into the checkoutcontent 
	if ($('.checkoutContent').outerHeight() < html.totalHeight) {
			// -50 for the checkout-navi
		var checkoutHeight = html.totalHeight - 51;
/* alert(checkoutHeight) */
		if($('.contentHeader').length > 0) { 
				// -114 for contentHeader and headline
			checkoutHeight = html.totalHeight - 114;
/* alert(checkoutHeight) */
		} 
		$('.checkoutContent').height(checkoutHeight).css({'padding-bottom': 0});
	}
	
		// show Footer and Meta-Menu
	$('#footer').show();
	$('.mainMenuBelow').css('visibility', 'visible');
	
};


/**
 * calculates the ratio between the width and
 * the height of a given element
 * the ratio is calculated using the original data if accessible, otherwise the current width and height are used
 */
b_getRatio = function(el){
	var ration;
	if ($(el).data('width') && $(el).data('height')) {
		ratio = $(el).data('width') / $(el).data('height');
	} else {
		ratio = $(el).width() / $(el).height();
	}
	return ratio;
};

/**
 * hide images while they're not loaded or when the window is resizing
 */
b_showHideImages = function (col, status) {
	if (status === "hide") {
		$(col).hide();
	} else {
		$(col).fadeIn(800);
	}
};

/**
 * resize the image for the startpage. on the startpage the image is behind the mainmenu. 
 * resize to the height of the window-size
 */
b_scaleStartpageImage = function(img) {
	var imgHeight = parseInt($(window).height()-2);
		// find the correct width of the "viewable" area
	var maxWidth = ($(window).width() > 1400 ? 1398 : ($(window).width() < 980 ? 980 : ($(window).width()-2)));
	var imgWidth = b_getRatio(img) * imgHeight;
	var marginLeft = parseInt((maxWidth - imgWidth) / 2);
		// this is needed for the startpage to ensure that the image doesn't get carried 
		// to the right and cropped of most of its content to the right
	if (marginLeft > 0) {
		marginLeft = 0;
	}
	
	img.width(imgWidth).height(imgHeight).css({'marginLeft': marginLeft});
	b_showHideImages(img);
};



/**
 * resize a video (HTML tag) to the window size but keep the aspect ratio
 * arrange to height AND width. always show the whole video
 */
b_scaleStartpageVideo = function(videoEl) {
		// the maximal "viewable" height of the image
	var maxHeight = $(window).height() - 2;
	var maxWidth = $(window).width() - 2;
		// check the original ratio of the image
	var videoElRatio = b_getRatio(videoEl);

	if (isIE7) {
		videoElRation = videoEl.data('width') / videoEl.data('height')
	}
	
	var videoElHeight, videoElWidth = 0;
	var cssOptions = {
		'position': 'absolute',
		'zIndex': '-40000'
	};

	if (isPad || isPhone){
		cssOptions.position = 'static'
		maxWidth = maxWidth - 201
		$('.imageWrap').css({'padding-left': 201} )
		$('.imageInnerWrap').css({'overflow': 'hidden'} )
	}


		// wouldvideoElWidth:: how wide would the image be, if we arrange to height
	wouldVideoElWidth = parseInt(videoElRatio * maxHeight);


		// check if we can arrange to height or need to arrange to width.
	if (wouldVideoElWidth < parseInt(maxWidth)) {
		videoElHeight = parseInt(maxWidth / videoElRatio);
		videoElWidth = maxWidth;
		cssOptions.marginTop = parseInt((maxHeight - videoElHeight) / 2);
		cssOptions.marginLeft = 0;
	} else {
		videoElHeight = maxHeight;
		videoElWidth = wouldVideoElWidth;
		cssOptions.marginTop = 0;
		cssOptions.marginLeft = parseInt((maxWidth - videoElWidth) / 2);
	}
	
	if (isIE7){
		b_calcAllHeights(true)
	} 
	$('body').css({'overflow': 'hidden'})
	
	
	videoEl.width(videoElWidth).height(videoElHeight).css(cssOptions);
		
	
};




/**
 * resize the image for the campaign-pages. there is no image behind the mainmenu.
 * arrange to height AND width. always show the whole image
 */
b_scaleImageToArea = function(img, dontFadeIn) {
		// the maximal "viewable" height of the image
	var maxHeight = $(window).height()-2;
		// check the original ratio of the image
	var imgRatio = b_getRatio(img);
	var imgWidth = 0;
	var imgHeight = 0;
	var maxWidth;
		// check if there is a rightcol an find the correct width of the "viewable" area
	if ($('#rightCol').length  > 0) {
		maxWidth = ($(window).width() > 1400 ? 998 : ($(window).width() < 980 ? 580 : ($(window).width()-403)));
	}
	else {
		maxWidth = ($(window).width() > 1400 ? 1198 : ($(window).width() < 980 ? 780 : ($(window).width()-203)));
	}

		// wouldImgWidth:: how wide would the image be, if we arrange to height
	wouldImgWidth = parseInt(imgRatio * maxHeight);
	
		// check if we can arrange to height or need to arrange to width.
	if (wouldImgWidth > parseInt(maxWidth)) {
		imgHeight = parseInt(maxWidth / imgRatio);
		imgWidth = maxWidth;
	}
	else {
		imgHeight = maxHeight;
		imgWidth = wouldImgWidth;
	}
	
	
		// ensure the hover images for imagemaps don't get two fade-ins
	if (!dontFadeIn) {
		img.width(imgWidth).height(imgHeight);
		b_showHideImages(img);
			// set the position of the right menu/column. always to the right of the image.
		$('#rightCol').css({'left': imgWidth + 202});
	}
	else {
		img.animate({ width: imgWidth, height: imgHeight}, durations.zoomFade, 'linear', function() {
			b_calcAllHeights();
		});
			// set the position of the right menu/column. always to the right of the image.
			// animate is set for the zoom-Out-View
		$('#rightCol').animate({'left': imgWidth + 202}, durations.zoomFade);
	}
};

/** 
 * arrange the image to the width. 
 * If the image is higher than the window, there will be a scroller.
 */
b_scaleImageToWidth = function(img, animate) {
	var maxWidth = ($(window).width() > 1400 ? 1198 : ($(window).width() < 980 ? 780 : ($(window).width()-203)));
	var imgHeight = maxWidth / b_getRatio(img);
	
	if (animate){
		img.animate({ width: maxWidth, height: imgHeight}, durations.zoomFade, 'linear', function() {
				// if the image is not shown (which happens if you resize the browser, because than the image will be hidden at first
			if (img.css('display') === 'none') {
				b_showHideImages(img, 'show');
			}
			b_calcAllHeights();
		});
	}
	else {
		img.css({ width: maxWidth, height: imgHeight});
				// if the image is not shown (which happens if you resize the image, because than the image will be hidden at first
		if (img.css('display') === 'none') {
			b_showHideImages(img, 'show');
		}
		b_calcAllHeights();
	}
		// set the position of the right menu/column. always to the right of the image.
	$('#rightCol').animate({'left': maxWidth + 202}, durations.zoomFade);
};


/**
 * scaling of image-map-pictures (hoverimages)
 */
b_initImageMap = function() {
	if ($('.campaignViewWithMap map').length > 0) {
		$('map area').each(function() {
			var map = $(this).data("originalcoords");
			var imgHeight = $('.campaignTeaser').data('height');
			var currentHeight = $('.campaignTeaser').height();
			var imgRatio = currentHeight / imgHeight;
			var newCoords = "";
			var coords = map.split(",");

			for (i=0; i<coords.length; i++) {
				if(i < coords.length-1) {
					newCoords += parseInt(coords[i] * imgRatio) + ",";
				} else {
					newCoords += parseInt(coords[i] * imgRatio);
				}
			}
			$(this).attr('coords', newCoords);
		});
			// write the current width and height of the image to the div.hoverImages. (div.hoverImages {overflow:hidden}
		$('.hoverImages').css({
			'width': $('.campaignTeaser').width(),
			'height': $('.campaignTeaser').height()
		});
	}
};


/*
 * campaign - scale list view
 * scale the img in the campaign list view proportial of the window size. form 1024 to 1280
*/
b_scaleListView = function() {
	
	
	// first we want to check if this function is really needed to run 
	// (has the size of the window changed since the last run?
	// if the window-size hasn't changed, simply return
/*
	if (windowWidthLastRun == $(window).width()) {
		return;
	} 
*/

	// reset the inline styles
	$('.row').each(function() {
		$(this).css({'width': 'auto'});
	});
	$('.imageWrap').css({'width': 'auto'});
	$('.campaignRow').width('auto');
	$('.campaignRow').each(function() {
		$(this).css({'width': 'auto'});
	});
	$('.imageWrap a img').each(function() {
		$(this).css({
			'height': 'undefined',
			'width': 'undefined'
		});
	});

		var container = $('.campaignRow');
		var containerW = $(window).width() - 198;
		var minW = 780;
		var maxW = 920;
		var checkCurrentRowWidth = 0;
		var testausgabe = "";
		
			// first we determine the desired row-width
			// containerW > maxW -> maxW
			// containerW < minW -> minW
			// containerW between minW and maxW -> containerW
		var newRowWidth = (containerW >= maxW ? maxW : (containerW > minW ? containerW : minW));
		
			// get current Row Width
		var currentRowWidth = 0;
		$(container).children().first().children().children().each(function() {
			currentRowWidth += $(this).children('img').width();
		});
		
			//parse all rows
		for (i=0; i < $(container).length; i++) {
		
				// gets current row height and calculates current row ratio
			var currentRowHeight = $('.campaignList .campaignRow:eq('+i+') .row .imageWrap a').children().height();
			var currentRowRatio = currentRowHeight/currentRowWidth;

				// get the new height of the row proportional to the max width of the container $('.campaignRow') 
			var newHeight = parseInt((newRowWidth * currentRowHeight) / currentRowWidth);
			var checkNewRowWidth = 0;
			
				// parse the images in a row
			for (b=0; b < $('.campaignList .campaignRow:eq('+i+') .row').children().length; b++ ) {
				
					// el is one image
					// elwrap is the wrap around the image
				var elwrap = $('.campaignList .campaignRow:eq('+i+') .row .imageWrap:eq('+b+')');
				var el = $(elwrap).find('img');
				
					//scale one image to the newHeight
				var newWidth = parseInt(newHeight * b_getRatio($(el)));
	
				$(el).css({
					'height': newHeight,
					'width': newWidth
				});
				$(elwrap).css({'width': newWidth});
				checkNewRowWidth += newWidth + 1;
			}
			
			$('.campaignList .campaignRow:eq('+i+') .row').css({'width': checkNewRowWidth });
			
				// get the smallest row,.put the value in the <div class="campaignRow">
				// important to hide the y-scrollbar
			if (checkNewRowWidth < checkCurrentRowWidth || i === 0) {
				checkCurrentRowWidth = checkNewRowWidth;
			}
		}
		
/* 		$('.campaignRow').css({'width': newRowWidth +1}); */
		
			// show images
		b_showHideImages('.campaignList');
		b_calcAllHeights();
		
			// set window-width to windowWithLastRun to ensure we only recalculate if the window has been resized
		windowWidthLastRun = $(window).width();
};


	/**
	 * adds a hover-effect to all buttons
	 * except the buttons that are included within a div.hoverImages (for campaign-ImageMap-Features), since we need a different approach there (position:absolute for .hoverImages)
	 */

	/**
	 * adds a hover-effect to all buttons
	 * new version May, 3rd 2011
	 */
b_initButtonHover = function() {

	$('.button, .buttonHover').hover(function() {
		$(this).stop(true, true).css({opacity: '0.9', backgroundColor: '#444'}).animate({opacity: '1', backgroundColor: '#666'}, durations.buttonHover);
	}, function() {
		$(this).stop(true, true).css({opacity: '1', backgroundColor: '#666'}).animate({opacity: '0.9', backgroundColor: '#444'}, durations.buttonHover);
	});

	$('.buttonCompany').hover(function() {
		$(this).stop(true, true).animate({opacity: '1', backgroundColor: '#666'}, durations.buttonHover);
	}, function() {
		$(this).stop(true, true).animate({opacity: '0.9', backgroundColor: '#999'}, durations.buttonHover);
	});

	$('.buttonCompanyOverview').hover(function() {
		$(this).stop(true, true).animate({opacity: '1', backgroundColor: '#4c4c4c'}, durations.buttonHover);
	}, function() {
		$(this).stop(true, true).animate({opacity: '0.9', backgroundColor: '#666'}, durations.buttonHover);
	});

};



/** 
 * opens the layer of the product-detailview 
*/

b_openLayer = function(relAttr) {
		var layerNr = relAttr.split('-');
		
		$('body').addClass(relAttr);
		$('.overlay, #layer-' + layerNr[1]).fadeIn(durations.fadeInLayerPvDetail);
		
		var belowHeight = $('body').height() - $('#layer-' + layerNr[1] + ' .layerContent').height() - 92; 
		$('#layer-' + layerNr[1] + ' .layerBelow').height(belowHeight);
		
			//show the close button
		$('.layerClose').delay(200).fadeIn('slow');
};


/**
 * fade in the zoom-button on pv-pages
 */
b_initZoomButton = function() {
	$('.pvImgItem').hover( 
	function() {
			// prevent the plus-icon to hover when image is in zoomed-mode
		if (!$(this).hasClass('layerZoomed')) {
			$(this).find('.buttonZoomIcon').stop(true, true).fadeIn(durations.campainListViewHover);
		}
	},
	function() {
		$(this).find('.buttonZoomIcon').stop(true, true).fadeOut(durations.campainListViewHover);
	});
};

/**
 * store some data after loading of the page, so we can access original values (colors, dimensions) 
 * after having changed some values.
 */
b_storeData = function (){
		// save the size of all images
	$('img').each(function() {
		$(this).data('width', $(this).width());
		$(this).data('height', $(this).height());
	});
		// save the start bg color in the data-bgColor, all elements with the class 
		// colorSwitch fade to #333 but the have different current bg colors
	$('.colorSwitch').each(function() {
		$(this).data('bgColor', $(this).css("background-color"));
		$(this).children().data('color', $(this).children().css("color"));
	});
};

/**
 * zoom-function for campaign-pages incl. image-replace with zoom-image
 */
b_initCampaignZoom = function() {
	$('.zoomIn-Out').children().click(function() {
		var img = $('.campaignTeaser');
		var button = $('.navi');
		button.fadeOut(500);
		$('.buttonAbsolute').fadeOut(500);
		$('.bigImg').fadeOut(500)
		img.fadeOut(500, function() {
		
			if ($(this).hasClass('zoomIn')) {
				
/* 				$(this).removeClass('zoomIn').addClass('zoomOut').text("Zoom In"); */
				var buttonText = $('.topNaviRight a').data('zoomintext')
				$('.topNaviRight a').text(buttonText)
				$(this).removeClass('zoomIn').addClass('zoomOut').text();
				b_scaleImageToArea(img, 1);
			} else {
				var buttonText = $('.topNaviRight a').data('zoomouttext')
				$('.topNaviRight a').text(buttonText)
				$(this).removeClass('zoomOut').addClass('zoomIn');
				$(img).removeClass('arrangeToHeight').addClass('fullHeightImage');
				b_scaleImageToWidth(img);
/* 				bigImgSrc = img.parent().prop('href'); */
				bigImgSrc = img.data('zoomview')
				newImgWidth = img.data('width')
				newImgHeight = img.data('height')
				if (bigImgSrc === undefined) { 
					img.before('<img src="'+ bigImgSrc +'" width="'+ newImgWidth +'" height="'+ newImgHeight +'" class="bigImg newImage" style="display: none; position: absolute; left: 0; top: 0; " />');
					b_scaleImageToWidth($('.bigImg'))
					$('.bigImg').fadeIn('slow')
				}
			}
			img.fadeIn(800);
			button.fadeIn(800);
		});
		return false;
	});
/*
			var bigImgSrc = $(el).prop('href');
			$(el).children().before('<img src="'+ bigImgSrc +'" width="510" height="'+ newHeight +'" class="bigImg" style="position: absolute; z-index: 601; display: none; left: '+ -1*moveToLeft +'px; top: '+ -1*moveToTop +'px; " >');
			//if the animation is done, fade in the big img over the curren img
			$('img.bigImg').load(function() {
				$(this).fadeIn('slow');
			});
*/





};
	// Show by hovering the "Complete the Outfit"-Images a CTA
b_initPvSubImgList = function() {
	$('.pvSubImgList .pvImgItem').hover(function() {
		$(this).find('.pvImgItemCTA').stop(true, true).fadeIn();
	},
		function() {
		$(this).find('.pvImgItemCTA').stop(true, true).fadeOut();
	});
};

// returns a jQuery object of a random video
b_findRandomVideo = function() {
	var videos = $('video');
	var randomVideoNo = Math.floor(Math.random()*videos.length);
	return videos.eq(randomVideoNo);
};

b_playRandomVideo = function() {
	var videoEl = b_findRandomVideo();
	var amazingVideoObj = videoEl.data('amazingVideo');
	amazingVideoObj.play();

	window.clearTimeout(randomVideoTeaserTimeout);

	amazingVideoObj.$el.unbind('ended').bind('ended', function(evt) {
		randomVideoTeaserTimeout = window.setTimeout(function(){
			b_playRandomVideo();
		}, 1000);
		amazingVideoObj.$el.unbind(evt);
		amazingVideoObj.end();
	});
};

/*
//prv play Video
b_playVideo = function(elementId) {
	//check that it's just 1 video playing
	var playingVideo = $('.video-js.vjs-playing');
	if ($(playingVideo).length > 0) {
		b_stopVideo($(playingVideo).prop('id'));
	}

	$('#' + elementId).get(0).player.currentTime('0');
	$('#' + elementId).get(0).player.play();
};

b_stopVideo = function(elementId) {
	$('#' + elementId).next().next().fadeIn('fast');
	$('#' + elementId).get(0).pause();
	
};

*/




b_companySliderMoveToRight = function() {
	nextPosition = companySliderCurrentPosition + 1
	newBannerMargin = nextPosition * itemWidth * (-1)
	if (nextPosition == companySliderItemCount - 1) {
		$('.companySliderNaviRight').hide();
	}
	$('.companySliderNaviLeft').show();
	$('.companySliderBannerWrap').animate({'margin-left': newBannerMargin}, sliderFadeTime);
	companySliderCurrentPosition = nextPosition
}

b_companySliderMoveToLeft = function() {
	nextPosition = companySliderCurrentPosition - 1
	newBannerMargin = nextPosition * itemWidth * (-1)
	if (nextPosition == 0) {
		$('.companySliderNaviLeft').hide();
	}
	$('.companySliderNaviRight').show();
	$('.companySliderBannerWrap').animate({'margin-left': newBannerMargin}, sliderFadeTime);
	companySliderCurrentPosition = nextPosition

}

b_animateCompanySlider = function() {
	
	if (companySliderCurrentPosition < companySliderItemCount -1 && companySliderStopAnimation == 0) {
		b_companySliderMoveToRight();
		window.setTimeout(function() { b_animateCompanySlider(); }, sliderWaitTime);
		return;
	}
	if (companySliderCurrentPosition == companySliderItemCount -1 && companySliderStopAnimation == 0) {
		$('.companySliderBannerWrap').animate({'margin-left': 0}, 800);
		$('.companySliderNaviLeft').hide();
		$('.companySliderNaviRight').show();
		companySliderCurrentPosition = 0
		window.setTimeout(function() { b_animateCompanySlider(); }, sliderWaitTime);
		return;
	}
	window.setTimeout(function() { b_animateCompanySlider(); }, sliderWaitTime);
	
}


b_initCompanySlider = function() {

	if ($('.companySliderItem').length > 1) {
		itemWidth = $('.companySliderVisualWrap').width();
		companySliderItemCount = $('.companySliderItem').length
		newBannerMargin = 0
		maxBannerMargin = ($('.companySliderItem').length - 2) * itemWidth * (-1)
		
		$('.companySliderNaviRight a').click(function(evt){
			evt.preventDefault();
			b_companySliderMoveToRight();
		}) 
	
		$('.companySliderNaviLeft a').click(function(evt){
			evt.preventDefault();
			b_companySliderMoveToLeft();
		}) 
		
			//shows the navigation only by hovering the company-slider and Stopp the animation
		$('.companySlider').hover(function() {
			$('.companySliderNavi').fadeIn('slow')
			companySliderStopAnimation = 1
		}, function(){
			$('.companySliderNavi').fadeOut('slow')
			companySliderStopAnimation = 0
		})
			
			
			// adds a hover-effect to the navigation of the company-slider
		$('.companySliderNavi a').hover(function(){
			$('.companySliderNavi a').stop(true, true).animate({'opacity': 1}, durations.buttonHover)
		}, function(){
			$('.companySliderNavi a').stop(true, true).animate({'opacity': 0.8}, durations.buttonHover)
		})
		
		window.setTimeout(function() { b_animateCompanySlider(); }, sliderWaitTime);
	}
}


b_mediaQueryForIE = function() {
	if (isIE7 || isIE8){
	
		if ($(window).width() < 1254) {
			$('.detailView .mainContentInnerWrap').width(680)
			$('.layer').css({'left': 201})
			$('.naviClose').css({'right': 169 })
		}
		if ($(window).width() < 1112) {
			$('.detailView .mainContentInnerWrap').width(510)
		}
	}
}





/**##############################################
 * ##############################################
 * main function
 */
$(document).ready(function(){	
		// calculate the actual min-height of the main-menu
	b_calcMinHeight();

	//add Controls for iPhone and iPad
	if(isPad || isPhone) {
		$('video').each(function() {
			$(this).attr("controls", "true");
		});
	}
	
		// sets the title of an input into the input and replace by click on the input
	b13forms.initInputFieldsWithTitle();
	
		//init video
	if ($('.video-js-box').length > 0) {
		VideoJS.setupAllWhenReady();
	}


	if ($('.videoStartpage').length) {
		b_scaleStartpageVideo($('.videoStartpage'));
		b_scaleStartpageVideo($('.amazingVideoWithFlash'));
		if (isIE7) {
			window.setTimeout(function() {
				b_scaleStartpageVideo($('.videoStartpage'));
				b_scaleStartpageVideo($('.amazingVideoWithFlash'));
			}, 900)
		};
		$(window).resize(function() {
			b_scaleStartpageVideo($('.videoStartpage'));
			b_scaleStartpageVideo($('.amazingVideoWithFlash'));
		});
	}


			// CSS media-Queries for IE7 and IE8
	b_mediaQueryForIE();
	

	
		//hide all the fullscreen images (.imageWrap > .campaignTeaser ensures that hoverImages will not be affected by this)
	b_showHideImages('.mainImage, .imageWrap .campaignTeaser, .campaignList', "hide");
	
		// init the fade in of the zooming-button in the product-detail-view (AP2)
	b_initZoomButton();

		// initialize jqTransform
	$('.jqTransform').jqTransform();

		// this gets done once window.load is ready
	$(window).load(function() {
			// at first of all, store all image-sizes and the backgroundcolor of buttons in the data-attribut  
		b_storeData();
		
			// do some scaling: startpage, campaign-pages
		if ($('.startpage').length > 0) {
			b_scaleStartpageImage($('.mainImage'));
		}
		if ($('.campaignView').length > 0) {
			b_scaleImageToArea($('.campaignTeaser'));
		}
			// calculate the coords of the imagemap
		b_initImageMap();
		
			//show the images of the .prvWrap
		b_showHideImages('.prvWrap');
		
			// calculate all heights
		b_calcAllHeights();
		

		// call plugin on multiple DOM elements
		if ($('.amazingVideo').length > 0) {

			var $aVideos = $('.amazingVideo').amazingVideo();
			b_playRandomVideo();
		}

		if ($('.videoStartpage').length) {
			if (isIE7) {
					b_scaleStartpageVideo($('.videoStartpage'));
					b_scaleStartpageVideo($('.amazingVideoWithFlash'));
			};
		}
		

	});




		// this gets done once the window gets resized
	$(window).resize(function(){
		var lastRun = windowWidthLastRun + windowHeightLastRun;
		var nowRun = $(window).width() + $(window).height();
		
		if (lastRun !== nowRun) {
				// hide all images
			b_showHideImages('.mainImage, .imageWrap .campaignTeaser, .campaignList', "hide");
				// do some scaling: startpage, campaign-pages
			if ($('.startpage').length > 0) {
				b_scaleStartpageImage($('.mainImage'));
			}
			if ($('.campaignView').length > 0  && $('.zoomIn').length === 0) {
				b_scaleImageToArea($('.campaignTeaser'));
			}
			if ($('.campaignView').length > 0  && $('.zoomIn').length > 0) {
				b_scaleImageToWidth($('.campaignTeaser'));
			}
				// recalculate imagemaps and heights
			b_initImageMap();
			b_calcAllHeights();
			
			windowWidthLastRun = parseInt($(window).width());
			windowHeightLastRun = parseInt($(window).height());
			
				// CSS media-Queries for IE7 and IE8
			b_mediaQueryForIE();
			
			

		}
		
	});
	
	
		// scale the listview if there is one and add the scaling-function to load- and resize-events
	if ($('.campaignList').length > 0) {
		$(window).load(function() {
			b_scaleListView();
			$(window).resize(function() {
				b_scaleListView();
			});
		});
	}

		// add the prv-images to show/hide-function if any
		//doesn't work with ie7 and ie8
	if ($('.prvWrap').length > 0 && !isIE7 && !isIE8) {
		b_showHideImages('.prvWrap', "hide");
		// lochstampfer:: moved to window.load()
/*
		$('img').load(function() {
			b_showHideImages('.prvWrap');
		});
*/
	}
		// init the zoom-button on the campaign-view
	b_initCampaignZoom();
	
		// Show a small "Zum Produkt"-Link below the "Complete the Outfit"-Images
	b_initPvSubImgList();

		//campain list view hover
	if ($('.campaignList').length > 0) {
		$('.imageWrap').hover(function() {
			var children = $(this).children('.imgHover');
			$('.imgHover').not(children).stop(true, true).fadeIn(durations.campainListViewHover);
			children.stop(true, true).fadeOut(durations.campainListViewHover);
			$(this).find('.CTA').stop(true, true).delay(500).fadeIn(durations.campainListViewHover);
			$(this).find('.eyeCatcher').stop(true, true).delay(500).fadeIn(durations.campainListViewHover);
		}, function() {
			var children = $(this).children('.imgHover');
			$(this).find('.CTA').stop(true, true).fadeOut(durations.campainListViewHover);
			$(this).find('.eyeCatcher').stop(true, true).fadeOut(durations.campainListViewHover);
		});
		$('.campaignList').mouseleave(function() {
			$('.imgHover').stop(true, true).fadeOut(durations.campainListViewHover);
		});
	}
	
		// right sidebar accordion
	$('.accordionLink').click(function(evt) {
		evt.preventDefault();
		var el = $(this).parent('.accordionHeadline').parent('.accordionItem');
		if ($(el).hasClass('accordionClosed')) {
			var headlineHeight = $(el).find('.accordionHeadline').height();
				// +31px for the height of the button and +1px for the margin-bottom of the body
			$(el).addClass('accordionOpened').animate({ 'height': $(this).parent().next().height() + headlineHeight +1}, 400, function() { 
				$(el).removeClass('accordionClosed'); 
			});
			var toCloseElement = $(el).siblings('.accordionOpened')
			toCloseElement.removeClass('accordionOpened');
			toCloseElement.addClass('accordionClosed');
			var toCloseHeadlineHeight = toCloseElement.find('.accordionHeadline').height()
			$('.accordionSelect').removeClass('open');
			toCloseElement.animate({ 'height': toCloseHeadlineHeight + 1})
/*
			$(el).siblings().animate({ 'height': '31px'}, function() {
				//if level-2 open
				$('.accordionSelect').removeClass('open');
				$(this).removeClass('accordionOpened');
				$(this).addClass('accordionClosed');
			});
*/
			return false;
		}
			// Closes the accordion on click on the openlink
		if ($(el).hasClass('accordionOpened')) {
			var toCloseElement = $(el)
			toCloseElement.removeClass('accordionOpened');
			toCloseElement.addClass('accordionClosed');
			var toCloseHeadlineHeight = toCloseElement.find('.accordionHeadline').height()
			$('.accordionSelect').removeClass('open');
			toCloseElement.animate({ 'height': toCloseHeadlineHeight + 1})
		}
		return false;
	});
		
	/**
	 * manages the hover function over parts of an image of a campaign with image-map
	 * also shows and hides the corresponding buttons
	 */
	$('.imageWrap map area').hover(function(evt) {
		var previousElement = $(evt.relatedTarget);
		if (!previousElement.hasClass('button') && previousElement.parents('.button').length === 0) {
			var showImg = $(this).data("mapnumber");
			$('.hoverImages').show().children().hide();
			//in that case fadeIn is not working with ie, maybe z-index problem in ie
			if (isIE7 || isIE8) {
				$('.buttonForMapNumber-' + showImg).css({'display': 'block'});
				$('.mapnumber-' + showImg).css({'display': 'block'});
			} else {
				$('.buttonForMapNumber-' + showImg).fadeIn(durations.imageMapHover);
				$('.mapnumber-' + showImg).fadeIn(durations.imageMapHover);
			}
		}
	}, function(evt) {
			// element that is being entered, if it's the button itself, 
			// don't fade out the map
		var nextElement = $(evt.relatedTarget);
		if (!nextElement.hasClass('button') && nextElement.parents('.button').length === 0) {
			var showImg = $(this).data("mapnumber");
			//in that case fadeOut is not working with ie, maybe z-index problem in ie
			if (isIE7 || isIE8) {
				$('.buttonForMapNumber-' + showImg).css({'display': 'none'});
				$('.mapnumber-' + showImg).css({'display': 'none'});
			} else {
				$('.buttonForMapNumber-' + showImg).fadeOut(durations.imageMapHoverOut);
				$('.hoverImages').fadeOut(durations.imageMapHoverOut);
			}
			$('.hoverImages').children().hide();
		}
	});
	
	$('.campaignViewWithMap .button').mouseleave(function(evt) {
			// element that is being entered, if it is not the map,
			// fade out the map
		var nextElement = evt.relatedTarget;
		if (nextElement.nodeName !== "AREA") {
			var showImg = $(this).data("mapnumber");
			$('.buttonForMapNumber-' + showImg).fadeOut(durations.imageMapHover);
			$('.hoverImages').fadeOut(durations.imageMapHover);
			$('.hoverImages').children().hide();
		}
	});


	
	b_initButtonHover();

	/**
	 * adds a hover-effect to the Headline-CTA on Startpage and Product-Range-View
	 */
	$('.CTAHeadline a').hover(function() {
		if (!$(this).hasClass('noHover')) {
			$(this).find('div').stop(true, true).css({opacity: '0.9', backgroundColor: '#444'}).animate({opacity: '1', backgroundColor: '#666'}, durations.buttonHover);
		}
	}, function() {
		if (!$(this).hasClass('noHover')) {
			$(this).find('div').stop(true, true).css({opacity: '1', backgroundColor: '#666'}).animate({opacity: '0.9', backgroundColor: '#444'}, durations.buttonHover);
		}
	});
/*
	$('.CTAHeadlinePink a').hover(function() {
		$(this).find('div').stop(true, true).css({opacity: '0.9', backgroundColor: '#f69'}).animate({opacity: '1', backgroundColor: '#f69'}, durations.buttonHover);
	}, function() {
		$(this).find('div').stop(true, true).css({opacity: '1', backgroundColor: '#f69'}).animate({opacity: '0.9', backgroundColor: '#f69'}, durations.buttonHover);
	});
*/


		// hover for shopping-card
	$('.mainMenuSection-1 a').hover(function() {
		$('.mainMenuBackgroundHover').fadeIn(durations.hoverMainMenu);
	}, function() {
		$('.mainMenuBackgroundHover').fadeOut(durations.hoverMainMenu);
	});
	
	
		//hover for the colorswitch
	$('.colorSwitch').hover(function(evt) {	
		evt.stopPropagation();
		var defaultColor = $(this).data('bgColor');
		var defaultColorFont = $(this).children().data('color');
		if ($(this).parent().hasClass('hover-fff')) {
			//hover to white
			$(this).stop(true, true).css({backgroundColor: defaultColor }).animate({backgroundColor: '#333'}, durations.buttonHover);
			$(this).stop(true, true).children().css({color: defaultColorFont }).animate({color: '#fff'}, durations.buttonHover);
		} else {
			if ($(this).hasClass('colorSwitch-d5d5d5')) {
				$(this).stop(true, true).children().css({color: defaultColorFont }).animate({color: '#000'}, durations.buttonHover);
				$(this).stop(true, true).css({backgroundColor: defaultColor }).animate({backgroundColor: '#d5d5d5'}, durations.buttonHover);
			} else{
				$(this).stop(true, true).css({backgroundColor: defaultColor }).animate({backgroundColor: '#333'}, durations.buttonHover);
			}
		}
	}, function() {
		var defaultColor = $(this).data('bgColor');
		var defaultColorFont = $(this).children().data('color');
		if ($(this).parent().hasClass('hover-fff')) {
			$(this).css({backgroundColor: '#333'}).animate({backgroundColor: defaultColor }, durations.buttonHover);
			$(this).children().css({color: '#fff' }).animate({color: defaultColorFont}, durations.buttonHover);
		} else {
			if ($(this).hasClass('colorSwitch-d5d5d5')) {
				$(this).children().css({color: '#000' }).animate({color: defaultColorFont}, durations.buttonHover);
				$(this).stop(true, true).css({backgroundColor: '#d5d5d5' }).animate({backgroundColor: defaultColor}, durations.buttonHover);
			} else{
				$(this).css({backgroundColor: '#333'}).animate({backgroundColor: defaultColor }, durations.buttonHover);
			}
		}
	});
	
	
	/*
	 * hover campaignTeaser
	 * manages the hover function for the button "see more/jetzt Ansehen"
	*/
		// add display:none to the button (inline-style) important for the first time when you enter the img
	if ($('.campaignViewWithMap').length === 0  &&  $('.campaignTeaser').length > 0 && $('map').length > 0) {
		$('.imageInnerWrap .buttonAbsolute').css({'display': 'none'});
		
		$('.campaignTeaser').hover(function(evt) {
			var previousElement = $(evt.relatedTarget);
			if (!previousElement.hasClass('button') && previousElement.parents('.button').length === 0) {
				$(this).parent().next().stop(true, true).fadeIn(durations.campaignFadeInOutButton);
			}
		}, function(evt) {
			// element that is being entered, if it's the button itself, 
			// don't fade out the button
			var nextElement = evt.relatedTarget;
			if (nextElement.nodeName !== "A") {
				$(this).parent().next().stop(true, true).fadeOut(durations.campaignFadeInOutButton);
			}
		});
	}
	
	if ($('.campaignView').length > 0 && $('.campaignViewWithMap').length === 0 ) {
		$('.imageInnerWrap').hover( function() {
				$('.buttonAbsolute').fadeIn(durations.campaignFadeInOutButton);
		},
		function(){
			$('.buttonAbsolute').fadeOut(durations.campaignFadeInOutButton);
		});
	}
	
		// pv detail layer open/close
		// lochstampfer: excluded in a nuew funtion for triggering layeropen with external javascript (oxid)
/*
	$('.layerLink').click(function() {
		var el = $(this).attr('rel');
		var layerNr = el.split('-');
		
		$('body').addClass(el);
		$('.overlay, #layer-' + layerNr[1]).fadeIn(durations.fadeInLayerPvDetail);
		
		var belowHeight = $('body').height() - $('#layer-' + layerNr[1] + ' .layerContent').height() - 118; 
		$('#layer-' + layerNr[1] + ' .layerBelow').height(belowHeight);
		
			//show the close button
		$('.layerClose').delay(200).fadeIn('slow');

	});
*/
	
	
	
	$('.layerLink').click(function(evt) {
		evt.preventDefault();
		b_openLayer($(this).attr('rel'));
		if (isIE7 || isIE8) { $('.pvMainImg object').hide() }

	});

	$('.close').click(function() {
		var nr = ($('body').attr('class').split('layerOpen-'));
		var currentNr = "layerOpen-" + nr[1];
		$('.layer, .overlay').fadeOut(durations.fadeInLayerPvDetail, function() {
			// wait until the fadeOut is ready, don't know why window.setTimeout is necessary but without it's not working right
			window.setTimeout(function() {
				$('body').removeClass(currentNr);
			}, durations.fadeInLayerPvDetail);
		});
			// show the close button
		$('.layerClose').fadeOut();
		$('.pvMainImg object').show()
	});	
	
	
	// zoomView animation for a single image
	$('.imageZoomLink, .zoomIcon ').click(function(evt) {
		evt.preventDefault();
		$('.imageZoomLink').children().stop(true, true);
		
		$('.pvMainImg object').hide()
		
		el = $(this);
		if ($(el).hasClass('zoomIcon')) {
			el = $(el).parents('.imageZoom').find('.imageZoomLink');
		}
		
			// make sure that it's not clickable when the layer is open
		if ($(el).hasClass('activ')) {
			$('.close').click();
			return;
		} else {
			$(el).addClass('activ');
		}
		
		$(el).children().css({'position': 'absolute', 'z-index': '600' });
			// Show no overlay in IE7, z-index doesn't work
		if (!isIE7) {
			$('.overlay').fadeIn();
		}
		var newHeight = parseInt(510 / b_getRatio($(el).children()));
		$(el).parent().addClass('layerZoomed');
		var offset = $(el).children().offset();

		/** 
		 * start the animation. we need to animate the resizing and repositioning in one combined animation
		 */

			// move the image to the top 
		var moveToTop = 0;
		if (offset.top > 27) {
			moveToTop = parseInt(offset.top - 27);
		}

		var moveToLeft;
			//move the image to the right
		if (parseInt($(window).width()) > 1254) {
			moveToLeft = offset.left - 340 -201;
		} else {
			if ( offset.left < 885) {
				moveToLeft = parseInt(offset.left - 201);
			}
		}
		
		//doing the animation of the img
		$(el).children().stop(true, true).animate({'width':'510', 'height': newHeight, 'left': '-' + moveToLeft, 'top': '-' + moveToTop}, 500, function() { 
			//get src to the big img from the href in the warp a img
			var bigImgSrc = $(el).prop('href');
			$(el).children().before('<img src="'+ bigImgSrc +'" width="510" height="'+ newHeight +'" class="bigImg" style="position: absolute; z-index: 601; display: none; left: '+ -1*moveToLeft +'px; top: '+ -1*moveToTop +'px; " >');
			//if the animation is done, fade in the big img over the curren img
			$('img.bigImg').load(function() {
				$(this).fadeIn('slow');
			});
		}); 

		/*
$(el).children().stop(true, true).animate({'width':'510', 'height': newHeight, 'left': '-' + moveToLeft, 'top': '-' + moveToTop}, 500, function() { 
			//if the animation is done, clone the image. we load the big img-verson  of the im in the clone
			$(el).children().clone().insertBefore($(this)).hide().addClass('bigImg').css('z-index', 601);
			var imgSrc = $('.bigImg').attr('src').split('.');
			imgSrc = imgSrc[0].substr(0, imgSrc[0].length - 4) + "z01." + imgSrc[1];
			$('img.bigImg').error(function() {
					//if the img src doesen't exist remove the div
				$('img.bigImg').remove();
			}).attr('src', imgSrc);
			$('img.bigImg').load(function() {
					$(this).fadeIn('slow');
			});
		}); 
*/

			//show the close button
		$('.layerClose').delay(200).fadeIn('slow');
	});

		// Close an open layer
	$('.close').click(function() {
		//delete the big Img
		$('img.bigImg').remove();
		//if a image is zoomed close it
		if ($('.layerZoomed').length > 0) {
			var el = $('.layerZoomed a img');
			var crtH = $(el).attr('height');
			var crtW = $(el).attr('width');
			var offset = $(el).offset();
				// if the image is on the right side of the page
			if ( offset.left < 880) {
				$(el).animate({'height': crtH, 'width': crtW, 'top': 0, 'left': 0}, 500, function() {
					$(el).attr('style', '').parent().parent().removeClass('layerZoomed');
					$('.imageZoom a.activ').removeClass('activ');
				});
			} else {
					// if the image is on the left side of the page
				$(el).animate({'height': crtH, 'width': crtW, 'top': 0, 'right': 0}, 500, function() {
					$(el).attr('style', '').parent().parent().removeClass('layerZoomed');
					$('.imageZoom a.activ').removeClass('activ');
				});
			}
		} else {
				// close the normal layerlinks
			var nr = ($('body').attr('class').split('layerOpen-'));
			var currentNr = "layerOpen-" + nr[1];
			$('.layer, .overlay').fadeOut(durations.fadeInLayerPvDetail);
			$('body').removeClass(currentNr);
			$('.layerZoomed a').children().animate({width:'-=100%', height:'-=100%'}, 500);
		}
		$('.layerClose').fadeOut();
		$('.pvMainImg object').show()
		
	});
	
	
	// close a layer with clicking out of the layerbox
	$('.overlay, .layerZoomed img').click(function() {
		$('.close').click();
	});
	
	
	var colorFadeForLinks = $('.jqTransformSelectWrapper div span, a');
	
		// get the current color of each menu list item and save it
	colorFadeForLinks.each(function() {
		$(this).data('color', $(this).css("color")); 
	});
	
		// hover mainMenu
		// if your A tag has class noHover the will be no color animation, this is used at the right column for the "Warenkorb" button
	colorFadeForLinks.mouseenter(function() {
		if (!$(this).is('.noHover') && !$(this).parent().is('.button, .buttonHover, .colorSwitch, .hoverToWhite') && !$(this).parents().is('.hoverToWhite')) {
			$(this).animate({color: "#000"}, durations.hoverMainMenu);
			if ($(this).is('.iconLink')) {
				$(this).find('span').stop(true, true).fadeIn(durations.hoverMainMenu);
			}
		}
	});
	colorFadeForLinks.mouseleave(function() {
		if (!$(this).hasClass('noHover')) {
			$(this).stop(true, true);
			var defaultColor = $(this).data('color');
			$(this).animate({color: defaultColor}, durations.hoverMainMenu);
			if ($(this).is('.iconLink')) {
				$(this).find('span').stop(true, true).fadeOut(durations.hoverMainMenu);
			}
		}
	});
	
	
	$('.hoverToWhite a').hover(function(){
		if (!$(this).is('.noHover') && !$(this).parent().is('.button, .buttonHover, .colorSwitch')) {
			$(this).animate({color: "#ccc"}, durations.hoverMainMenu);
		}
	}, function(){
		var defaultColor = $(this).data('color');
		if (!$(this).is('.noHover') && !$(this).parent().is('.button, .buttonHover, .colorSwitch')) {
			$(this).animate({color: defaultColor}, durations.hoverMainMenu);
		}
	})
	

	//Video JS
	//show/hide Play/Stop controler for pv look
	if ($('.playerControllPV').length > 0) {
		$('.pvMainImg').hover(function() {
			$('.playerControllPV').fadeIn();
		}, function() {
			$('.playerControllPV').fadeOut();
		});
	}
	
	/*
$('.prvWrap').hover(function(evt) {
			var nextElement = evt.relatedTarget;
			alert($(this).attr('class'));
			if (nextElement.nodeName != "VIDEO") {
			console.log(evt.target + " " + evt.relatedTarget);
				//isRandomVideoPlaying = false;
				console.log("stop");
			}
		}, function(evt) {
			var nextElement = evt.relatedTarget;
			alert("out:" + $(this).attr('class'));
			if (nextElement.nodeName != "VIDEO") {
			console.log("leave:" + evt.target + " " + evt.relatedTarget);
				//isRandomVideoPlaying = true;
				console.log("start");
				//b_playRandomVideoAnimation();
			}
		})
*/
	
	//play random video in prv list
	/*
if ($('.prvWrap').length > 0) {
		window.setTimeout(function(){
			b_playRandomVideoAnimation();
		}, 6000);
		
			//remove big play button
		$('.vjs-big-play-button').empty();
		
		var last = Math.round((new Date()).getTime() / 1000), diff;
		$('.video-js-box').hover(function(evt) {
			isRandomVideoPlaying = true;
			diff = evt.timeStamp - last;
			if ( last ) {
				if (diff > 300) {
						//var previousElement = $(evt.relatedTarget);
					var play = $(this).children('video').attr('id');
					b_playVideo(play);
				}
			}
			last = evt.timeStamp;
		}, function(evt) {
			
			evt.delay('300').stopPropagation();
			
			var play = $(this).children('video').attr('id');
			b_stopVideo(play);
			isRandomVideoPlaying = false;
		});
	}
*/
	
	
		// show the drop-Downs with the class .filterItem
	if ($('.filterItem').length > 0) {
		$('.filterItem').hover( function() {
				$(this).find('ul').stop(true,true).slideDown(500);
			},
			function ()
			{
				$(this).find('ul').stop(true,true).slideUp(500);
		});
	}
	

	
		// set the hoverfunction to the social-item in the right Col of the product-detailview
	$('.rightBarSocial').hover ( function() {
			$(this).animate({color: "#000"}, durations.hoverMainMenu);
		},
		function() {
				$(this).animate({color: '#666'}, durations.hoverMainMenu);
	});

	
		// Shows the content (i.e. more form-fields) between the radioboxes, if you check one radiobox
	$('.radioLink').click(function(evt){ 
		evt.preventDefault();
		var radioid = $(this).data('radioid');
		var radioname = $(this).data('radioname');
			// +30 for some space underneath the content
		var innerWrapHeight = $(this).next().find('.radioInnerFormInnerWrap').height() + 30;
		$('input[name="' + radioname + '"]').removeAttr('checked');
		$('#' + radioid).attr('checked', 'checked');
	
		if ($(this).parents('.radioWrapChecked').length === 0) {
			$(this).parents('.radioWithContent').find('.radioWrapChecked .radioInnerForm').animate({height: 0}, 'slow', function() {
					b_calcAllHeights();
			});
			$(this).next('.radioInnerForm').animate({height: innerWrapHeight}, 'slow', function() {
				b_calcAllHeights();
			});
			$(this).parents('.radioWrap').siblings().removeClass('radioWrapChecked');
			$(this).parents('.radioWrap').addClass('radioWrapChecked');
		}
	});
	
		// fades in the small info-layers in the forms
	$('.miniLayerWrap').hover(function() {
		$(this).find('.miniLayer').stop(true,true).fadeIn('slow');
		$(this).find('.buttonQuestionmark').stop(true, true).animate({backgroundColor: '#666'}, durations.buttonHover);
	}, function() {
		$(this).find('.miniLayer').stop(true,true).fadeOut('slow');
		$(this).find('.buttonQuestionmark').stop(true, true).animate({backgroundColor: '#999'}, durations.buttonHover);
	});

		// toggles the detail-view-content-visibilty of the help-site
	$('.smallAccordionLink').click( function(evt) {
		evt.preventDefault();
		content = $(this).next('.smallAccordionContent');
		if (content.hasClass('isOpen')) {
			content.stop(true, true).slideUp(500, function(){ b_calcAllHeights() }).removeClass('isOpen').parent().removeClass('open');
		} else {
			$(this).parents('.smallAccordionWrap').find('.isOpen').slideUp(500).removeClass('isOpen').parent().removeClass('open');
			content.slideDown(500, function(){ b_calcAllHeights() }).addClass('isOpen').parent().addClass('open');
		}
		
	});
	
	
		// shows the right accordion-item by using hash of the url
	if ($('.smallAccordionLink').length > 0 ) {
		var destination = window.location.hash;
//alert(destination)
		var content =  $(destination).next('.smallAccordionContent')
		content.slideDown(500, function(){ b_calcAllHeights() }).addClass('isOpen').parent().addClass('open');

	}





		// make the login submit work
	$('.formSubmit').click(function(evt) {
		$(this).parents('form').first().submit();
		evt.preventDefault();
	});

	
		// show the footerLayer
	$('.footerInnerWrap li').hover( function(evt) {
		$(this).find('.footerLayer').stop(true, true).fadeIn(500)
	}, function() {
		$(this).find('.footerLayer').stop(true, true).fadeOut(200)
	});
	
	$('.footerInnerWrap').hover( function(evt) {
		$('#footer').addClass('footerLayerOpen')
	}, function() {
		window.setTimeout(function () {$('#footer').removeClass('footerLayerOpen')}, 300);
	});
	
	
	//:hover .footerLayer { display: block; }

	
		// animate the companySlider
	if ($('.companySlider').length > 0 ) {
		b_initCompanySlider();
	}


		// show the infoLayer by clicking on the label a 
	$('.formRowInfoLayer label a').click(function(evt){
		evt.preventDefault();
		$(this).parents().find('.infoLayer').fadeIn('slow')
		//, function(){
					// makes content scrollable
			$('.scroll-pane').jScrollPane({showArrows:true});
//		})
	})
		// close the infoLayer by clicking on the a
	
	$('.infoLayerClose a').click(function(evt){
		evt.preventDefault();
		$(this).parents('.infoLayer').fadeOut('slow');
	})
	
		// Makes the Videos on the PRV Clickable including Flash-Object.
/*
	$('.prvItem').click(function() {
		window.location = $(this).find('.prvDescriptionLink').attr('href')
	})
*/
	$('.prvItem object').click(function() {
		window.location = $(this).parents('.prevItem').find('.prvDescriptionLink').attr('href')
	})


});
