/* orangeSlides
 * Creates slideshow like presentations with jQuery
 *
 * @author David Bongard  (mail@bongard.net | www.bongard.net)
 * @version 0.9 - 20070601
 * @licence  http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * Copyright (c) 2007 David Bongard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

orangeSlides.init = function(number){
	$("#all_slides").html(slides.length);
	this.first();
	this.togglePlayback();
};
orangeSlides.go = function(number){
	if(this.currentSlide+number <= slides.length && this.currentSlide+number > 0){
		this.currentSlide = this.currentSlide+number;
	}
	$(this.containerId).fadeOut(this.transitionSpeed, function(){
		$(orangeSlides.containerId).html(slides[orangeSlides.currentSlide-1]).fadeIn(this.transitionSpeed);
		$("#current_slide").html(orangeSlides.currentSlide);
	});
};
orangeSlides.first = function(){
	this.go(eval('-'+this.currentSlide)+1);
};
orangeSlides.last = function(){
	this.go(slides.length-this.currentSlide);
};
orangeSlides.play = function(){
		if(this.currentSlide < slides.length){
			this.playbackTimeout = setTimeout('orangeSlides.go(1)',this.displayTime);
		}else{
			this.playbackTimeout = setTimeout('orangeSlides.first()',this.displayTime);
		}
		this.playbackTrigger = setTimeout('orangeSlides.play()',this.displayTime);
};
orangeSlides.togglePlayback = function(){
	if(this.playbackMode==1){
		this.play();
		$("#switch").html(this.pauseSymbol); // pause symbol
		this.playbackMode=0;
	}else{
		$("#switch").html(this.playSymbol); // play symbol
		clearTimeout(this.playbackTimeout);
		clearTimeout(this.playbackTrigger);
		this.playbackMode=1;
	}
};
