/* EASING METHODEN
'easeOutQuad', 'easeInQuad', 'easeInOutQuad', 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeInQuart', 'easeOutQuart', 'easeInOutQuart', 'easeInQuint', 'easeOutQuint', 'easeInOutQuint', 'easeInSine', 'easeOutSine', 'easeInOutSine', 'easeInExpo', 'easeOutExpo', 'easeInOutExpo', 'easeInCirc', 'easeOutCirc', 'easeInOutCirc', 'easeInElastic', 'easeOutElastic', 'easeInOutElastic', 'easeInBack', 'easeOutBack', 'easeInOutBack', 'easeInBounce', 'easeOutBounce', 'easeInOutBounce' 

BUTTONS: ids der Weiter und Back-Buttons muessen die id des Containers enthalten + '_back' oder id des Containers + '_weiter'
Bsp: id des containers 'ce_carousel, Weiter-Button: 'ce_carousel_weiter', Back-Button: 'ce_carousel_back'
*/

jQuery.fn.littleCarousel = function(options) {

var media = this;
var media_ul = jQuery(this).find("ul");
var media_li = jQuery(this).find("li");
var bild = jQuery(media_li).find("img");
var legende = jQuery(this).find(".leg_carousel");

var wrapper =  '#' + jQuery(this).attr('id') + '_wrapper';
var nav_back =  jQuery(wrapper).find(".navmitte_links");
var nav_vor =  jQuery(wrapper).find(".navmitte_rechts");
var goBack =  jQuery(wrapper).find(".carousel_goBack");
var goForward =  jQuery(wrapper).find(".carousel_goForward");

var zuruck =  '#' + jQuery(this).attr('id') + '_back';
var weiter =  '#' + jQuery(this).attr('id') + '_weiter';


var defaults = {
view: 500,
view_hoch:100,
bild_breit:100,
bild_hoch:100,
start:1,
paket: 5,
auto:0,
dauer:800,
bewegung:'swing'
};
  
var options = jQuery.extend(defaults, options);
var start = options.start;



var anz_pakete = Math.ceil(media_li.length / options.paket);
var position = media_ul.position();
var left = position.left;
var breit = media.innerWidth();
var bildabstand = parseInt((options.view - (options.paket * options.bild_breit)) / (options.paket - 1));
var vorlauf = options.view + bildabstand;
var breite_container = parseInt(anz_pakete * vorlauf);

/* MARGIN-TOP DER NAVI-PFEILE */
var marg_top = parseInt((options.bild_hoch - 30) / 2);


media.each(function() {

//alert("Hallo");
jQuery(wrapper).css({
'width': options.view + 'px'
});

media.css({
'height': options.view_hoch + 'px',
'width': options.view + 'px'
});

nav_back.css({
'height': options.view_hoch + 'px'
});

goBack.css({
'marginTop': marg_top + 'px'
});

nav_vor.css({
'height': options.view_hoch + 'px'
});

goForward.css({
'marginTop': marg_top + 'px'
});

media_ul.css({
/*'height': options.bild_hoch + 'px',*/
'width': breite_container + 'px'
});

bild.css({
'marginRight': bildabstand + 'px'
});

legende.css({
'marginRight': bildabstand + 'px'
});


if(options.start > 1) {
media_ul.css({
'left': '-' + ((start-1)*vorlauf) + 'px' 
});
}


jQuery(zuruck).click(function(e){
if(start > 1) {
var vo = (start - 2) * vorlauf;
media_ul.animate({
'left': '-' + vo + 'px'
}, {duration: options.dauer, easing: options.bewegung});
start -= 1;
} else {
media_ul.animate({
'left': '-' + ((anz_pakete - 1) * vorlauf) + 'px'
}, {duration: options.dauer, easing: options.bewegung});
start = anz_pakete;
}
e.preventDefault();
});


jQuery(weiter).click(function(e){
if(start < anz_pakete) {
var vo = start*vorlauf;
media_ul.animate({
'left': '-' + vo + 'px'
}, {duration: options.dauer, easing: options.bewegung});
start += 1;
} else {
media_ul.animate({
'left': '0px'
}, {duration: options.dauer, easing: options.bewegung});
start = 1;
}
e.preventDefault();
});



}); /* ENDE each */
} /* ENDE fn */
