var initialHeight = 50;
var initialHeightInfo = 270;
var initialHeightText = 10;
var destHeightText;
var destHeightInfo;
var heights = new Array();
heights['fleisch'] = 0;
heights['pommes'] = 0;
heights['sossen'] = 0;
heights['getraenke'] = 0;

if ($.browser.name == 'msie' || $.browser.name == 'opera')
	var alternative = true;

function init() {
	$('#infofield_nav').show();
	$('.textfield_nav').css('visibility', 'visible'); 
	$('#slideshow').css('visibility', 'visible');
	for ( var i = 2; i <= 12; i++) {
		j = (i < 10) ? '0' + i : i;
		$('#slideshow').append("<img src=\"img/slideshow/BilderGallerie"+ j +".png\" width=\"241\" height=\"221\" />");
	}
	$('#impressum').load('impressum.html', function() {
		$('div.close').html('<hr><br /><center><a href=\"#\" class=\"jqmClose\">Schlie&szlig;en</a></center>');
	});
	$('#rundgang').load('rundgang.html', function() {
		$('div.close').html('<hr><br /><center><a href=\"#\" class=\"jqmClose\">Schlie&szlig;en</a></center>');
	});
	
	if (alternative) { 
		if ($.browser.name == 'msie' && $.browser.versionNumber == 7) {
			$('head').append('<link rel=\"stylesheet\" type=\"text/css\" href=\"css/ke_ie7.css\" />');
			$('#infofield_text').after($('#infofield_inner_dynbg'));
			$('#infofield_inner_dynbg').css('z-index', '-1');
			$('#infofield_nav').css('margin-top', '-55');
			$('#slideshow').css('z-index', '10');
			
		} else {
			$('head').append('<link rel=\"stylesheet\" type=\"text/css\" href=\"css/ke_ie.css\" />');
		}
		
		$('#infofield').before('<div id=\"infofield_corner\" class=\"ro\"><div class=\"lo\"><div class=\"ru\"><div class=\"lu\"></div></div></div></div>');
		$('#infofield').appendTo($('.lu'));
		$('#infofield_inner_corner').before('<div id=\"infofield_dynbg\">');
		
		$('#infofield').css('background', 'none');
		
		for (id in heights) {
			$('#' + id + ' > .textfield_image').before('<div class=\"textfield_bg\">');
			$('#' + id).before('<div class=\"ro_klein\"><div class=\"lo_klein\"><div class=\"ru_klein\"><div id=\"' + id + '_corner\" class=\"lu_klein\">');
			$('#' + id).appendTo($('#' + id + '_corner'));
		}
		$('.textfield').css('background', 'none');
	}
}

function height() {
	heights['fleisch'] = $('#fleisch > div.textfield_text').height();
	heights['pommes'] = $('#pommes > div.textfield_text').height();
	heights['sossen'] = $('#sossen > div.textfield_text').height();
	heights['getraenke'] = $('#getraenke > div.textfield_text').height();

	destHeightInfo = $('#infofield').height();
	destHeightText = $('#infofield_text').height();

	$('#fleisch > div.textfield_text').height(initialHeight);
	$('#pommes > div.textfield_text').height(initialHeight);
	$('#sossen > div.textfield_text').height(initialHeight);
	$('#getraenke > div.textfield_text').height(initialHeight);
	
	$('#infofield').height(initialHeightInfo);
	$('#infofield_inner').height(initialHeightInfo - 10);
	$('#infofield_text').height(initialHeightText);
	$('#infofield_inner_dynbg').height(160);
}

$(function() {
	function sizeEffectInfo() {
		if ($('#infofield').height() == initialHeightInfo || $('#infofield').height() == destHeightInfo) {
			var heightToSet = ($('#infofield').height() == initialHeightInfo) ? destHeightInfo : initialHeightInfo;
			var textHeightToSet = ($('#infofield_text').height() == initialHeightText) ? destHeightText : initialHeightText;
			var imgToSet = ($('#infofield').height() == initialHeightInfo) ? 'oben' : 'unten' ;

			$('#infofield_inner_dynbg').animate({height: heightToSet - 110}, 500);
			$('#infofield_text').animate({height: textHeightToSet }, 500);

			if (alternative) {
				$('#infofield_dynbg').animate({height: heightToSet - 80}, 500);

			}
			$('#infofield').animate({height: heightToSet}, 500);
			$('#infofield_inner').animate({height: heightToSet - 10 }, 500, function() {
				$('#infofield_nav > img').attr('src','img/ke_pfeil_' + imgToSet + '.png');
			});
		}
	};
	$("#infofield_nav").click(function() {
		sizeEffectInfo();
		return false;
	});
});

$(function() {
	function sizeEffect(id) {
		var imgToSet = ($('#' + id + ' > div.textfield_text').height() == initialHeight) ? 'oben' : 'unten' ;
		var heightToSet = ($('#' + id + ' > div.textfield_text').height() == initialHeight) ? heights[id] : initialHeight;

		$('#' + id + ' > div.textfield_text').animate({height: heightToSet}, 500,function() {
			$('#' + id + ' > div.textfield_nav > img').attr('src','img/ke_pfeil_' + imgToSet + '.png');
		  });

		if (alternative) {
			$('#' + id + ' > div.textfield_bg').animate({height: heightToSet + 75}, 500);
		}
	};
	$(".textfield_nav").click(function() {
		sizeEffect($(this).parent().attr('id'));
		return false;
	});
});

$(document).ready(function() {
	init();
	$('#slideshow').cycle( {
		fx: 'shuffle',
		easing: 'backout',
		delay: -4000,
		timeout: 8000
	});

	$('#impressum').jqm({modal: true, trigger: 'a.showImpressum'});
	$('#rundgang').jqm({modal: true, trigger: 'a.showRundgang'});
	
});

$(window).load(function() {
	height();
});
