/* 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: 4000, //in milliseconds
	playbackMode: 0, //0 = pause, 1 = play
	transitionSpeed: 'fast', //'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)
slides = [
    '<img src="images/nonstock/084.jpg"/>', 
    '<img src="images/nonstock/085.jpg"/>', 
    '<img src="images/nonstock/086.jpg"/>', 
    '<img src="images/nonstock/087.jpg"/>', 
    '<img src="images/nonstock/088.jpg"/>', 
    '<img src="images/nonstock/089.jpg"/>', 
    '<img src="images/nonstock/090.jpg"/>', 
    '<img src="images/nonstock/091.jpg"/>', 
    '<img src="images/nonstock/092.jpg"/>', 
    '<img src="images/nonstock/093.jpg"/>', 
    '<img src="images/nonstock/094.jpg"/>', 
    '<img src="images/nonstock/095.jpg"/>', 
    '<img src="images/nonstock/096.jpg"/>', 
    '<img src="images/nonstock/097.jpg"/>', 
    '<img src="images/nonstock/098.jpg"/>', 
    '<img src="images/nonstock/099.jpg"/>'
];

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;
    }
};
