var headerFadeIndex;
var headerImages;
var imageCache = [];

$(document).ready(function() {

	// initialize foldable press release body 
	$('.pr-teaser').each(function() {
		if ($(this).html().length) {
			$(this).next('.pr-body').hide();
			$(this).children('img').click(function() {
				$(this).parent().next('.pr-body').show();
			});
		}
	});

	// initialize image rotation
	headerImages = $('div.rotation img');
	headerFadeIndex = headerImages.length - 1;
	if (headerImages.length > 1)
		window.setInterval('headerFade()', 6000);
	
	// hotel search hint text
	var searchHintText = 'Suche nach Hotels';
	$('.finder-view-2 input[@type=text]')
		.val(searchHintText)
		.focus(function() {
			if ($(this).val() == searchHintText)
				$(this).val('');
		})
		.blur(function() {
			if ($(this).val() == '')
				$(this).val(searchHintText);
		});
	if ($.browser.msie)	// hide focus rect
		$('.finder-view-2 input[@type=text]').attr('hideFocus', 'true');
	$('#finder-form-2').add('#finder-form-2-1').each(function() {
		$(this).submit(function() {
			var i = $('input[@type=text]', $(this));
			if (i.val() == searchHintText)
				i.val('');
			return true;
		});
	});
	
	// preload images
//	preloadImage('images/hgp/button_search_over.png');
//	preloadImage('images/tgp/button_search_over.png');
//	preloadImage('images/tgp/button_anfrage-absenden_over.png');
//	preloadImage('images/tgp/button_details_over.png');
});

function headerFade() {
	headerFadeIndex = (headerFadeIndex + 1) % headerImages.length;
	var newImg = headerImages.eq(headerFadeIndex);
	newImg
		.css('opacity', 0)
		.appendTo($('div.rotation'))
		.animate({opacity:1}, 1500);
}

function preloadImage(url) {
	var img = document.createElement('img');
	img.src = url;
	imageCache.push(img);
}

