
$(document).ready(function() {
	observeHomeLink();
	observeContent();
	observeImageCaption();
	initImageGallery();
	initContactForm();
	observeMainMenu();
});

function observeHomeLink() {

	if ($('#menuHome').length > 0) {
		$('#metaMenu .lnkMtM:eq(0)').addClass('sel');
		$('#metaMenu .sel:eq(0)').removeClass('lnkMtM');
	}
}

function observeContent() {

	if ($('#menuSub').length > 0) {

		$('#contentBox').css('margin-top', '0');
		$('#content').css('margin-top', '15px');

		$('#content').before('<div id="submenu"></div>');
		$('#menuSub').appendTo("#submenu");

		$('#content').css({
			'float': 'left',
			'width': '775px'
		});

		if ($('#teaser').length > 0) {
			$('#content').css('width', '388px');
			$('#teaser').css('margin-top', '15px');
		}
	}

	if (($('#menuSub').length == 0) && ($('#teaser').length > 0)) {
		$('#content').css({
			'float': 'left',
			'width': '600px'
		});
	}
}

function observeImageCaption() {

	$('dd.csc-textpic-caption').each(function() {
		$(this).parent().mouseover(function() {
			$(this).find('dd.csc-textpic-caption').show();
		});
		$(this).parent().mouseout(function() {
			$(this).find('dd.csc-textpic-caption').hide();
		});
	});
}

function initImageGallery() {

	if ($('.imagegallery').length > 0) {

		var iNbImg = $('.imagegallery .csc-textpic-imagerow').length;

		if (iNbImg > 0) {

			var objNav = $('.imagegallery .igNav');

			for (i = 0; i < iNbImg; i++) {
				objNav.append('<a href="javascript:void(0)" class="igNavLnk normal">' + (i + 1) + '</a><input type="hidden" value="' + i +'" />');

				if (i < (iNbImg - 1)) {
					objNav.append('&nbsp;|&nbsp;');
				}
			}

			$('.imagegallery .igNav .igNavLnk').click(function() {
				var index = $('.imagegallery .igNav .igNavLnk').index(this);
				$('.imagegallery .csc-textpic-imagerow').css('display', 'none');
				$('.imagegallery .csc-textpic-imagerow:eq(' + index + ')').css('display', 'block');
				$('.imagegallery .igNavLnk').removeClass('normal');
				$('.imagegallery .igNavLnk').removeClass('active');
				$('.imagegallery .igNavLnk').addClass('normal');
				$('.imagegallery .igNavLnk:eq(' + index + ')').removeClass('normal');
				$('.imagegallery .igNavLnk:eq(' + index + ')').addClass('active');				
			});

			$('.imagegallery .csc-textpic-imagerow:eq(0)').css('display', 'block');
			$('.imagegallery .igNavLnk:eq(0)').removeClass('normal');
			$('.imagegallery .igNavLnk:eq(0)').addClass('active');
		}
	}
}

function initContactForm() {

	if ($('.tx-powermail-pi1').length > 0) {

		var name = $('#powermaildiv_uid1 label').text();
		var email = $('#powermaildiv_uid2 label').text();
		var subject = $('#powermaildiv_uid3 label').text();
		var message = $('#powermaildiv_uid4 label').text();
		var check = $('#powermaildiv_uid6 label').text();

		var mName = $('#powermaildiv_uid7 label').text();
		var mEmail = $('#powermaildiv_uid8 label').text();
		var mSubject = $('#powermaildiv_uid9 label').text();
		var mFirma = $('#powermaildiv_uid10 label').text();
		var mCheck = $('#powermaildiv_uid11 label').text();
		var mMessage = $('#powermaildiv_uid18 label').text();
		var mStrasse = $('#powermaildiv_uid19 label').text();
		var mOrt = $('#powermaildiv_uid20 label').text();
		var mTelefon = $('#powermaildiv_uid21 label').text();
		var mAnzahl = $('#powermaildiv_uid22 label').text();
		var mAnzahlPk = $('#powermaildiv_uid23 label').text();
		var mLand = $('#powermaildiv_uid25 label').text();
		var mZahlung = $('#powermaildiv_uid26 label').text();

		if (!$('#uid1').val()) {
			$('#uid1').css('color', '#aeaeae');
			$('#uid1').val(name);
		}
		if (!$('#uid2').val()) {
			$('#uid2').css('color', '#aeaeae');
			$('#uid2').val(email);
		}
		if (!$('#uid3').val()) {
			$('#uid3').css('color', '#aeaeae');
			$('#uid3').val(subject);
		}
		if (!$('#uid4').val()) {
			$('#uid4').css('color', '#aeaeae');
			$('#uid4').val(message);
		}
		if (!$('#uid6').val()) {
			$('#uid6').css('color', '#aeaeae');
			$('#uid6').val(check);
		}

		if (!$('#uid7').val()) {
			$('#uid7').css('color', '#aeaeae');
			$('#uid7').val(mName);
		}
		if (!$('#uid8').val()) {
			$('#uid8').css('color', '#aeaeae');
			$('#uid8').val(mEmail);
		}
		if (!$('#uid9').val()) {
			$('#uid9').css('color', '#aeaeae');
			$('#uid9').val(mSubject);
		}
		if (!$('#uid10').val()) {
			$('#uid10').css('color', '#aeaeae');
			$('#uid10').val(mFirma);
		}
		if (!$('#uid11').val()) {
			$('#uid11').css('color', '#aeaeae');
			$('#uid11').val(mCheck);
		}
		if (!$('#uid18').val()) {
			$('#uid18').css('color', '#aeaeae');
			$('#uid18').val(mMessage);
		}
		if (!$('#uid19').val()) {
			$('#uid19').css('color', '#aeaeae');
			$('#uid19').val(mStrasse);
		}
		if (!$('#uid20').val()) {
			$('#uid20').css('color', '#aeaeae');
			$('#uid20').val(mOrt);
		}
		if (!$('#uid21').val()) {
			$('#uid21').css('color', '#aeaeae');
			$('#uid21').val(mTelefon);
		}
		if (!$('#uid22').val()) {
			$('#uid22').css('color', '#aeaeae');
			$('#uid22').val(mAnzahl);
		}
		if (!$('#uid23').val()) {
			$('#uid23').css('color', '#aeaeae');
			$('#uid23').val(mAnzahlPk);
		}
		if (!$('#uid25').val()) {
			$('#uid25').css('color', '#aeaeae');
			$('#uid25').val(mLand);
		}
		if (!$('#uid26').val()) {
			$('#uid26').css('color', '#aeaeae');
			$('#uid26').val(mZahlung);
		}

		$('#uid1').focus(function() {
			if ($(this).val() == name) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid1').blur(function() {
			if ($(this).val() == '') {
				$(this).val(name);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid2').focus(function() {
			if ($(this).val() == email) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid2').blur(function() {
			if ($(this).val() == '') {
				$(this).val(email);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid3').focus(function() {
			if ($(this).val() == subject) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid3').blur(function() {
			if ($(this).val() == '') {
				$(this).val(subject);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid4').focus(function() {
			if ($(this).val() == message) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid4').blur(function() {
			if ($(this).val() == '') {
				$(this).val(message);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid6').focus(function() {
			if ($(this).val() == check) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid6').blur(function() {
			if ($(this).val() == '') {
				$(this).val(check);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid7').focus(function() {
			if ($(this).val() == mName) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid7').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mName);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid8').focus(function() {
			if ($(this).val() == mEmail) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid8').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mEmail);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid9').focus(function() {
			if ($(this).val() == mSubject) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid9').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mSubject);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid10').focus(function() {
			if ($(this).val() == mFirma) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid10').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mFirma);
				$(this).css('color', '#aeaeae');
			}
		});

		$('#uid11').focus(function() {
			if ($(this).val() == mCheck) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid11').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mCheck);
				$(this).css('color', '#aeaeae');
			}
		});
		
		$('#uid18').focus(function() {
			if ($(this).val() == mMessage) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid18').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mMessage);
				$(this).css('color', '#aeaeae');
			}
		});
		
		$('#uid19').focus(function() {
			if ($(this).val() == mStrasse) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid19').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mStrasse);
				$(this).css('color', '#aeaeae');
			}
		});
		
		$('#uid20').focus(function() {
			if ($(this).val() == mOrt) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid20').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mOrt);
				$(this).css('color', '#aeaeae');
			}
		});
		
		$('#uid21').focus(function() {
			if ($(this).val() == mTelefon) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid21').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mTelefon);
				$(this).css('color', '#aeaeae');
			}
		});
		
		$('#uid22').focus(function() {
			if ($(this).val() == mAnzahl) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid22').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mAnzahl);
				$(this).css('color', '#aeaeae');
			}
		});
		$('#uid23').focus(function() {
			if ($(this).val() == mAnzahlPk) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid23').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mAnzahlPk);
				$(this).css('color', '#aeaeae');
			}
		});
		
		$('#uid25').focus(function() {
			if ($(this).val() == mLand) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid25').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mLand);
				$(this).css('color', '#aeaeae');
			}
		});
		$('#uid26').focus(function() {
			if ($(this).val() == mZahlung) {
				$(this).val('');
				$(this).css('color', '#000');
			}
		});
		$('#uid26').blur(function() {
			if ($(this).val() == '') {
				$(this).val(mZahlung);
				$(this).css('color', '#aeaeae');
			}
		});

		if ($('#frmcontact')) {
			$('#frmcontact').submit(function() {

				if ($('#uid1').val() == name) {
					$('#uid1').val('');
				}
				if ($('#uid2').val() == email) {
					$('#uid2').val('');
				}
				if ($('#uid3').val() == subject) {
					$('#uid3').val('');
				}
				if ($('#uid4').val() == message) {
					$('#uid4').val('');
				}
				if ($('#uid6').val() == check) {
					$('#uid6').val('');
				}
				if ($('#uid7').val() == mName) {
					$('#uid7').val('');
				}
				if ($('#uid8').val() == mEmail) {
					$('#uid8').val('');
				}
				if ($('#uid9').val() == mSubject) {
					$('#uid9').val('');
				}
				if ($('#uid10').val() == mFirma) {
					$('#uid10').val('');
				}
				if ($('#uid11').val() == mCheck) {
					$('#uid11').val('');
				}
				if ($('#uid18').val() == mMessage) {
					$('#uid18').val('');
				}
				if ($('#uid19').val() == mStrasse) {
					$('#uid19').val('');
				}
				if ($('#uid20').val() == mOrt) {
					$('#uid20').val('');
				}
				if ($('#uid21').val() == mTelefon) {
					$('#uid21').val('');
				}
				if ($('#uid22').val() == mAnzahl) {
					$('#uid22').val('');
				}
				if ($('#uid23').val() == mAnzahlPk) {
					$('#uid23').val('');
				}
				if ($('#uid25').val() == mLand) {
					$('#uid25').val('');
				}
				if ($('#uid26').val() == mZahlung) {
					$('#uid26').val('');
				}

			});
		}
	}
}

function observeMainMenu() {

	if ($('.lnkMM').length > 0) {

		var sColSave = '';

		$('.lnkMM, .lnkMMSel').mouseover(function() {
			sColSave = $(this).prev().css('color');
			$(this).prev().css('color', '#20B9D0');
		});
		$('.lnkMM, .lnkMMSel').mouseout(function() {
			$(this).prev().css('color', sColSave);
		});
	}
}
