function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

$(document).ready(function() {
	initMenu();
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
			markup: '<div class="pp_pic_holder"> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_loaderIcon"></div> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details clearfix"> \
											<a class="pp_close" href="#">Close</a> \
											<p class="pp_description"></p> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div> \
					<div class="ppt"></div>'
	});
	
	$('.storechooser').change(function(){
		$(".storechooser option:selected").each(function () {
			target = $(this).val();
		});
		document.location.href = target;
	});
	
	$('#schwerpunkt').change(function(){
		//$('#kontaktform').submit();
		$('#check').val(0);		
		$('.senden0').click();
	});
    
	equalHeight($(".infoboxHalfsize"));

	$(".inputText").focus(function() {
		if($(this).val() == 'Stichwort')
			$(this).val('');
	});
	
	$('.jobList').tableHover();
	$('.jobDesc').click(function(){
			document.location.href = $(this).children().attr('href');
	});
	$('.jobCity').click(function(){
			document.location.href = $(this).children().attr('href');
	});
	$('a').each(function(i) {
		$(this).focus(function() {
			this.blur();
		});
	});	

	$("#cat").val($('#catHolder').attr('value'));
	
	$('.jobTeaser li:odd').addClass('odd');
	
	// set form fields to empty depending on focus:
	$(".txtInput").focus(function() {
		if($(this).val() == 'E-Mailadresse' || $(this).val() == 'Passwort' || $(this).val() == 'Teilnahme-Code'){
			oldVal = $(this).val();
			$(this).val('');
		}
	});
	$(".txtInput").blur(function() {
		if($(this).val() == '' && (oldVal == 'E-Mailadresse' || oldVal == 'Passwort' || oldVal == 'Teilnahme-Code'))
			$(this).val(oldVal);
	});
	
	// bubbleinfo for map:
	$('.bubbleInfo').each(function () {
		var distance = 10;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var info = $('.popup', this).css('opacity', 0);


		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;

				info.css({
					top: -60,
					left: -50,
					display: 'block'
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}

			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);

			return false;
		});
	});	
	
	// slider animation for jobTeaser
	$('#jobSlider').cycle({ 
		fx:    'fade', 
		delay: -1000,
		timeout: 5000,
		prev: '.btBack',
		next: '.btFwd',
		before: onBefore
	});

});

function initMenu(){
	jQuery("#subnav a").removeAttr('title');
	jQuery("#subnav ul").css({display: "none"}); // Opera Fix
	jQuery("#subnav li").hover(function(){
		jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show();
	},function(){
		jQuery(this).find('ul:first').css({visibility: "hidden"});
	});	
}

function onBefore() {
	boxHeight = $(this).height()+15+'px';
	//alert(boxHeight);
	$('#jobSlider').animate({ height: boxHeight }, 1000);
	//alert(this.css('height'));
}
	

