jQuery(function($){
	/* Scrollbalken */
	if ($('#scroll_pane').length) {
		$('#scroll_pane').jScrollPane(
			{
				scrollbarWidth: 12
			}
		);
	}

	/* Login-Panel */
	$('#login_show').click(
		function() {
			if (!(jQuery.browser.msie == true && jQuery.browser.version == 6)) {
 				$('#login_panel').toggle();
 				return false;
			}
		}
	);
	$('#login_close').click(
		function() {
 			$('#login_panel').toggle();
 			return false;
		}
	);


	/* E-Mail für Newsletter */
	$('#letter_email').focus(
		function() {
			$(this).val('');
		}
	);
	$('#letter_email').blur(
		function() {
			if (!$(this).val()) {
				$(this).val('Ihre E-Mail-Adresse ...');
			}
		}
	);


	/* Marken-Liste */
	$('#brands_list > li').each(
		function() {
			var value = $('a', this).attr('href').replace('#', '');
			var option = $('option[value="' + value + '"]', '#brands_select');

			$(this).click(
				function() {
					if ($(this).hasClass('active')) {
						option.attr('selected', false);
						$(this).removeClass('active');
					} else {
						option.attr('selected', true);
						$(this).addClass('active');
					}
				}
			);
		}
	);
	$('#brands_reset').click(
		function() {
 			$('#brands_list > li[class="active"]').removeClass('active');
 			$('#brands_select > option').attr('selected', false);
 			return false;
		}
	);

	$('#Zoomer').hover(
		function() {
			$('.meta').hide();
			$('#scroll_pane').hide();
			$('select#attribute122').hide();
		},
		function() {
			$('.meta').show();
			$('#scroll_pane').show();
			$('select#attribute122').show();
		}
	);

	$('#detail_thumbs > li > a').click(
			function() {
				var li = $(this).parent();
				$('#detail_thumbs > li').removeClass('active');
				li.addClass('active');
				return false;
			}
	);

});

function redirectTo(url) {
	if (url) {
		document.location.href = url;
	}
}


var braun={};

/* Service-Popup */
braun.servicePopUp = function() {
	jQuery(function($){
		$('.foot a.service, a.service-intern').click(
			function() {
				if (!$('#overlay').length) {
					/* Body erweitern */
					$('body').append('<div id="overlay"></div><div id="screen"></div>');

					/* Werte initialisieren */
					var top, left, width, height, marginTop;
					var output = '';
					var screen = $('#screen');

					/* Screen positionieren */
					if (typeof(window.pageYOffset) == 'number') {
			      top = window.pageYOffset;
			      left = window.pageXOffset;
			    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			      top = document.body.scrollTop;
			      left = document.body.scrollLeft;
			    } else if (document.documentElement) {
			      top = document.documentElement.scrollTop;
			      left = document.documentElement.scrollLeft;
			    }

			    if (self.innerHeight) {
			    	width = self.innerWidth;
			  		height = self.innerHeight;
			  	} else if (document.documentElement && document.documentElement.clientHeight) {
			  		width = document.documentElement.clientWidth;
			  		height = document.documentElement.clientHeight;
			  	} else if (document.body) {
			  		width = document.body.clientWidth;
			  		height = document.body.clientHeight;
			  	}

			  	screen.css(
			  		{
			  			'top': parseInt(top),
			  			'left': parseInt(left),
			  			'marginTop': parseInt((parseInt(height) - 600) / 2),
			  			'marginLeft': parseInt((parseInt(width) - 500) / 2)
			  		}
			  	);

					output += '<div class="head"><h1>Kundeninformationen</h1><a href="#">Schlie&szlig;en</a></div>';
					output += '<ul class="navi"><li class="shipping"><a href="#">Versand &amp; R&uuml;ckgabe</a></li><li class="sizes"><a href="#">Gr&ouml;&szlig;enschl&uuml;ssel</a></li><li class="privacy"><a href="#">AGB</a></li></ul>';
					output += '<div class="content"></div>';

					screen.html(output);

					screen.find('.navi li a').click(
						function() {
							var area = $(this).parent().attr('class');

							screen.find('.navi li a').removeClass('active');
							$(this).addClass('active');
							screen.find('.content').load(homeUrl + 'html/service/' + area + '.php');



							return false;
						}
					);

					screen.find('.head a').click(
						function() {
							$('#screen').remove();
							$('#overlay').remove();
							$('object').css({'visibility':'visible'});
							return false;
						}
					);
				}


				$('object').css({'visibility':'hidden'});

				/* Werte zuweisen */
				var area = this.href.replace(/^.*#/, '');

				/* Werte annulieren */
				if(!screen)
					return false;
				screen.find('.navi li a').removeClass('active');
				screen.find('.navi li.' + area + ' a').addClass('active');
				screen.find('.content').load(homeUrl + 'html/service/' + area + '.php');

				return false;
			}
		);
	});
}



braun.jsSelectBox = function() {
	jQuery(function($){


		/* Select */
		if ($('.select select').length) {
			$('.select select').change(
				function () {
					$('p', $(this).parent()).text(
						$(this).children(':selected').text()
					);
				}
			);

			$('.select select').each(
					function () {
						/*console.log("each");

						if($(this).children('option').length == 2) {

							$('p', $(this).parent()).parent('div').addClass("disabled");
							$(this).children('option:eq(1)').attr("selected","selected");
						}*/
						$('p', $(this).parent()).text(
							$(this).children(':selected').text()
						);
					}
				);
		}

		$('select.month').change(
				function () {
					var value = $(this).children(':selected').val();
					var text = $(this).children(':selected').text();
					if( value && text && text.length > 2) {
						text = text.substring(0,2);
					}
					$('p', $(this).parent()).text(text);
				}
			);

	});


}

Event.observe(window, 'load', function() {
	braun.servicePopUp();
	braun.jsSelectBox();
});
