//:PATCH: MG 2010.07.28 imCar gibt das carousel Object zurück
var imCar = false;
var imagecarousel = {
	itemVisibleInCallback: function(carousel, item, i, state, evt) {
		if (state == 'prev') {
			var idx = carousel.index(i);
			carousel.add(i, carousel.get(idx).html());
		}
	},
	itemVisibleOutCallback: function(carousel, item, i, state, evt) {
		if (state == 'next') {
			var indexes = imagecarousel.getCarouselIndexes(carousel);
			var idx = carousel.index(i);
			carousel.add((indexes[1] + 1), carousel.get(idx).html());
		}
	},
	getCarouselIndexes: function(carousel) {
		var first_index = carousel.prevFirst;
		var last_index = first_index;
		var ok = false;
		while (ok == false) {
			if (carousel.get(last_index).html() == null) {
				return [first_index, last_index-1];
			}
			last_index = last_index + 1;
		}
	},
	randomize: function(carousel, childElem) {
		var $this = jQuery(carousel);
		var elems = $this.children(childElem);
		elems.sort(function() { return (Math.round(Math.random())-0.5); });
		$this.remove(childElem);
		for(var i=0; i < elems.length; i++) {
			$this.append(elems[i]);
		}
	},
	/**
	 * Normal initCallback
	 */
	initCallback: function(carousel, state) {
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
		/* Deaktiviert am 15.02.2011
		carousel.buttonNext.bind('mouseover', function() {
			$(this).everyTime(10, 'nextImage', function() {
				carousel.next();
			});
		});
		
		carousel.buttonNext.bind('mouseout', function() {
			rzcolorboxOnReady();
			$(this).stopTime('nextImage');
			
		});
		
		carousel.buttonPrev.bind('mouseover', function() {
			$(this).everyTime(10, 'prevImage', function() { 
				carousel.prev();
			});
		});
		
		carousel.buttonPrev.bind('mouseout', function() {
			rzcolorboxOnReady();
			$(this).stopTime('prevImage');
			
		});
		*/
		//:PATCH: MG 2010.07.28
		imCar = carousel;
	},
	/**
	 * Mouseover initCallback
	 */
	initCallbackMouseover: function (carousel, state) {
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
		
		
		
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	}
};

