// 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"))
  			{
  			  $span.css('opacity', 1);
  			}
  			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
	    }
	  });
	};
});

$(function(){ 
    // find all the input elements with title attributes
	$('input[title!=""]').hint();
});

$(document).ready(function ()
{
  $('.popup-link').click(function()
  {
    var href = $(this).attr('href');
    var width = 950;
    var height = 700;
    var l = (screen.availWidth - width) / 2;
    var t = (screen.availHeight - height) / 2;
    window.open(href,'popup','width=' + width + ',height=' + height + ',toolbar="no",scrollbars="no",menubar="no",left=' + l + ',top=' + t + '');
    return false;
  });
});

function popup(url)
{
  window.open(url, '', 'width=420,height=500,scrollbars=yes,resizable=yes');
  void(0);
}

function doSubmit(id)
{
  document.getElementById(id).submit();
  return false;
}