// Showing an element an scroll to it
$.fn.betterSlide = function(destination) {
	// where in px from top is the element?
    var dest = $(destination).offset().top;
	// show the element and as callback scroll it into the viewport (if not animated)
    jQuery(this).show(1, function() {
		jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: dest}, 2000, "swing" );
	});
};
(function($){
	$.fn.addCaption = function(options) {
		var defaults = {
			wrapClass: 'teaserbox',
			altText: 'entweder ein leeres oder kein alt-Attribut verwendet'
		};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var obj = $(this);
			var indWrapClass = options.wrapClass;
			if(obj.hasClass("right")){
				indWrapClass += " right";
			}
			if($(this).hasClass("left")){
				indWrapClass += " left";
			}	
			var capText = obj.attr('alt');
			if(capText == '') capText = options.altText;
			obj.wrap('<div class="'+indWrapClass+'">').after('<p>').next("p").text(capText);
		});
	};
})(jQuery);
 
jQuery(document).ready(function(){
	jQuery("#s").click(function(){
		jQuery(this).attr('value','');
	});
	jQuery("#showmore a").click(function() {
	    $("#moreinfo").betterSlide("#showmore");
		jQuery(this).parent("p").slideUp("slow");
		return false;
	});
	
	$("#banner .maske ul").data("pos", 0);
	
	$("#banner .maske .sleft").hide();
	
	$("#banner .maske .sright").click(function() {

        var pos = $("#banner .maske ul").data("pos");
        pos -= 800;
        if (pos == -2400) $(this).fadeOut();
        if(pos == -800) $("#banner .maske .sleft").fadeIn();
        
        $("#banner .maske ul").data("pos", pos);


        $("#banner .maske ul").animate({
            left: $("#banner .maske ul").data("pos"),
            opacity: 1
        },
        750);
        return false;
    });
    
    $("#banner .maske .sleft").click(function() {

        var pos = $("#banner .maske ul").data("pos");
        pos += 800;
        if (pos == 0) $(this).fadeOut();
        if(pos == -1600) $("#banner .maske .sright").fadeIn();
        
        $("#banner .maske ul").data("pos", pos);


        $("#banner .maske ul").animate({
            left: $("#banner .maske ul").data("pos"),
            opacity: 1
        },
        750);
        return false;
    });
    $("img.withLegend").addCaption();
});