/**
 * content.simple.slideshow.js - insert headline here
 *
 * COPYRIGHT: All  title   and  proprietary  rights,  including  trade
 * secrets,   in   the   Software   and   any   copies thereof and the
 * accompanying  written   materials,   are  owned  by   schukai  GmbH
 * and  are  protected  by  German  copyright  laws,  other applicable
 * copyright   laws  and  international  treaty  provisions.
 *
 * @package    alvine
 * @author     schukai GmbH <info@schukai.de>
 * @copyright  Copyright (C) 2002, 2003, 2004, 2005, 2006 schukai GmbH
 * @license    http://www.alvine.de/license/
 * @version    20061114
 * @link       http://www.alvine.de/
 */
 
function content_frontend_plugin_content_simple_slideshow_init(){

}

if(typeof slideshow == 'undefined') {
  var slideshow = new Object();
}

function slideshow_addPreloadIndex(boxID){
  slideshow[boxID]['preload_count']++;
}

function slideshow_addImage(boxID, imageUrl, imageTitle, slideSpeed, slideAngle){

  if(typeof slideshow[boxID] == 'undefined') slideshow[boxID] = new Object();
  if(typeof slideshow[boxID].preload_count == 'undefined') slideshow[boxID].preload_count = 0;
  if(typeof slideshow[boxID].images == 'undefined') slideshow[boxID].images = new Array();
  
  var imageData = new Object();
  imageData.obj = document.createElement('IMG');
  imageData.obj.src = imageUrl;
  imageData.obj.onload = "slideshow_addPreloadIndex('"+boxID+"')";
  imageData.url = imageUrl;
  imageData.title = (typeof imageTitle != 'undefined')?imageTitle:'image';
  imageData.alvine_slideSpeed = (!isNull(slideSpeed))?slideSpeed:100;
  imageData.alvine_slideAngle = (!isNull(slideAngle))?slideAngle:12;
  
  slideshow[boxID].images.push(imageData);
  
}

function slideshow_getImages(boxID){
  
  return slideshow[boxID];
}


function slideshow_init(boxID, speed, maxImages){
  var imagesData = slideshow_getImages(boxID);
  /*
  var preloadReady = false;

  while(!preloadReady){
    if(maxImages != imagesData.preload_count) continue;

    preloadReady = true;
  }
  */
  if(typeof imagesData.index == 'undefined') slideshow[boxID].index = 0;
  
  slideshow_setImage(boxID);
    
  var timerID = setInterval('slideshow_changeImage("'+boxID+'")', speed);

  //slideshow_changeImage(boxID);
}


function slideshow_changeImage(boxID){
  
  var imagesData = slideshow_getImages(boxID);
  var index = imagesData.index;
  
  if(typeof imagesData.images[index] == 'undefined') {
    index = 0;
    slideshow[boxID].index = index;
  }
  
  slideshow_setImage(boxID);  
}

//var effectAppear = new Object();

function slideshow_setImage(boxID){
  var panelObj = element_isObject(boxID);
  var imageObj2 = element_isObject(boxID+'_image_back');  
  var imageObj = element_isObject(boxID+'_image_front');
  
  var imagesData = slideshow_getImages(boxID);
  var index = imagesData.index;
 
  imageObj2.src = imageObj.src;

  element_setOpacity(imageObj, 0);
  imageObj.src   = imagesData.images[index].url;
  imageObj.title = imagesData.images[index].title;

  effects_fade(imageObj, 100, 'now', imagesData.images[0].alvine_slideSpeed, imagesData.images[0].alvine_slideAngle);
  
  slideshow[boxID].index++;
}
