jQuery(function($) {
	// resize content window according to screen size
	onResizeWindow();
	onResizeWindow();
   
	$(window).resize( function() {
		onResizeWindow();
		onResizeWindow();		
	});
	
   
	// --------------------------------------------------------------------------------	
   // google map link
	// --------------------------------------------------------------------------------
	//$('li.googleMapLink a').click( function(e) {
		$('li.googleMapLink a').each( function() {
			$(this).attr('href', $(this).attr('href')+'&height=400&width=400&KeepThis=true&TB_iframe=true').addClass('thickbox');
		});
	//});
	
	// --------------------------------------------------------------------------------	
   // effects: navigation
	// --------------------------------------------------------------------------------
		$('#navi ul.sf-menu > li.sfHover > ul').css('width', '900px');
		$('#navi > ul > li').each( function() {
			if( $(this).find('ul').length < 1 ) {
				$(this).append('<ul><li></li></ul>');
			}
		});
		$("ul.sf-menu").superfish({
			pathClass:  'current',
			autoArrows: false,
			dropShadows: false,
			speed:0,
			delay:400,
			onBeforeShow: function() {
				if( $(this).find('li').length > 0 ) {
					if( $(this).parent().next().length < 1 ) {
						$(this).parent().css({'width':'150px', 'height':'11px'});
					}
					$(this).parent('div#navi > ul.sf-menu > li > ul > li').css({'background-image':'url(fileadmin/tpl_html/img/transparent_bg.png)'});
					$(this).parent('div#navi > ul.sf-menu > li > ul > li').find('a:first').css({'color':'#4D4E50'});
				}
			},
			onHide: function() {
				if( $(this).find('li').length > 0 ) {
					$(this).parent('div#navi > ul.sf-menu > li > ul > li').css({'background-image':'none'});
					$(this).parent('div#navi > ul.sf-menu > li > ul > li').find('a:first').css({'color':'#E0E1E2'});
					$('#navi ul.sf-menu > li.sfHover > ul').css('width', '900px');
				}
			}
		});
		
		// $('#navi ul.sf-menu > li.sfHover > ul > li:last').css({'width':'150px', 'height':'11px'});
		
		/* $('#navi ul.sf-menu > li > ul > li').hover( function() {
			if( $(this).find('ul').length > 0 ) {
				$(this).css({'background-image':'url(fileadmin/tpl_html/img/transparent_bg.png)', 'color':'#4d4e50'});
			}
		}, function() {
			if( $(this).find('ul').length > 0 ) {
				$(this).css({'background-image':'none', 'color':'none'});
			}
		}); */
		/*$('#navi .mainnavi .subnavi li.subitem').hover( function() {
		if( $(this).find('ul').length > 0 ) {
			if( navigator.userAgent.indexOf('MSIE') > 0 ) {
				
			} else {
				$(this).find('a:first').css({'background-image':'url(fileadmin/tpl_html/img/transparent_bg.png)', 'color':'#4d4e50'});
				if( $(this).next().attr('class') != 'subitem' ) {
					$(this).css('width', '167px');
				}
			}
		}
	}, function() {
		if( $(this).find('ul').length > 0 ) {
			if( $(this).find('a:first').hasClass('active') ) {
				$tmpLinkColor = '#4d4e50';
			} else {
				$tmpLinkColor = '#e0e1e2';
			}
			$(this).find('a:first').css({'background-image':'none', 'color':$tmpLinkColor});
		}
	});
	
	//$('#navi .mainnavi .subnavi > li:last > a').css('width', '175px');
	$('#navi .mainnavi .subnavi li.subitem ul:last').css('width', '175px');
	
	//$('#navi .mainnavi .subnavi li.subitem ul').mouseout( function() { $(this).css('display', 'none') });
	
	$().mousemove( function(e) {
		var $layer = $('#navi');
		var layerOffset = $layer.offset();
		if( e.pageX < layerOffset.left || e.pageX > layerOffset.left+$layer.width() ||
		    e.pageY < layerOffset.top || e.pageY > layerOffset.top+$layer.height()+100) {
			$('#navi .mainnavi .item > a').not('[class=active]').css('color', '#e0e1e2');
			$('#navi .mainnavi .item .subnavi').css('display', 'none');
			$('#navi .mainnavi .item > a[class=active]').next().css('display', 'block');
		}
	});
	$('#navi .mainnavi .item > a[class=active]').next().css('display', 'block');
	$('#navi .mainnavi .item').hover( function() {
		$('#navi .mainnavi .item > a').not('[class=active]').css('color', '#e0e1e2');
		$('#navi .mainnavi .item .subnavi').not('[class=active]').css('display', 'none');
		// if( ! $(this).children().is('.active') || ! $(this).find('.subnavi').css('display')=='block') {
			$(this).find('a:first').css('color', '#4d4e50');
			$(this).find('.subnavi').css('display', 'block');
		// }
	}, function() {});*/
	
	// --------------------------------------------------------------------------------
	// set scrollbars
	// --------------------------------------------------------------------------------
	if( ! $('*').is('.templateD1') && ! $('*').is('.templateD1press') ) {
		$('.content').css({'height':'470px', 'padding-right':'0'}).jScrollPane({'scrollbarMargin':'0', 'showArrows':'true'});
		$('.content2text').css({'height':'460px', 'padding-right':'0'}).jScrollPane({'scrollbarMargin':'0', 'showArrows':'true'});
		if( $('*').is('.templateG') || $('*').is('.templateGvv') && ( ! $('*').is('.searchForm') ) ) {
			
		}
		// if(  ) {
			// $('.content3text').css({'height':'470px', 'padding-right':'0'}).jScrollPane({'scrollbarMargin':'0', 'showArrows':'true'});
			// 	}
		if( $('*').is('.storefinder') && $('*').is('.listContainer') ) {
			$('.listContainer').css({'height':'400px', 'padding-right':'0'}).jScrollPane({'scrollbarMargin':'0', 'showArrows':'true', 'dragMaxHeight':'10'});
//			$('.content3text .jScrollPaneContainer').css({'height':'385px'});
			$('.content3').css('overflow', 'hidden');
		} else {
			$('.content3text').css({'height':'460px', 'padding-right':'0'}).jScrollPane({'scrollbarMargin':'0', 'showArrows':'true', 'dragMaxHeight':'10'});
		}
	}
	if( $('*').is('.storefinder') ) {
		$('a.jScrollArrowUp').css({'top':'23px', 'z-index':'200'});
	}
	if( $('*').is('.content3 .searchForm') ) {
		$('.content3text a.jScrollArrowUp').css({'top':'0', 'z-index':'200'});
	}
	if( $('*').is('.templateD1') && $('*').is('.set-products') ) {
		$('.productRightTop').css({'padding-left':'0'}).jScrollPane({'scrollbarMargin':'0', 'showArrows':'true', 'dragMaxHeight':'1'});
	}
	
	// --------------------------------------------------------------------------------
	// effects: general (fade in, background image rotation)
	// --------------------------------------------------------------------------------
	var $hasBgImg = $('*').is('#bgPreloader');
	if( $hasBgImg ) {
		$('#bgPreloader').css('display', 'none');
      $('#bgPreloader a').each( function() {
			$(this).css('display', 'none').replaceWith($('<img />').attr('src', $(this).attr('href')));
		});
	}
	$('#bgPreloader').css('display', 'block');
   if( ! $('*').is('.templateD1') || $('*').is('.templateHistorie') ) {
		$('div#main').css('display', 'none');
	}
   $('#bgPreloader img').css('display', 'none');
	if( ! $('*').is('.storefinder') ) {
		
		// starts fade in as soon as image has been loaded
		var img = new Image();
	   $(img).load(function () {
	      $(this).css('display', 'none');
	      $('#bgPreloader > img:eq(0)').replaceWith(this);
	      $(this).fadeIn(2000);
	   }).attr('src', $('#bgPreloader > img:eq(0)').attr('src'));
		
		// if we have more than one background start image cycling after content fade in
		$('div#main').fadeIn(1000, function() {
			if( $('#bgPreloader img').length > 1 ) {
				if( $('*').is('.templateHistorie') ) {
               $('#bgPreloader').cycle({ 
				    	'fx':'fade', 
				    	'speed':  1500,
						'timeout': 1000
					});
				} else {
					$('#bgPreloader').cycle({ 
				    	'fx':'fade', 
				    	'speed':  2500,
						'timeout': 5000
					});
				}
			}
		});
	}
	
	// ie 6 hacks -- remove as soon as possible
	if( navigator.userAgent.indexOf('MSIE 6.0') > 0 ) {
		
		// overlay is not shown when background image rotation is active unless you explicitley set visibility
		$('.overlay').css('visibility', 'visible');
		
		// removes the png teaser image in ie6
		$('#teaser #teaserbild').remove();
	}
	
	// --------------------------------------------------------------------------------
	// effects: storefinder
	// --------------------------------------------------------------------------------
	if( $('*').is('.templateC .storefinder') ) {
		var img = new Image();
	   $(img).load(function () {
	      $(this).css('display', 'none');
	      $('#bgPreloader > img:eq(0)').replaceWith(this);
	      $(this).fadeIn(2000);
	   }).attr('src', $('#bgPreloader > img:eq(0)').attr('src'));
		$('div#main').css('display', 'block');
		$('div#main .content .storefinder').show('slide', {'direction':'up'});
	} else if( $('*').is('.templateF .storefinder') ) {
		var img = new Image();
	   $(img).load(function () {
	      $(this).css('display', 'none');
	      $('#bgPreloader > img:eq(0)').replaceWith(this);
	      $(this).css('display', 'block');
	   }).attr('src', $('#bgPreloader > img:eq(0)').attr('src'));
		$('div#main').css('display', 'block');
		$('div#main .content2 .storefinder').show('fold', '', 500);
	} else if( $('*').is('.templateG .storefinder') ) {
		var img = new Image();
	   $(img).load(function () {
	      $(this).css('display', 'none');
	      $('#bgPreloader > img:eq(0)').replaceWith(this);
	      $(this).css('display', 'block');
	   }).attr('src', $('#bgPreloader > img:eq(0)').attr('src'));
		$('div#main').css('display', 'block');
		$('div#main .content3 .storefinder').show('fold', '', 600);
	}	

	// --------------------------------------------------------------------------------	
	// effects: collection
	// --------------------------------------------------------------------------------
	if( $('*').is('.templateD1') ) {
		
		// more colors link
		$('a.moreColors').click( function(e) {
			if( $('div.productRightBottom').css('top') == '235px' ) {
				e.preventDefault();
				$('.productRightBottom').css({'background':'#e7e7e7 url(fileadmin/tpl_html/img/column_bg_left.jpg) repeat-y scroll 0 0','z-index':'5000'}).animate( {'top':'175px'}, 800 );
				$(this).html($('a.closeColorsTmp').html()).css({'background':'url(fileadmin/tpl_html/img/arrow_down.gif) no-repeat scroll 0 5px'});
			} else {
				e.preventDefault();
				$('.productRightBottom').css({'background-color':'#e7e7e7','z-index':'5000'}).animate( {'top':'235px'}, 800 );
				$(this).html($('a.moreColorsTmp').html()).css({'background':'url(fileadmin/tpl_html/img/arrow_up.gif) no-repeat scroll 0 5px'});
			}
		});
		
		// product magnifyer standard options
		var options = { 
			zoomType: 'standard', //standard/reverse/innerzoom
			zoomWidth: 225,		//zoomed width default width
			zoomHeight: 235,		//zoomed div default width
			xOffset: 48,		//zoomed div default offset
			yOffset: -67,
			position: "right" ,//zoomed div default position,offset position is to the right of the image
			lens:true, //zooming lens over the image,by default is 1;
			lensReset : true,
			imageOpacity: 0.2,
			title : false,
			alwaysOn: false,
			showEffect:'fadein',
			hideEffect:'fadeout',
			fadeinSpeed: 'slow',
			fadeoutSpeed: 'slow',
			preloadImages :true,
			showPreload: false,
			preloadText : 'Loading zoom',
			preloadPosition : 'center'   //bycss
		}
		
		if( $('*').is('.set-products') || $('*').is('.big-image') ) {
			// product magnifyer product sets options
			var options = { 
				zoomType: 'standard', //standard/reverse/innerzoom
				zoomWidth: 225,		//zoomed width default width
				zoomHeight: 235,		//zoomed div default width
				xOffset: 1,		//zoomed div default offset
				yOffset: -27,
				position: "right" ,//zoomed div default position,offset position is to the right of the image
				lens:true, //zooming lens over the image,by default is 1;
				lensReset : true,
				imageOpacity: 0.2,
				title : false,
				alwaysOn: false,
				showEffect:'fadein',
				hideEffect:'fadeout',
				fadeinSpeed: 'slow',
				fadeoutSpeed: 'slow',
				preloadImages :true,
				showPreload: false,
				preloadText : 'Loading zoom',
				preloadPosition : 'center'   //bycss
			}
			// positioning of product set letters
			if( $('*').is('.set-letter') ) {
				$('div.productView > div').append($('div.set-letter'));
				$('div.set-letter').css({'position':'absolute','display':'block','top':'0','left':'0'});
				$('div.set-letter > img').attr({'width':'442','height':'442'});	}
				$('div.set-letter').mouseover( function() {
					$('div.set-letter').css('display', 'none');
				});
		}
		
		if( $('*').is('.jqzoom') ) {
			$('.jqzoom').jqzoom( options );
		}
		
		// fade in colors in detail view
		$('.templateD1 .productView img').css('display', 'none');
		$('.templateD1 .productRightTop ul').css('display', 'none');
		$('.templateD1 .productRightBottom .colorImg').css('display', 'none');
		$('.templateD1 .productView img').fadeIn(500, function() {
			$('.templateD1 .productRightTop ul').fadeIn(300, function() {
           $('.templateD1 .productRightBottom .colorImg').fadeIn(300);
         });
		});
		
		// loads thumbnail images in product overview
		if( $('*').is('.templateD1 .content .contentsubnavi') ) {
							// var overviewId = $('.templateD1 .content .contentsubnavi ul').attr('name');
							// 							$('.templateD1 .content .contentsubnavi').find('ul').css('display', 'none').end().css({'background':'#e7e7e7 url(fileadmin/tpl_html/img/ajax-loader.gif) no-repeat 322px 28px'});
							// 							$('body').append('<div id="overviewPreloader" style="display:none;"></div>');
							// 							$('#overviewPreloader').load('index.php?id='+overviewId+' .contentsubnavi', function() {
							// 								$('.templateD1 .content .contentsubnavi').replaceWith($('#overviewPreloader > .contentsubnavi'));
							// 								//$('.templateD1 .content .contentsubnavi').prepend('');
							// 								//$('.templateD1 .content .contentsubnavi').append('');
							// 								if( navigator.userAgent.indexOf('MSIE') > 0 ) {
							// 									$('.templateD1 .content .contentsubnavi div.scrollableArea *').css({'position':'relative','padding':'0','margin':'0','float':'left'});
							// 								}
								$('.templateD1 .content .contentsubnavi').smoothDivScroll({'mouseDownSpeedBooster': 2});
								//$('.templateD1 .content .contentsubnavi').css({'display':'none', 'margin-right':'25px'}).fadeIn(500);
							// });
						}
		
		// fade in products in overview
		$('.templateD1 .productOverview:eq(0)').css('background-image', 'none');
		$('.templateD1 .productOverview img').css('display', 'none');
		$('.templateD1 .productOverview img:eq(0)').fadeIn(300, function() {
			$('.templateD1 .productOverview img:eq(1)').fadeIn(300, function() {
				$('.templateD1 .productOverview img:eq(2)').fadeIn(300);
			});
		});	
	}

	
	// --------------------------------------------------------------------------------	
   // hacks!!!!
	// --------------------------------------------------------------------------------
	
	// removes transparent "Mehr Infos" layer in case we got no link, change in typo3
	if( $('*').is('.templateD1') && $('.overlay a').text() == "" ) {
				$('.overlay').css('display', 'none');
			}
	
	
});

function onResizeWindow() {
	var $w = jQuery(window);
	var $layer = jQuery('#wrapper');
	$wWidth = parseInt( $w.width() );	
	$wHeight = parseInt( $w.height() );
	$lWidth = parseInt( $layer.css('width') );
	$lHeight = parseInt( $layer.css('height') );
	if( $wWidth > $lWidth ) {
		$layer.css( 'margin', '10px 0 0 0' );
		$layer.css( 'left', ($wWidth/2-$lWidth/2)+'px' );
	} 
	if( $wHeight > $lHeight ) {
      $layer.css( 'margin', '10px 0 0 0' );
		$layer.css( 'top', ($wHeight/2-$lHeight/2)+'px' );
   } else {
		$layer.css( 'margin', '10px 0 0 0' );
		$layer.css( 'top', '0' );
	}
	
   var $bgWidthHeight = 1024;
   var $bgLeft = ($wWidth/2)-($bgWidthHeight/2);
   var $bgTop = ($wHeight/2)-($bgWidthHeight/2);
   jQuery('body').css('background', '#7b7c7e url("fileadmin/tpl_html/img/bg_1024x1024.jpg") no-repeat '+$bgLeft+'px '+$bgTop+'px');
   
   $('#wrapper').css('visibility', 'visible');
   $('.content').css('visibility', 'visible');
}

