$(document).ready(function() {

  /* focusEmpty Elemente
  -  bei focus Feld leeren, sofern noch der Standardwert enthalten ist
  --------------------------------------------------------------------- */
  aFocusEmpty = Array();

  $('input.focusEmpty').each(function() {
  	aFocusEmpty[$(this).attr('name')] = $(this).val();
  });


  $('input.focusEmpty').focus(function()
  {
  	if ($(this).val() == aFocusEmpty[$(this).attr('name')]) {
  		$(this).val('');
  	}
  }).blur(function()
  {
  	if ($(this).val() == '') {
  		$(this).val(aFocusEmpty[$(this).attr('name')]);
  	}
  });

  $('.contentBlockList ul li').hover(
	function() {
		$(this).addClass('active');
	},
	function() {
		$(this).removeClass('active');
	}
  );

// TeaserItems -> Link setzen

	$('.contentBlockTeaserContainer .teaserItem').hover(
		function() {
			$(this).addClass('teaserItemHover');
		},
		function() {
			$(this).removeClass('teaserItemHover');
		}
	);



// Beratersuche Sidebar -> Felder validieren

	$('#sidebarBeratersuche').submit(function() {
		$('#sidebarBeratersuche input.focusEmpty').each(function() {
  			sFoo = $(this).val();
			if (sFoo == aFocusEmpty[$(this).attr('name')]) {
				$(this).val('');
			}
		});

		bResult = true;

		// Länge der PLZ prüfen
		sPLZ = $('#sidebarBeratersuche input[name="sZIP"]').val();
		if ((sPLZ.length != 5) && (sPLZ.length != 0)) {
			alert('Bitte geben Sie eine 5-stellige PLZ ein');
			bResult = false;
		}

		// prüfen, ob wenigstens eines der Felder ausgefüllt ist
		if (($('#sidebarBeratersuche input[name="sBeratername"]').val() == '') && ($('#sidebarBeratersuche input[name="sZIP"]').val() == '')) {
			alert('Bitte füllen Sie mindestens eines der Suchfelder aus.');
			bResult = false;
		}

		// Länge des Beraternamens prüen
		sBeratername = $('#sidebarBeratersuche input[name="sBeratername"]').val();
		if ((sBeratername.length < 3) && (sBeratername.length != 0)) {
			alert('Bitte geben Sie mindestens drei Buchstaben beim Beraternamen ein');
			bResult = false;
		}


		if (bResult == false) {
			// focusEmpty Felder wieder herstellen wenn leer
			$('#sidebarBeratersuche input.focusEmpty').trigger('blur');
		}

		return bResult;
	});


	iSidebarShopingMallCount = $('#sidebarShopingMall').size();

	if (iSidebarShopingMallCount == 1) {
		iItemsCount = parseInt($('#sidebarShopingItemsContainer ul li').size());
		$('#sidebarShopingItemsContainer ul').css('width', (iItemsCount*145));
		$('#sidebarShopingNavBack a').click(function() {
			$(this).blur();
			iMarginLeft = parseInt($('#sidebarShopingItemsContainer ul').css('margin-left'));
			if (iMarginLeft <= (iItemsCount-1)*-145) {
				iMarginLeft = 0;
			} else {
				iMarginLeft = iMarginLeft - 145;
			}
			$('#sidebarShopingItemsContainer ul').animate({"marginLeft": iMarginLeft}, "fast");
			return false;
		});

		$('#sidebarShopingNavNext a').click(function() {
			$(this).blur();
			iMarginLeft = parseInt($('#sidebarShopingItemsContainer ul').css('margin-left'));
			if (iMarginLeft >= 0) {
				iMarginLeft = (iItemsCount-1)*-145;
			} else {
				iMarginLeft = iMarginLeft + 145;
			}
			$('#sidebarShopingItemsContainer ul').animate({"marginLeft": iMarginLeft}, "fast");
			return false;
		});

	}

// Shop Links
	$('a.shopLink').click(function() {
		sHref = $(this).attr('href');
		window.open(sHref,"SchornGES_Shop","location=no");
		return false;
	});

});