// sprite funktion mit active-state
$(function(){
  if ($.browser.msie && $.browser.version < 7) return;
  $('#mainnav li')
      .removeClass('highlight')
      .find('a')
      .append('<span class="hover" />').each(function () {
         var $span = $('> span.hover', this).css('opacity', 0);
         
      // aktive URL auslesen und aufsplitten
		  var path = window.location.toString().split("/");
		  var home = "/";
	  	var url = "/" + path[3] + "/";	 
		  	    
    	// element mit ausgelesener URL finden und manipulieren *hex hex*
		  $("#mainnav li a[href='" + [url || home] + "']").children("span").each(function() {   
		     	$(this).css('opacity', 1);
		     	$(this).parent().addClass("selected");
		  })
  	
  			// HAX um das aktive element nicht zu �ndern.
  			if($(this).hasClass("selected")) { } else {
          $(this).hover(function () {
              // on hover
              $span.stop().fadeTo(500, 1);
          }, function () {
              // off hover
              $span.stop().fadeTo(500, 0);
          });
          }
      });
});

// external links
$(function() {
	$(".external").attr("target","_blank").attr("rel","bookmark");
});

// textbox hints
$(function(){
	jQuery.fn.hint = function (blurClass) {
	  if (!blurClass) { 
	    blurClass = 'blur';
	  }
	
	  return this.each(function () {
	    // get jQuery version of 'this'
	    var $input = jQuery(this),
	
	    // capture the rest of the variable to allow for reuse
	      title = $input.attr('title'),
	      $form = jQuery(this.form),
	      $win = jQuery(window);
	
	    function remove() {
	      if ($input.val() === title && $input.hasClass(blurClass)) {
	        $input.val('').removeClass(blurClass);
	      }
	    }
	
	    // only apply logic if the element has the attribute
	    if (title) { 
	      // on blur, set value to title attr if text is blank
	      $input.blur(function () {
	        if (this.value === '') {
	          $input.val(title).addClass(blurClass);
	        }
	      }).focus(remove).blur(); // now change all inputs to title
	
	      // clear the pre-defined text when form is submitted
	      $form.submit(remove);
	      $win.unload(remove); // handles Firefox's autocomplete
	    }
	  });
	};
});

// Formular Validation etc.
/*$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		var nachricht = $("textarea#nachricht").val();
		if (nachricht == "") {
      $("label#nachricht_error").show();
      $("textarea#nachricht").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&nachricht=' + nachricht;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<strong>Kontaktformular abgeschickt!</strong>")
        .append("<p>Wir werden uns bei Ihnen melden.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='/images/check.png' />");
        });
      }
     });
    return false;
	});
});*/
