$(document).ready(function() {
	$('#type').change(function() {
		if ($('#type option[value="Pressekontakt"]').attr('selected')) {
			$('#street, #city, #phone, #fax, #date, #case, #where, #ppl').hide();
			$('#theater').val('Medium');
		}
		else if ($('#type option[value="Kontakt Michael"]').attr('selected')) {
			$('#street, #theater, #city, #phone, #fax, #date, #case, #where, #ppl').hide();
		}
		else {
			$('#street, #city, #phone, #fax, #date, #case, #where, #ppl, #area').show();
		}
	});
	
});

$(function() {
	setslideWidth();
  $(window).resize(function() {
    setslideWidth();
  })
	
  $('.wizzard a:first').addClass('active');
  
  $('.wizzard a').click(function(e) {
    e.preventDefault();
    
    $('.wizzard a').removeClass('active');
    $(this).addClass('active');
    
    var position = $(this).parent().prevAll('li').get().length;
    $('.wizzard').data('position', position);
    
    setslideWidth(true);
  });
  
  $('.next').click(createCallback('next', 'first'));
  $('.prev').click(createCallback('prev', 'last'));
  
  function createCallback(direction, fallback) {
    return function(e) {
      e.preventDefault();

      var current = $('.wizzard a.active');
      var next = current.parent()[direction]('li').find('a');
      if(next.get(0) === undefined) {
        next = $('.wizzard a:' + fallback);
      };
      next.click();
    }
  }
  
  function setslideWidth(animate) {
    var window_width = $(window).width(),
      slide_width = $('.slide:first').outerWidth(),
      position = $('.wizzard').data('position');
      
  	$('.slide, .slide').width(window_width);
    if(animate) {
      $('.container').animate({'margin-left': slide_width * position * -1});
    } else {
  	  $('.container').css('margin-left', slide_width * position * -1);
    }
  	
  }
});
