/**
 * all dhtml for the MBA Shop
 * 
 * @author Oliver Christ
 */
//execute when page has loaded 
jQuery(window)
		.load( 
			function() {
				/**
				 * functionality for header login
								 * 
				 * @author Oliver Christ
				 */
				jQuery('#login_lnk').mouseover(function() {
			        jQuery('#ms-fly-login-box').removeClass("hidden");
			    });
				var flyoutInputfieldFocussed = false;
				jQuery('#ms-fly-login-box').mouseleave(function(evt) {
					if (!flyoutInputfieldFocussed) {
			            jQuery(this).addClass("hidden");
			        }
			    });
				jQuery("#lgn-email, #lgn-password").focus(function() {
					flyoutInputfieldFocussed = true;
				});
				jQuery("#lgn-email, #lgn-password").blur(function() {
					flyoutInputfieldFocussed = false;
				});
				
				/**
				 * functionality for superhome
				 * 
				 * @author Oliver Christ
				 */
				$("#superhome .teaserWide, #superhome .teaserSmall").hover(
						function() {
							$(this).parent().children("a").removeClass(
									"teaserWide").addClass("teaserSmall");
							$(this).addClass("teaserWide").removeClass(
									"teaserSmall");
						});
				
				/**			 
				 * functionality for header
				 * 
				 * @author Oliver Christ
				 */

				// help flyout
				$("#help").mouseenter(function() {
					var left = $(this).position().left + $("#login-contact").position().left - 1;
					$("#helpFlyout").css("left", left + "px");
					$("#helpFlyout").show();
					$(this).addClass('hover');
				}).mouseleave(function() {
					$("#helpFlyout").hide();
					$(this).removeClass('hover');
				});
				$("#helpFlyout").mouseenter(function(){
					$("#helpFlyout").show();
					$("#help").addClass('hover');
				}).mouseleave(function(){
					$("#helpFlyout").hide();
					$("#help").removeClass('hover');
				});
			
				// shop flyout
				$("#shop").hover(function() {
					var left = $(this).position().left;// +
					// $("#mainnav").position().left
					// -
					// 18;
					$("#shopFlyout").css("left", left + "px");
					$("#shopFlyout").show();
				});
					$("#shopFlyout").mouseleave(function() {
					$(this).hide();
				});
			
				// shopping cart flyout
				$("#header .cart").mouseenter(function() {
					$("#cartFlyout").show();
					$(this).addClass("active");
					$("#cartFlyout").css("top", "85px");
				}).mouseleave(function() {
					$("#cartFlyout").hide();
				});
					$("#SearchBar .cart").mouseenter(function() {
					$("#cartFlyout").show();
					$(this).addClass("active");
					$("#cartFlyout").css("top", "119px");
				}).mouseleave(function() {
					$("#cartFlyout").hide();
					$(this).removeClass("active");
				});
				$("#cartFlyout").mouseleave(function() {
					$("#cartFlyout").hide();
					$("#SearchBar .cart").removeClass("active");
				}).mouseenter(function() {
					$("#cartFlyout").show();
					$("#SearchBar .cart").addClass("active");
				});
				
				/**
				 * functionality for telematik home
				 * 
				 * @author Oliver Christ
				 */
				 
				// layer 1
				$("#layer1 .btn1").click(function() {
					$("#layer1").hide();
					$("#layer2").show();
				});
				$("#layer1 .btn2").click(function() {
					$("#layer1").hide();
					$("#layer5").show();
				});
				 
				// layer 2
				$("#layer2 .back").click(function() {
					$("#layer2").hide();
					$("#layer1").show();
				});
				$("#layer2 .btn1").click(function() {
					$("#layer2").hide();
					$("#layer3").show();
				});
				$("#layer2 .btn2").click(function() {
					$("#layer2").hide();
					$("#layer7").show();
				});
				 
				// layer 3
				$("#layer3 .back").click(function() {
					$("#layer3").hide();
					$("#layer2").show();
				});
				$("#layer3 .btn2").click(function() {
					$("#layer3").hide();
					$("#layer4").show();
				});
				 
				// layer 4
				$("#layer4 .back").click(function() {
					$("#layer4").hide();
					$("#layer3").show();
				});
				 
				// layer 5
				$("#layer5 .back").click(function() {
					$("#layer5").hide();
					$("#layer1").show();
				});
				/*
				 * $("#layer5 .btn2").click(function(){ $("#layer5").hide();
				 * $("#layer6").show(); });
				 */
				$("#layer5 #navigation").change(
						function() {
							$("#layer5 .img").css("height", "230px").css(
									"background", "none");
						$("#layer5 .cnt .txt2").show();
						$("#layer5 input").show();
						$("#layer5 .vsAppInfo").show();
						$("#layer5 .cnt img.img1").show();
					});
					 
					// layer 6
					$("#layer6 .back").click(function() {
						$("#layer6").hide();
						$("#layer5").show();
					});
					$("#layer6 .btn2").click(function() {
						$("#layer6").hide();
						$("#layer7").show();
					});
				
					// layer 7
					$("#layer7 .back").click(function() {
						$("#layer7").hide();
						$("#layer2").show();
					});
				
					// colorpicker
					$("#telematikHome .color").click(function() {
						$("#telematikHome .color").removeClass("active");
						$(this).addClass("active");
					});
					
					/**
					 * poduct suggestion
					 * 
					 * @author Oliver Christ
					 *//* -sfresta-3044: being called when last seen products have been loaded
					if ($('.productSuggestion .product').length > 5) {
						$('.productSuggestion .back')
								.click(
										function(event) {
							// prevent href
							event.preventDefault();
											// remove marking of link wenn
											// clicked
							$(this).blur();
											// move last product to first
											// position
											$(
													'.productSuggestion .scroll .product:last-child')
													.prependTo(
															'.productSuggestion .scroll');
							// remove left padding
											$('.productSuggestion .scroll')
													.css('padding-left', '0');
							// animate padding to old value
											$('.productSuggestion .scroll')
													.animate({
														'padding-left' : 175
													}, 500);
										});
						$('.productSuggestion .next')
								.click(
										function(event) {
											// prevent href
											event.preventDefault();
											// remove marking of link wenn
											// clicked
											$(this).blur();
											// animate padding to 0
											$('.productSuggestion .scroll')
													.animate(
															{
																'padding-left' : 0
															},
															500,
															function() {
																// move first
																// product to
																// last position
																$(
																		'.productSuggestion .scroll .product:first-child')
																		.appendTo(
																				'.productSuggestion .scroll');
																// restore left
																// padding
																$(
																		'.productSuggestion .scroll')
																		.css(
																				'padding-left',
																				'175px');
							});
						});
					}*/
				
					/**
					 * article magnifier
					 * 
					 * @author Oliver Christ
					 *//*
					if ($("#article .article").get(0)) {
						if ($("#article #magnifier img").width() == 1000
								&& $("#article #magnifier img").height() == 1000) {

							// var imgPath = $("#article #magnifier
							// img").attr("src");
							// $("#article #magnifier").css("background-image",
							// "url(" + imgPath
							// + ")");

							$("#article #magnifier").hide();
							var frameWidth = 135;
							var frameHeight = 135;
							var articlePos = $('#article .article').position();
							var imgX = articlePos.left;
							var imgY = articlePos.top;
							var websiteX = Math.floor($('#website').position().left);
							$('#article .article .image table')
								.mouseenter(function() {
									$("#magnifierFrame").show();
									$("#magnifier").show();
								})
								.mouseleave(function() {
									$("#magnifierFrame").hide();
									$("#magnifier").hide();
								})
								.mousemove(function(e) {
									var imageWidth = $("#imagetable").width() + 2;
									var imageHeight = $("#imagetable").height() + 2;
									var mouseX = e.pageX - imgX - websiteX;
									var mouseY = e.pageY - imgY;
									var frameX = mouseX - Math.floor(frameWidth / 2);
									var frameY = mouseY - Math.floor(frameHeight / 2);

									frameX = (frameX < 0) ? 0 : frameX;
									frameX = (frameX > (imageWidth - frameWidth)) ? (imageWidth - frameWidth) : frameX;
									frameY = (frameY < 0) ? 0 : frameY;
									frameY = (frameY > (imageHeight - frameHeight)) ? (imageHeight - frameHeight) : frameY;

									$("#magnifierFrame").css( "left", frameX + "px");
									$("#magnifierFrame").css("top", frameY + "px");

									var magnifierX = Math.floor(frameX * imageWidth / frameWidth);
									var magnifierY = Math.floor(frameY * imageHeight / frameHeight);
									// console.log(frameX + ", " +
									// frameY + ", " + magnifierX +
									// ", "
									// + magnifierY + ", " +
									// (imageWidth / frameWidth) +
									// ", " +
									// (imageHeight / frameHeight));
									$("#magnifier").css("background-position","-" + magnifierX + "px -" + magnifierY + "px");
								});

						}
						$("#article #magnifier img").hide();
					}*/
					/**
					 * article magnifier
					 * 
					 * @author sfresta -- includes changes for enfinity site
				 	 */
					if ($("#article .article").get(0)) {
						//var imgPath = $("#article #magnifier img").attr("src");
						//$("#article #magnifier").css("background-image", "url(" + imgPath + ")");
			
						// var imgPath = $("#article #magnifier
						// img").attr("src");
						// $("#article #magnifier").css("background-image",
						// "url(" + imgPath
						// + ")");
			
						$("#magnifier").hide();
						$("#article #magnifier").hide();
						var frameWidth = 135;
						var frameHeight = 135;
						var articlePos = $('#article .article').position();
						var imgX = articlePos.left;
						var imgY = articlePos.top;
						var websiteX = Math.floor($('#website').position().left);
						$('#article .article .image table').mouseenter(function(){
							var imgSize = getImgRealSize("#mainimage");
							if(imgSize.width >= 1000 || imgSize.height >= 1000){
								$("#magnifierFrame").show();
								$("#magnifier").show();
							}
						}).mouseleave(function(){
							$("#magnifierFrame").hide();
							$("#magnifier").hide();
						}).mousemove(
							function(e){
							var imgSize = getImgRealSize("#mainimage");
							if(imgSize.width >= 1000 || imgSize.height >= 1000){
								$("#magnifierFrame").show();
								$("#magnifier").show();
								var imageWidth = $("#imagetable").width() + 2;
								var imageHeight = $("#imagetable").height() + 2;
								var mouseX = e.pageX - imgX - websiteX;
								var mouseY = e.pageY - imgY;
								var frameX = mouseX - Math.floor(frameWidth / 2);
								var frameY = mouseY - Math.floor(frameHeight / 2);

								frameX = (frameX < 0) ? 0 : frameX;
								frameX = (frameX > (imageWidth - frameWidth)) ? (imageWidth - frameWidth) : frameX;
								frameY = (frameY < 0) ? 0 : frameY;
								frameY = (frameY > (imageHeight - frameHeight)) ? (imageHeight - frameHeight) : frameY;
					
								$("#magnifierFrame").css( "left", frameX + "px");
								$("#magnifierFrame").css("top", frameY + "px");
								
								var magnifierX = Math.floor(frameX * imageWidth / frameWidth);
								var magnifierY = Math.floor(frameY * imageHeight / frameHeight);
								// console.log(frameX + ", " +
								// frameY + ", " + magnifierX +
								// ", "
								// + magnifierY + ", " +
								// (imageWidth / frameWidth) +
								// ", " +
								// (imageHeight / frameHeight));
								$("#magnifier").css("background-position","-" + magnifierX + "px -" + magnifierY + "px");
							} else {
								$("#magnifierFrame").hide();
								$("#magnifier").hide();
							}
						});
						
						$("#article #magnifier img").hide();
					}
				
					/**
					 * article tooltips
					 * 
					 * @author Oliver Christ
					 */
					$('#article .maintenance a').hover(function() {
						obj = $(this).parent().children('.tooltip:eq(' + ($(this).index() / 2) + ')');
						offsetX = Math.floor((21 - $(this).width()) / 2);
						offsetY = -20;
						posX = $(this).position().left - offsetX - 130;
						posY = obj.height();
						obj.css("left", posX + "px");
						obj.css("top", offsetY - posY + "px");
						obj.toggle();
					});
					/**
					 * article color and sizes tooltips
					 * 
					 * @author Oliver Christ
					 */
					$('#article .colors a, #article .sizes a').hover(function() {
						$("#tooltip").css("width", "auto");
						var txt = $(this).attr("title");
						$("#tooltip .txt").text(txt);
						var x = Math.ceil($(this).position().left - $("#tooltip").width() / 2 + 5);
						var y = Math.ceil($(this).position().top - $("#tooltip").height() - 22);
						$("#tooltip").css("top", y + "px");
						$("#tooltip").css("left", x + "px");
						$("#tooltip").css("width", $("#tooltip").width() + "px");
						$("#tooltip").toggle();
					});
					/**
					 * article sizes layer
					 * 
					 * @author Oliver Christ
					 */
					$("#article .article .txtLnk").click(function() {
						$("#layerSizes").show();
					});
					$("#layerSizes .close").click(function() {
						$("#layerSizes").hide();
					});
					/**
					 * New Js for Fullscreen Template
					 * 
					 * @author Marcel Ploch
					 */
					/**
					 * Delegation of Elements in View Div
					 */
					$(".view").delegate('a', 'mouseenter', function() {
						$(this).css({
							'position' : 'relative',
							'top' : '-25px'
						});
						$(this).children().css({
							'width' : '50px',
							'height' : '50px'
						});
					});
				
					$(".view").delegate('a', 'mouseleave', function() {
						$(this).css({
							'position' : 'relative',
							'top' : '0px'
						});
						$(this).children().css({
							'width' : '25px',
							'height' : '25px'
						});
					});
				
					/**
					 * Delegation of Elements in Color Div
					 */
					$(".color").delegate('a', 'mouseenter', function() {
						$(this).css({
							'width' : '35px',
							'height' : '20px',
							'position' : 'relative',
							'top' : '-2px'
						});
					});
					$(".color").delegate('a', 'mouseleave', function() {
						$(this).css({
							'width' : '30px',
							'height' : '15px',
							'position' : 'relative',
							'top' : '0px'
						});
					});
				
					var sliderButtonValue = 20;
				
					/**
					 * Onclick Event f�r alle Bilder in der Galerie
					 * 
					 */
					$(".product").delegate(
							'img',
							'click',
							function() {
								var sliderValue = $("#slider").slider("value");
								if (sliderValue < 100) {
									$("#slider").slider("value",
											(sliderValue + sliderButtonValue));
								} else {
									$("#slider").slider("value", 1);
								}
							});
				
					$(".slider #left").click(
							function() {
								var sliderValue = $("#slider").slider("value");
								if (sliderValue > 1) {
									$("#slider").slider("value",
											(sliderValue - sliderButtonValue));
								} else {
									$("#slider").slider("value", 100);
								}
							});
				
					$(".slider #right").click(
							function() {
								var sliderValue = $("#slider").slider("value");
								if (sliderValue < 100) {
									$("#slider").slider("value",
											(sliderValue + sliderButtonValue));
								} else {
									$("#slider").slider("value", 1);
								}
							});
				
					/**
					 * Zooming with gzoom
					 */
					if($('#articleCinema').get(0)){
    					var colorsOnPage = $('.color a');
    					var imagesOnPage = $('.images');
    					var thumbnailsOnPage = $('.view img');
    					var currentPosition = 0;
				
    					changeImageAndZoom(imagesOnPage[currentPosition], true);
				
    					if (imagesOnPage.length == 0) {
    						$('.slider').css('border', 'none');
    						$('.slider').remove();
    						$('#imageRotateLeft').remove();
    						$('#imageRotateRight').remove();
    					}
				
    					if (colorsOnPage.length == 0) {
    						$('.color').css('border', 'none');
    						$('.slider').css('border', 'none');
    						$('.color').children().remove();
    						$('.view').css('border-right','none');
    					}
				
    					if (thumbnailsOnPage.length == 0) {
    						$('.view').css('border', 'none');
    						$('.color').css('border-left', 'none');
    						$('.misc').css('border', 'none');
    						$('.view').children().remove();
    					}
				
    					$('#imageRotateLeft')
    							.click(
    									function() {
    										$(".view a").attr('class','');
    										var currentAvailabeImages = imagesOnPage.children('#'+$('.color .active').attr('title'));
    										var current  = currentAvailabeImages.children().clone();
    										currentPosition--;
    										if (currentPosition < 0) {
    											currentPosition = current.length - 1;
    										} else if (currentPosition >= (current.length - 1)) {
    											currentPosition = 0;
    										}
    										$('.view #'+current[currentPosition].id).parent().attr('class','active');
    										changeImageAndZoom(
    												current[currentPosition],
    												false);
    									});
				
    					$('#imageRotateRight')
    							.click(
    									function() {
    										$(".view a").attr('class','');
    										var currentAvailabeImages = imagesOnPage.children('#'+$('.color .active').attr('title'));
    										var current  = currentAvailabeImages.children().clone();
    										currentPosition++;
    										if (currentPosition < 0) {
    											currentPosition = current.length - 1;
    										} else if (currentPosition > (current.length - 1)) {
    											currentPosition = 0;
    										}
    										$('.view #'+current[currentPosition].id).parent().attr('class','active');
    										changeImageAndZoom(
    												current[currentPosition],
    												false);
    									});
    				}
				
					/**
					 * 
					 */
					function changeImageAndZoom(image, first) {
						if (!first) {
							$('#articleCinema .product').children().remove();
							$('#articleCinema .product').append(image);
						}
						$('#articleCinema .product').tzoom(
								{
									slider : '#slider',
									imageSrc : $("#articleCinema .product img")
											.attr('src'),
									scaleUp : true
								});
						jQuery('.ui-slider-handle').append('<img src="images/cinema/schieber2.png" class="sliderSchieber"/>');
					}
				
					$(".view").delegate('img', 'click', function() {
						$(".view a").attr('class','');
						$(this).parent('a').attr('class','active');
						var currentAvailabeImages = imagesOnPage.children('#'+$('.color .active').attr('title'));
						var current  = currentAvailabeImages.children().clone();
//						console.log(current);
						changeImageAndZoom(current[this.id-1],false);
					});
				
					$(".color").delegate('a', 'click', function() {
						$(".color a").attr('class','');
						$(this).attr('class','active');
						var currentAvailabeImages = imagesOnPage.children('#'+$('.color .active').attr('title'));
						var current  = currentAvailabeImages.children().clone();
						/**
						 * 
						 */
						current.each(function(index,Element){
							var parentElement = $(".view #"+(index+1)).parent();
//							console.log(parentElement);
							$(".view #"+(index+1)).remove();
							current[index].id = index+1;
							$(parentElement).append($(current[index]).clone().attr('class','productDetailThumbnail'));
						});
						changeImageAndZoom(current[0],false);
					});
					
					/**
					 * article fullsize link
					 * 
					 * @author Oliver Christ
					 *//*
					$("#article .fullscreen").click(function() {
						$("#article #articleCinema").show();
					});
					$("#article .modalContent .buttonClose").click(function() {
						$("#article #articleCinema").hide();
					});*/
					$("#article .fullscreen").click(function(){
						$("#article .modalWrapper").show();
					});
					$("#article .modalContent .buttonClose").click(function(){
						$("#article .modalWrapper").hide();
					});
				
					/**
					 * shopping cart change article
					 * 
					 * @author Oliver Christ
					 */
					/*
					 * $("#shoppingcart .productTable
					 * .changeArticle").click(function(){
					 * $("#layerChangeArticle").show(); });
					 * $("#layerChangeArticle .close").click(function(){
					 * $("#layerChangeArticle").hide(); });
					 */
					/**
					 * filter functionality
					 * 
					 * @author Oliver Christ
					 */
					$("#artikleFilter select").change(
							function() {
						var val = $("option:selected", this).text();
								$(this).parent("div")
										.children(".selectedValue").text(val)
										.css("display", "block");
						$(this).hide();
					});
					$("#artikleFilter .reset")
							.click(
									function(e) {
										e.preventDefault();
										$(this).parent("div").children(
												".selectedValue").hide();
										$(this).parent("div")
												.children("select").show();
										$(this).parent("div")
												.children("select")[0].selectedIndex = 0;
				
					});
					
					/**
					* payment form handling
					* 
					* @author Oliver Christ
					*/
					$("#payment .methods>input").click(function() {
						$("#payment .box").hide();
						$(this).next().next().show();
					});
					
					/**
					* landing page image slider
					* 
					* @author Oliver Christ
					*/
					$("#landingpage .productKeyvisual .slide a:nth-child(1)").show(); //sf: modified to support links
					$("#landingpage .slider a").click(function(e) {
						e.preventDefault();
						window.clearInterval(landingpageIntervalObj);
						landingSlide($(this));
						landingpageIntervalObj = window.setInterval("landingSlide(null)", 6000);
					});
					if ($("#landingpage .productKeyvisual .slide").get(0)) {
						$("#landingpage .productKeyvisual .slide").css('height',$("#landingpage .productKeyvisual .slide img:first-child").height() + 'px');
						var landingpageIntervalObj = window.setInterval("landingSlide(null)", 6000);
					}
				
					/**
					* height adaption for product resultlist
				 	* 
					* @author Oliver Christ
					*/
					var productCount = 0;
					var productObj = new Array();
					var productImageHeight = new Array();
					var productInfoHeight = new Array();
					var productAddHeight = new Array();
					var productLength = $('#searchresult .result .product').length;
					$('#searchresult .result .product')
					.each(
							function() {
								// get values of product and save in
								// array for later usage
								productObj[productCount] = this;
								productImageHeight[productCount] = $('.image', this).height();
								productInfoHeight[productCount] = $('.info', this).height();
								productAddHeight[productCount] = $('.add', this).height();
								//console.log(productCount + ', ' + productCount%4 + ', ' + productImageHeight[productCount] + ',  ' +  productInfoHeight[productCount] + ', ' + productAddHeight[productCount]);
								// row finished or elements of last row
								if (productCount % 4 == 3 || productCount == productLength - 1) {
								    // alle auf 0 setzen, falls undefined
                                    if(!productImageHeight[productCount-3]) productImageHeight[productCount-3] = 0;
                                    if(!productImageHeight[productCount-2]) productImageHeight[productCount-2] = 0;
                                    if(!productImageHeight[productCount-1]) productImageHeight[productCount-1] = 0;
                                    if(!productImageHeight[productCount]) productImageHeight[productCount] = 0;
                                    if(!productInfoHeight[productCount-3]) productInfoHeight[productCount-3] = 0;
                                    if(!productInfoHeight[productCount-2]) productInfoHeight[productCount-2] = 0;
                                    if(!productInfoHeight[productCount-1]) productInfoHeight[productCount-1] = 0;
                                    if(!productInfoHeight[productCount]) productInfoHeight[productCount] = 0;
                                    if(!productAddHeight[productCount-3]) productAddHeight[productCount-3] = 0;
                                    if(!productAddHeight[productCount-2]) productAddHeight[productCount-2] = 0;
                                    if(!productAddHeight[productCount-1]) productAddHeight[productCount-1] = 0;
                                    if(!productAddHeight[productCount]) productAddHeight[productCount] = 0;
									/*
									console.log('---------------------------------------------------------');
									console.log(
									Math.max(productImageHeight[productCount-3],productImageHeight[productCount-2],productImageHeight[productCount-1],productImageHeight[productCount]) + ', ' +
									Math.max(productInfoHeight[productCount-3],productInfoHeight[productCount-2],productInfoHeight[productCount-1],productInfoHeight[productCount]) + ', ' +
									Math.max(productAddHeight[productCount-3],productAddHeight[productCount-2],productAddHeight[productCount-1],productAddHeight[productCount]) );
									console.log('---------------------------------------------------------');
									*/
									// set max height for all products
									// in row
									for ( var i = 0; i <= productCount % 4; i++) {
										$('.image td',productObj[productCount - i]).css('height',
											Math.max(
												productImageHeight[productCount - 3],
												productImageHeight[productCount - 2],
												productImageHeight[productCount - 1],
												productImageHeight[productCount])
												+ 'px');
										$('.info',productObj[productCount - i]).css('height',
											Math.max(
												productInfoHeight[productCount - 3],
												productInfoHeight[productCount - 2],
												productInfoHeight[productCount - 1],
												productInfoHeight[productCount])
											+ 'px');
										$('.add',productObj[productCount - i]).css('height',
											Math.max(
												productAddHeight[productCount - 3],
												productAddHeight[productCount - 2],
												productAddHeight[productCount - 1],
												productAddHeight[productCount])
											+ 'px');
									}
									// last element with next link
									$('.next', productObj[productCount]).css('height',$(productObj[productCount - 1]).height() + 'px');
									
											// reset for last row with less than
											// 4 products
											productObj[productCount - i] = 0;
											productImageHeight[productCount - 3] = 0;
											productImageHeight[productCount - 2] = 0;
											productImageHeight[productCount - 1] = 0;
											productImageHeight[productCount] = 0;
											productObj[productCount - i] = 0;
											productInfoHeight[productCount - 3] = 0;
											productInfoHeight[productCount - 2] = 0;
											productInfoHeight[productCount - 1] = 0;
											productInfoHeight[productCount] = 0;
											productObj[productCount - i] = 0;
											productAddHeight[productCount - 3] = 0;
											productAddHeight[productCount - 2] = 0;
											productAddHeight[productCount - 1] = 0;
											productAddHeight[productCount] = 0;
										}
										productCount++;
									});
				
					/**
					 * height adaption for last seen products
					 * 
					 * @author Oliver Christ
					 *//* sfresta - lastseenproducts are displayed using ajax thus this script does not work
					var productCount = 0;
					var productObj = new Array();
					var productHeight = new Array();
					var productLength = $('#lastSeenProducts .lastSeenProductTile').length;
					$('#lastSeenProducts .lastSeenProductTile')
							.each(
									function() {
										// get values of product and save in
										// array for later usage
										productObj[productCount] = this;
										productHeight[productCount] = $(this)
												.height();
										// console.log(productCount + ', ' +
										// productCount%3 + ', ' +
										// productHeight[productCount]);
										// row finished or elements of last row
										if (productCount % 3 == 2
												|| productCount == productLength - 1) {
											// set max height for all products
											// in row
											for ( var i = 0; i <= productCount % 3; i++) {
												$(productObj[productCount - i])
														.css(
																'height',
																Math
																		.max(
																				productHeight[productCount - 2],
																				productHeight[productCount - 1],
																				productHeight[productCount])
																		+ 'px');
											}
											// reset for last row with less than
											// 4 products
											productObj[productCount - i] = 0;
											productHeight[productCount - 2] = 0;
											productHeight[productCount - 1] = 0;
											productHeight[productCount] = 0;
										}
										productCount++;
									});*/
						
					/**
					 * iPad footer fix
					 * 
					 * @author Oliver Christ
					 */
					var isiPad = navigator.userAgent.match(/iPad/i) != null;
					if (isiPad) {
						$('#footer').css('position', 'relative');
					}
				});
				
/**
 * fucction for landing page image slider
 * 
 * @author Oliver Christ
 */
function landingSlide(obj) {
	var imgNumber;
	var imgCount;
	if (obj == null) {
		imgNumber = $("#landingpage .slider a.active").index() + 2;
		imgCount = $("#landingpage .slider a").length;
		if (imgNumber > imgCount) {
			imgNumber = 1;
		}
		obj = $("#landingpage .productKeyvisual .slider a:nth-child(" + imgNumber + ")");
	}
	$("#landingpage .slider a").removeClass("active");
	obj.addClass("active");
	imgNumber = obj.index() + 1;
	$("#landingpage .slide a").fadeOut(2000);	 												//sf: modified to support links
	$("#landingpage .productKeyvisual .slide a:nth-child(" + imgNumber + ")").fadeIn(2000);		//sf: modified to support links
};

/**
* Returns a real size of an image
* @author sfresta
*/
function getImgRealSize(selector) {
	imgsrc = $(selector).attr('src');
	$("#website").append('<img src="' + imgsrc + '" id="realimagesize" style="display:none">');
	var w = $("#realimagesize").width(); var h = $("#realimagesize").height();
	$("#realimagesize").remove();
	return {
		'width':w,
		'height':h
	}
}

/**
* height adaption for last seen products
* @author Oliver Christ
*/
function fixHeightlastSeenProduct(selector, cols) {
	var cellCount = $(selector).length;
	var rows = Math.ceil(cellCount / cols);
	var cells = new Array();
	var rowHeights = new Array();
	var cnt = 0;
	$(selector).each(function(){
		cells[cnt] = this;
		cnt++;
	});
	cnt = 0;
	for (var r=0; r<rows; r++) {
		var maxH = 0;
		for (var c=r*cols;c<(r+1)*cols; c++) {
			if ($(cells[c]).height() > maxH) maxH = $(cells[c]).height()
		}
		rowHeights[cnt] = maxH;
		cnt++;
	}
	for (var obj=0; obj<cellCount; obj++) {
		var r = Math.ceil((obj+1)/cols)-1;
		$(cells[obj]).css('height', rowHeights[r]);
		$(cells[obj]).find(".lastSeenProductCheckBoxDiv").css('padding-top', Math.floor(rowHeights[r]/2)-10);
	}
	
	/*
	var productCount = 0;
	var productObj = new Array();
	var productHeight = new Array();
	var productLength = $('#lastSeenProducts .lastSeenProductTile').length;
	$('#lastSeenProducts .lastSeenProductTile').each(function(){
		//get values of product and save in array for later usage
		productObj[productCount] = this;
		productHeight[productCount] = $(this).height();
		//console.log(productCount + ', ' + productCount%3 + ', ' + productHeight[productCount]);
		//row finished or elements of last row
		if(productCount%cols == 2 || productCount == productLength-1){
			//set max height for all products in row
			for(var i=0; i<=productCount%cols; i++){
				$(productObj[productCount-i]).css('height',Math.max(productHeight[productCount-2],productHeight[productCount-1],productHeight[productCount]) + 'px');
			}
			//reset for last row with less than 4 products
			productObj[productCount-i]=0;productHeight[productCount-2]=0;productHeight[productCount-1]=0;productHeight[productCount]=0;
		}
		productCount++;
	});
	*/
}

