
var slider_pos = 0;
var slider_widths = [];
var slider;

$(window).load(function(){

    $('.image_silder').each(function(){
        slider = $(this);
        var images = $(this).children('img');

        if ( images.length > 1){
            // Wie groß brauchen wir das alles so?
            var max_height = 0;
            var max_width = 0;
            $(images).each(function(){
                if ( $(this).height() > max_height ) max_height = $(this).height();
                if ( $(this).width() > max_width ) max_width = $(this).width();
            });

            var slider_width = 0;
            var slider_code = '';
             $(images).each(function(){
                 slider_widths.push(slider_width);
                slider_code += '<img src="'+$(this).attr('src')+'" alt="'+$(this).attr('alt')+'" style="position: absolute; left: '+slider_width+'px;">';
                slider_width += $(this).width();
            });
            // Initialisieren
            $(images).remove();
            $(slider).css({
                'position': 'relative',
                'display' : 'block',
                'width' : max_width+'px',
                'height' : max_height+'px',
                'overflow': 'hidden'
            });
            $(slider).append('<div>'+slider_code+'</div>');
            $(slider).children('div').css({
                'position': 'absolute',
                'display' : 'block',
                'width' : slider_width+'px',
                'height' : max_height+'px',
                'overflow' : 'hidden'
            });




            var slider_pos = (max_height - 45) / 2;
            slider.append( '<img src="img/slider_left.png" onClick="slide_left();" class="slider_button" style="left: 15px">' );
            slider.append( '<img src="img/slider_right.png" onClick="slide_right();" class="slider_button" style="right: 15px">' );
            slider.children('.slider_button').css({
                position: 'absolute',
                top: slider_pos+'px',
                cursor: 'pointer'
            });

        }

    });

});


function slide_left(){
    slider_pos -= 1;
    while ( slider_pos < 0 ) slider_pos += slider_widths.length;
    $(slider).children('div').animate({marginLeft: -1*slider_widths[slider_pos]});
}
function slide_right(){
    slider_pos += 1;
    while ( slider_pos >= slider_widths.length ) slider_pos -= slider_widths.length;
    $(slider).children('div').animate({marginLeft: -1*slider_widths[slider_pos]});
}


