$(document).ready(function() {
    switches = $('ul > li');
    slides = $('li');
    switches.each(function(idx) {
            this.slide = slides[idx];
        }).hover(
        function() {
            switches.removeClass('active');
            $(this).addClass('active');  
        });
    });

$(function()
{

  var hideDelay = 500;  
  var currentID;
  var hideTimer = null;

  var container = $('<div id="snippetPopupContainer"><div id="snippetPopupContent"></div>');

  $('body').append(container);

  $('a#spt').live('click',function() {
	var currentID = $(this).attr('rel')
	$('ul#sp'+currentID).toggle();
  });
	
  $('.snippetPopupTrigger').live('mouseover', function()
  {
      var currentID = $(this).closest('li').attr('id');

      if (currentID == '')
          return;

      if (hideTimer)
          clearTimeout(hideTimer);

      var pos = $(this).offset();
      container.css({
          left: (pos.left) + 35 + 'px',
          top: (pos.top) - 15 + 'px'
      });

      $('#snippetPopupContent').html('&nbsp;');

	  if(undefined!==window.aj) {
		window.aj.abort(); 
		window.aj = null; 		
	  } 
	  
      $('#snippetPopupContent').html('<span><img src="/img/ajax-loader-on-white.gif"> Bitte haben Sie einen Moment Geduld.</span>');
	  postObject = new Object; 
	  postObject.id = currentID;
	  aj = $.post('/ajax/getSnippet', postObject, 
		function(data){
			if ((data.valid) && (data.id == currentID))
			{
				$('#snippetPopupContent').html(data.snippet);
			}
			else
			{
				$('#snippetPopupContent').html('<span>Leider ist ein unbekannter Fehler aufgetreten.</span>');
			}
		}, "json" );
			
      container.css('display', 'block');
  });
 
  $('.snippetPopupTrigger').live('mouseout', function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
      hideTimer = setTimeout(function()
      {
          container.css('display', 'none');
      }, hideDelay);
  });
 
  $('#snippetPopupContainer').mouseover(function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
  });

  $('#snippetPopupContainer').mouseout(function()
  {
      if (hideTimer)
          clearTimeout(hideTimer);
      hideTimer = setTimeout(function()
      {
          container.css('display', 'none');
      }, hideDelay);
  });

});
