$(document).ready(function() {
   /*
   alert('WAAAARGH!11einseinself!1!!');   // das musste ich mal rauslassen
   return false;                          // und tschüss ;)
   */

   // headerImage hover effect 
   $('.headerImage').hover(function() {
      $(this).children('.layerText').stop().css({'opacity':'0.5'})
         .animate({'height':'32px','opacity':'1'}, 250).end()
         .children('.layerBackground').stop().animate({'height':'32px'}, 250)
         .end().children('.button').stop().animate({'opacity':'1'}, 250);
   }, function() {
      $(this).children('.layerText').stop()
         .animate({'height':'0px','opacity':'0.5'}, 500).end()
         .children('.layerBackground').stop().animate({'height':'0px'}, 500)
         .end().children('.button').stop().animate({'opacity':'0.5'}, 500);
   }).children('.layerBackground').css({'opacity':'0.5'}).end()
      .children('.button').css({'opacity':'0.5'});

   // event search form
   $('.extra-links .week').click(function() {
      $('#cb-search-form input[name="startDate"]').remove();
      $('#cb-search-form input[name="endDate"]').remove();
      $('#cb-search-form input[name="event_datetime"]').val($(this).attr('ref'));
      $('#cb-search-form').submit();
   });
   
   // search forms helper
   jQuery.fn.defaultValuedInput = function(default_value) {
      jQuery(this).each(function() {
         jQuery(this).focus(function() {
            if (jQuery(this).val() == default_value || jQuery(this).val() == '') {
               jQuery(this).val('');
            }
            jQuery(this).addClass('active');
         }).focus().blur(function() {
            if (jQuery(this).val() == default_value || jQuery(this).val() == '') {
               jQuery(this).val(default_value).removeClass('active');
            }
         }).blur();
      });
   }
   
   // search forms
   $('.searchInput').defaultValuedInput($('.searchInputDefaultValue').html());
   
   // fix services
   $('.press_check > .entry > .entry').each(function() {
      var text = $(this).children('.name').children('.text');
      $(this).children('.children').prepend(text.clone());
      text.remove();
   });
   
   // fix search form
   $('.go-button').click(function() {
      $(this).parent().parent()[0].submit();
      return false;
   });
});

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

function positionZoomIcon() {
   $('.portrait').each(function() {
      if ($(this)[0].height > 20) {
         $(this).parent().children('.zoom').css('top',($(this).offset().top + $(this)[0].height - 11)+'px');
      }
   });
}

function closeThickbox() {
 jQuery("body, html").css("overflow","");
   $('#TB2_overlay, #TB2_window').remove();
   $('#TB2_overlay, #TB2_window, #TB2_HideSelect').remove();
}

function styleCbSearch() {
   $('.visitMenuLabel').each(function() {
      var label = $(this).parent().children('.cbSearchLink').html().replace(/^.*http:\/\/web1\.heimat\.de\/agdok\/[a-z]{2}_[A-Z]{2}\/([^\/]+)\/.*$/, '$1').replace(/^.*http:\/\/www\.agdok\.de\/[a-z]{2}_[A-Z]{2}\/([^\/]+)\/.*$/, '$1').split('_')[0];
      var caption = $('.cbSearchLabel2Caption').children('.'+label).html();
      $(this).html(caption);
   });
}

function submitform(myfield) {
   if (window && window.event && window.event.keyCode == 13) {
      myfield.form.submit();
      return false;
   }
}

