$(document)
		.ready(
				function() {
         /* Feedback */
      var feedbackTab = {
        speed:300,
        containerWidth:$('.feedback-panel').outerWidth(),
        containerHeight:$('.feedback-panel').outerHeight(),
        tabWidth:$('.feedback-tab').outerWidth(),

        init:function(){
          $('.feedback-panel').css('height',feedbackTab.containerHeight + 'px');

          $('a.feedback-tab').click(function(event){
            if ($('.feedback-panel').hasClass('open')) {
              $('.feedback-panel')
              .animate({
                left:'-' + feedbackTab.containerWidth
              }, feedbackTab.speed)
              .removeClass('open');
            } else {
              $('.feedback-panel')
              .animate({
                left:'0'
              },  feedbackTab.speed)
              .addClass('open');
            }
            event.preventDefault();
          });
        }
      };

      feedbackTab.init();

      $('a.close').click(function() {
        $('.feedback-panel')
        .animate({
          left:'-' + feedbackTab.containerWidth
        }, feedbackTab.speed)
        .removeClass('open');
        return false;
      });

      $(".feedback-panel .button").live('click', function() {
        var name = $("input#name").val();
        var email = $("input#email").val();
        var message = $("textarea#message").val();
        var response_message = "Danke für ihr Feedback!";
        var error_message = "Fehler beim Senden, bitte versuchen Sie es später erneut!";
        var dataString = 'name=' + name + '&email=' + email + '&message=' + message;
        var feedbackForm = $('#form-wrap').html();

        $.ajax({
          type: "POST",
          url: "feedback",
          data: dataString,
          success: function() {
            $('#form-wrap').html("<div id='response-message'></div>");
            $('#response-message').html("<p>" + response_message +"</p>").hide().fadeIn(500).animate({
              opacity: 1.0
            }, 1000).fadeIn(0, function(){
              $('#form-wrap').html(feedbackForm);
              $('.feedback-panel').animate({
                left:'-' + (feedbackTab.containerWidth)
              },(feedbackTab.speed)).removeClass('open');
            });
          },
          error: function() {
            $('#form-wrap').html("<div id='response-message'></div>");
            $('#response-message').html("<p>" + error_message +"</p>").hide().fadeIn(500).animate({
              opacity: 1.0
            }, 1000).fadeIn(0, function(){
              $('#form-wrap').html(feedbackForm);
              $('.feedback-panel').animate({
                left:'-' + (feedbackTab.containerWidth)
              },(feedbackTab.speed)).removeClass('open');
            });
          }
        });
        return false;
      });
      /* END Feedback */
					var heightLogoArr = new Array();
					$('.content_results_logo_0').each(function(e) {
						heightLogoArr[e] = $(this).height();
					});
					$('.content_results_logo_1').each(function(e) {
						heightLogoArr[e] = $(this).height();
					});
					$('.content_results_logo_2').each(function(e) {
						heightLogoArr[e] = $(this).height();
					});
					var heightNameArr = new Array();
					$('.content_results_name_0').each(function(e) {
						heightNameArr[e] = $(this).height();
					});
					$('.content_results_name_1').each(function(e) {
						heightNameArr[e] = $(this).height();
					});
					$('.content_results_name_2').each(function(e) {
						heightNameArr[e] = $(this).height();
					});
					$('.content_results_row')
							.each(
									function(e) {
										var height;
										if (heightLogoArr[e] > heightNameArr[e]
												&& heightNameArr[e] < 50) {
											if (heightLogoArr[e] > 50) {
												height = 50;
											} else {
												height = heightLogoArr[e];
											}
										} else {
											height = heightNameArr[e];
										}
										$(this).css('height', height + 10);
										$(this)
												.children()
												.each(
														function() {
															var heightChildren = $(
																	this)
																	.height();
															var offsetTop = (height - heightChildren) / 2;
															if (offsetTop < 0) {
																offsetTop = '0px'
															}
															$(this)
																	.css(
																			'position',
																			'relative')
																	.css('top',
																			offsetTop)
																	.css(
																			'height',
																			height);
														});
									});
					$('.google_adsense_wrapper').each(
							function(e) {
								var height = $('.google_adsense').height();
								if (height > 0) {
									var offsetTop = (height - 13) / 2;
									$('.google_adsense_arrow_0').css(
											'position', 'relative').css('top',
											offsetTop);
									$('.google_adsense_arrow_1').css(
											'position', 'relative').css('top',
											offsetTop);
									$('.google_adsense_arrow_2').css(
											'position', 'relative').css('top',
											offsetTop);
								} else {
									$(this).remove();
								}
							});
					$(function() {
						$('#detailsuche').click(function() {
							if ($('#extsearch').is(':hidden')) {
								$('#extsearch').fadeIn('slow');
								$(this).removeClass('detailed_show');
								$(this).addClass('detailed_hide');
								$.cookie('showDetailsuche', 'true');
							} else {
								$('#extsearch').fadeOut('slow');
								$(this).removeClass('detailed_hide');
								$(this).addClass('detailed_show');
								$.cookie('showDetailsuche', 'false');
							}
							return false;
						});
					});
					$(function() {
						var showDetailsuche = $.cookie('showDetailsuche');
						if (showDetailsuche == 'true') {
							$('#extsearch').show();
							$('#detailsuche').removeClass('detailed_show');
							$('#detailsuche').addClass('detailed_hide');
						}
						;
						if (showDetailsuche == 'false') {
							$('#extsearch').hide();
							$('#detailsuche').removeClass('detailed_hide');
							$('#detailsuche').addClass('detailed_show');
						}
						;
					});
					$(function() {
						$('#jobtitle').autocomplete(
								"/autocomplete.php?mode=jobtitle&plain=true", {
									width : 244,
									scrollHeight : 200,
									selectFirst : false,
									delay : 100,
									minChars : 1,
									max : 10,
									cacheLength : 0,
									matchSubset : false
								});
						$('#location').autocomplete(
								"/autocomplete.php?mode=location&plain=true", {
									width : 244,
									max : 25,
									scrollHeight : 200,
									selectFirst : false,
									matchSubset : false,
									delay : 100,
									minChars : 1
								});
					});
					$('#jobtitle').select().focus();
					$('.rem')
							.click(
									function() {
										$(this)
												.effect(
														"shake",
														{
															direction : "up",
															distance : 15,
															times : 2
														},
														200,
														function() {
															$(this)
																	.replaceWith(
																			'<img src="/images/stellenangebote_button_rem_active.png"/>');
														});
										$.ajax( {
											type : "POST",
											url : $(this).attr('href')

										});
										return false;
									});
					$("a.merkliste_remove").click(function() {
						$(this).closest("div").parent().fadeOut(500);
						$.post($(this).attr('href'));
						return false;
					});
					$('#deleteSavedJobs').click(function() {
						$.ajax( {
							type : "POST",
							url : "pages/clearSavedJobs"
						});
						$('.content_results').fadeOut(700);
						return false;
					});
				});
