jQuery.fn.simpleSpy = function (limit, interval) {
    limit = limit || 8;
    interval = interval || 6000;
    
    return this.each(function () {
        // 1. setup
            // capture a cache of all the list items
            // chomp the list down to limit li elements
        var $list = jQuery(this),
            items = [], // uninitialised
            currentItem = limit,
            total = 0, // initialise later on
            height = $list.find('> li:first').height();
            
        // capture the cache
        $list.find('> li').each(function () {
            items.push('<li>' + jQuery(this).html() + '</li>');
        });
        
        total = items.length;
        
        $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit});
        jQuery('#rightside').css({height : height * limit + 50});
        $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

        // 2. effect        
        function spy() {
            // insert a new item with opacity and height of zero
            var $insert = jQuery(items[currentItem]).css({
                height : 0,
                opacity : 0,
                display : 'none'
            }).prependTo($list);
                        
            // fade the LAST item out
            $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
                // increase the height of the NEW first item
                $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
                
                // AND at the same time - decrease the height of the LAST item
                // $(this).animate({ height : 0 }, 1000, function () {
                    // finally fade the first item in (and we can remove the last)
                    jQuery(this).remove();
                // });
            });
            
            currentItem++;
            if (currentItem >= total) {
                currentItem = 0;
            }
            
            setTimeout(spy, interval)
        }
        
        spy();
    });
};

var show = 1;
var showSearch = 1;
		jQuery(window).load(function () { 
		    //jQuery("ul#ticker").liScroll({travelocity: 0.05}); 
        jQuery("h3#showcontact").click(function () {           
          if(show == 1){
            show = 0;
            jQuery(".test").show("slow");
          }
          else{
            show = 1;
            jQuery(".test").hide("slow");
          }
      });
      jQuery("h3#showsearch").click(function () {           
          if(showSearch == 1){
            showSearch = 0;
            jQuery("#showformsearch").show("slow");
          }
          else{
            showSearch = 1;
            jQuery("#showformsearch").hide("slow");
          }
      });
    });

function submitContactForm (form) {
		var the_button =  document.getElementById('submit');
		var toFocus = null;
		var focusSet = 0;
		errors = new Array();
		if(!document.getElementById('user-name').value.length) {
		  if(focusSet == 0){ toFocus = 'user-name';focusSet = 1;}
			errors.push('Bitte geben Sie ihren Namen ein.');
		}
		if(!document.getElementById('user-email').value.length) {
		  if(focusSet == 0){ toFocus = 'user-email';focusSet = 1;}
			errors.push('Bitte geben Sie ihre E-Mail ein.');
		}
		if(!document.getElementById('user-comment').value.length) {
		  if(focusSet == 0){ toFocus = 'user-comment';focusSet = 1;}
			errors.push('Bitte geben Sie eine Nachricht ein.');
		}
		if(errors.length) {
		  document.getElementById(toFocus).focus();
			var message = "Es wurden nicht alle Pflichfelder ausgefüllt:\n\n";
			for(i = 0; i < errors.length; i++) {
				message += errors[i] + "\n";
			}
			alert(message);
			return false;
		}
		return true;
	}
	
jQuery.fn.liScroll = function(settings) {

		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var defTiming = stripWidth/settings.travelocity;
				var totalTravel = stripWidth+containerWidth;	
											
				function scrollnews(spazio, tempo){
				 $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};
