/* 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.
 */

//configuration
orangeSlides = {
	displayTime: 10000, //in milliseconds
	playbackMode: 1, //0 = pause, 1 = play
	transitionSpeed: 1950, //'fast', 'normal', 'slow' or milliseconds
	currentSlide: 1,
	playSymbol: 'Play',
	pauseSymbol: '<img src="images/tiny_red.gif" border="0" /> Pause',
	containerId: '#slide'
};
//getting the data (JSON)
data = '["<img src=\\"images/slide/2.jpg\\" >",'
+ '"<img src=\\"images/slide/3.jpg\\" >",'
+ '"<img src=\\"images/slide/4.jpg\\" >",' 
+ '"<img src=\\"images/slide/5.jpg\\" >",'
+ '"<img src=\\"images/slide/6.jpg\\" >",' 
+ '"<img src=\\"images/slide/7.jpg\\" >",' 
+ '"<img src=\\"images/slide/8.jpg\\" >",' 
+ '"<img src=\\"images/slide/9.jpg\\" >",' 
+ '"<img src=\\"images/slide/10.jpg\\" >",' 
+ '"<img src=\\"images/slide/11.jpg\\" >",' 
+ '"<img src=\\"images/slide/12.jpg\\" >",' 
+ '"<img src=\\"images/slide/13.jpg\\" >",' 
+ '"<img src=\\"images/slide/14.jpg\\" >",'
+ '"<img src=\\"images/slide/15.jpg\\" >",'
+ '"<img src=\\"images/slide/16.jpg\\" >",' 
+ '"<img src=\\"images/slide/17.jpg\\" >"]';
slides = eval(data);

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;
	}
};
//init
$(document).ready(function() {
	orangeSlides.init();
});
