
$(document).ready(function() {
	initBigImg();
	initGalleryCatLnk();
	initContactForm();
	initNewsletterSubscription();
});

function initBigImg() {

	var sUrl = $('#themeImg').attr('value');
	/*sUrl = document.location.protocol + '//' + document.location.hostname + '/' + sUrl;*/

	var img = new Image();

	$(img).load(function() {
		$('body').css('background-image', 'url(' + sUrl + ')');
    }).error(function() {
    }).attr('src', sUrl);
}

function initGalleryCatLnk() {

	$('.wtgallery_category_pic-pattern').click(function() {
		document.location.href = $(this).prev().find('a').attr('href');
	});
}

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_uid5 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 (!$('#uid5').val()) {
			$('#uid5').css('color', '#aeaeae');
			$('#uid5').val(check);
		}

		$('#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');
			}
		});
	}
}

function initNewsletterSubscription() {

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

		var fname = $('.tsrNlForm .fname label').text();
		var lname = $('.tsrNlForm .lname label').text();
		var email = $('.tsrNlForm .email label').text();

		if (!$('#nlvorname').val()) {
			$('#nlvorname').css('color', '#aeaeae');
			$('#nlvorname').val(fname);
		}
		if (!$('#nlnachname').val()) {
			$('#nlnachname').css('color', '#aeaeae');
			$('#nlnachname').val(lname);
		}
		if (!$('#nlmail').val()) {
			$('#nlmail').css('color', '#aeaeae');
			$('#nlmail').val(email);
		}

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

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

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