//Functions needed for the whole page

jQuery(document).ready(function() {
	jQuery('#SearchText,#AddSearchText')
		.click(function() {
			if(jQuery(this).val() == 'PLZ') {
				jQuery(this).val('').css('color', '#000');
			}
		})
		.blur(function() {
			if(jQuery(this).val() == '') {
				jQuery(this).val('PLZ').css('color', '#7A7A7A');
			}
		})
		.focus(function() {
			if(jQuery(this).val() == 'PLZ') {
				jQuery(this).val('').css('color', '#000');
			}
		})
		.val('PLZ');

	jQuery('#FtSearchText')
	.click(function() {
		if(jQuery(this).val() == 'Textsuche') {
			jQuery(this).val('').css('color', '#000');
		}
	})
	.blur(function() {
		if(jQuery(this).val() == '') {
			jQuery(this).val('Textsuche').css('color', '#7A7A7A');
		}
	})
	.focus(function() {
		if(jQuery(this).val() == 'Textsuche') {
			jQuery(this).val('').css('color', '#000');
		}
	})
	.val('Textsuche');

	// Make external links open in new window
	jQuery("area[rel='external']").attr('target', 'blank');

	// Scroll down...
	var $target = (jQuery.browser.safari ? jQuery('body') : jQuery('html'));

	if(jQuery.browser.msie) {
		var timeBeforeScroll = 200;
	} else {
		timeBeforeScroll = 0;
	}

	setTimeout(function() {
		if(parseInt( $target.scrollTop() ) == 0) {
			if(document.getElementById('Map') != null) {
				$target.animate({scrollTop: findPosY(document.getElementById('Map')) - 55 + 'px'}, 1500);
			} else {
				$target.animate({scrollTop: '135px'}, 800);
			}
		}
	}, timeBeforeScroll);


	jQuery(document.body).mousewheel(function() {
		$target.stop();
	})
});

// Returns the offsetTop position of an element
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if(obj.y)
		curtop = obj.y;

	return curtop;
}
