$(document).ready(function() {
  $(".teaser div.teasercontainer_hl").click(function(){
    if(false == $(this).next().is(':visible')) {
	  $(this).next().slideDown(300);
    }
    else {
      $(this).next().slideUp(300);
    }
  });

  $("div#navi ul li").mouseenter(function(){
	$(this).addClass("active");
  });
  $("div#navi ul li").mouseleave(function(){
	$(this).removeClass("active"); 
  });
  
  //Open Location List for Town
  $(".name").click(function(){
	  if($(this).parent().parent().hasClass("open")) {
	    $(this).parent().parent().removeClass("open");
	    $(this).parent().parent().next().slideUp(300);
		$(this).next().next().show();
		$(this).next().next().next().hide();
	  }
	  else {
		$(this).parent().parent().addClass("open");
		$(this).parent().parent().next().slideDown(300);
		$(this).next().next().hide();
		$(this).next().next().next().show();
	  }
  });
  
  $(".show_locations").click(function(){
	  $(this).parent().parent().addClass("open");
	  $(this).parent().parent().next().slideDown(300);
	  $(this).hide();
	  $(this).next().show();
  });
  $(".hide_locations").click(function(){
	  $(this).parent().parent().removeClass("open");
	  $(this).parent().parent().next().slideUp(300);
	  $(this).hide();
	  $(this).prev().show();
  });
  $(".dot").click(function(){
	  $(this).parent().parent().addClass("open");
	  $(this).parent().parent().next().slideDown(300);
	  $(this).prev().prev().hide();
	  $(this).prev().show();
  });
  
  if($("#nl_birthday").length != 0){
	    $("#nl_birthday").datepicker({
			  maxDate:"-1D",
			  defaultDate: -7300,
			  yearRange: 'c-100:c',
			  autoSize: false,
			  changeMonth: true,
			  changeYear: true,
			  buttonImage: "fileadmin/images/block-house/calendar.jpg",
			  buttonImageOnly: true,
			  showOn: 'both'
	    });
  }
  
  if($("#tr_date").length != 0){
	    $("#tr_date").datepicker({
			  minDate:"+1D",
			  maxDate:"+365D",
			  defaultDate: +1,
			  yearRange: 'c:c+1',
			  autoSize: false,
			  changeMonth: true,
			  changeYear: true,
			  buttonImage: "fileadmin/images/block-house/calendar.jpg",
			  buttonImageOnly: true,
			  showOn: 'both'
	    });
  }
  
  $(function() {
		$('#tr_city').change(function(){
			$.ajax({
				url: ('/index.php'),
				data: 'eID=bhlocations&city=' + $(this).val(),
				type: 'GET',
				timeout: 2000,
				dataType: 'json',
				error: function() {
					alert('Error loading data!');
				},
				success: function(json){
					var output = '';
					for (p in json) {
						output += '<option value=\"' + json[p].id + '\">' + json[p].name + '</option>\n';
					}
					$('#tr_location').html(output);
				}
			})
		});
	});

});

function showHaendlerInfo(id,lat,lng) {
  if ($("#row"+id).css('display') != 'block') {
    $("#hsearchresults .detail").hide();
    $(".row .ort").css('background-image','url(/fileadmin/images/block-house/hsearchclose.gif)');
    $("#row"+id).slideToggle();
    $("#ort"+id).css('background-image','url(/fileadmin/images/block-house/hsearchopen.gif)');
	  if (GBrowserIsCompatible()) {
      var map = new GMap2(document.getElementById("map"+id));
      map.setCenter(new GLatLng(lat, lng), 13);
      map.addOverlay(new GMarker(new GLatLng(lat, lng)));
      map.addControl(new GSmallZoomControl);
    }
  }
  else {
    $("#row"+id).slideToggle();
    $("#ort"+id).css('background-image','url(/fileadmin/images/block-house/hsearchclose.gif)');
  }
}

