// Frank Scholz Computerservice
// Bruchköbel, 01.10.2007

// Update: 08.Feb.2008: Preload der Images, einbinden Special.js (Showroom)

var preLoad=[];
var moveactive=false;

function checkload(index)
{
  if (!preLoad[index].complete)
    setTimeout('checkload('+index+')', 100);
}


function browser_info(innerHeight,innerWidth,browser){
  this.innerHeight=innerHeight;
  this.innerWidth=innerWidth;
  this.browser=browser;
}


function slider(config)
{
   var z=0;
   var client = new browser_info();
   var floating=true;
   function preload()
   {
    for(n=0;n<config.images.length;n++)
    {
       preLoad[n]=new Image();
       preLoad[n].src=config.images[n];
       setTimeout('checkload('+n+')' ,n*100);
    }
  }

  function clientsize(element)
  {
    if (self.innerHeight) // all except Explorer
    {
	    client.innerWidth  = self.innerWidth;
	    client.innerHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    {
  	  client.innerWidth = document.documentElement.clientWidth;
    	client.innerHeight = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
  	  client.innerWidth = document.body.clientWidth;
	    client.innerHeight = document.body.clientHeight;
    }
    if ((config.direction=='left'||config.direction=='right')?(config.images.length-1)*config.width + 'px' :config.width > client.innerWidth - 198 - 40 +"px")
      element.style.width = client.innerWidth - 198  - 40 + "px";
    else
      element.style.width =(config.direction=='left'||config.direction=='right')?(config.images.length-1)*config.width+"px":config.width+"px";
    if((config.direction=='top'||config.direction=='bottom')?(config.images.length-1)*config.height + 'px':config.height> client.innerHeight/2-20+"px")
      element.style.height=client.innerHeight/2-20+"px";
    else
      element.style.height=(config.direction=='top'||config.direction=='bottom')?(config.images.length-1)*config.height+"px":(config.desc)?config.height+50+"px":config.height+"px";
  }

  if(isFinite(config.id)||!config.id)config.id='noid_'+Math.random();
  document.write("<div style='overflow:hidden;' id='"+config.id.replace(/[^a-zA-Z0-9]+/g,'_')+"'></div>");
  var bobj=document.getElementById(config.id.replace(/[^a-zA-Z0-9]+/g,'_'));
  bobj.style.overflow='hidden';
  bobj.style.border=config.border;
  bobj.title='';

  var pic_pos=[],images=[],pic_dimension=[],elements=[];
  var pos=new pos_config();

  var pic_index=config.images.length+1,pic_index_cap=2*config.images.length;
  
  function pos_config(init,last)
  {
    this.init=init;
    this.last=last;
  }

  function init()
  {
    if (!isFinite(config.interactive))
       config.interactive=false;
    if(config.direction=="left" || config.direction=="right")
    {
      direction=config.direction;
      dimension="width";
    }
    else if(config.direction=="top" || config.direction=="bottom")
    {
      direction=config.direction;
      dimension="height";
    }
   else
   {
      direction="left";
      dimension="width";
   }

    var pic=new Image();
    pos.init=-(config[dimension]+config.space);
    pic.style.width=config.width+"px";
    pic.style.height=config.height+"px";
    pic.style.border='none';
    var elementx=document.createElement('div');
    elementx.style.position='absolute';
    elementx.style[direction]=100+'px';
    elementx.style.width=config.width+"px";
    (config.desc)?elementx.style.height=config.height+30+"px":elementx.style.height=config.height+"px";
    var description=document.createElement('div');
    description.style.position='absolute';
    description.style.top=config.height+5+'px';

    for(var i=0;i<config.images.length;i++)
    {
      images[0]=pic.cloneNode(true);
      images[0].src=config.images[i];
      pos.last=(i*config[dimension]+i*config.space);
      elements[i]=elementx.cloneNode(true);
      elements[i].style[direction]=pos.last+"px";
      elements[i].id=config.id+"_"+i;
      elements[i+config.images.length]=elements[i];
      if(config.interactive)
      {
        elements[i].style.cursor='pointer';
        elements[i].onclick = function(){
          bobj.select(this.id.slice(config.id.length+1,this.id.length));
        }
      }
      if(config.desc)
      {
        var desc=description.cloneNode(true);
        var Text = document.createTextNode(config.desc[i]);
        desc.appendChild(Text);
        elements[i].appendChild(desc);
      }
      var z = bobj.appendChild(elements[i]);
      z.appendChild(images[0]);
    }
  }
  preload();
  init();

  bobj.transparency =function(value)
  {
    value=(typeof(value)=="undefined")?50:100-value;
    filterValue="Alpha(opacity="+value+")";
     // Wert fuer CSS opacity
     opacityValue=""+value/100;
     // Anzahl der passenden Elemente bestimmen
     bobj.style.filter=filterValue;
     bobj.style.MozOpacity=opacityValue;
     bobj.style.KhtmlOpacity=opacityValue;
     bobj.style.MozOpacity=opacityValue;
     bobj.style.opacity=opacityValue;
  }
  bobj.select =function(value)
  {
    var liste=[];
    if (moveactive)
      return;
    for(z=0,i=0;i<config.preview[value].length;i++)
    {
      if (config.preview[value][i]!=0)
      {
        liste[z]=(config.images[value].slice(0,config.images[value].search(/-/)+1)+(i+1)+'.jpg');
        z++;
      }
    }
    moveactive=true;
    special=window.setInterval('document.getElementById("'+config.special+'").move(0,"'+config.desc[value]+'","'+liste+'")',config.speed*6);
  }
  bobj.move = function()
  {
    clientsize(bobj);
    if (moveactive)
      bobj.transparency(15);
    else
      bobj.transparency(0);

    if ((!floating) || (moveactive))
      return;
    for(i=0;i<config.images.length;i++)
    {
      if (document.getElementById(config.id+"_"+i).style[direction].slice(0,document.getElementById(config.id+"_"+i).style[direction].length-2) == pos.last)
        document.getElementById(config.id+"_"+i).style[direction]=pos.init+"px";
      cPos = document.getElementById(config.id+"_"+i).style[direction].slice(0,document.getElementById(config.id+"_"+i).style[direction].length-2);
      cPos++;
      document.getElementById(config.id+"_"+i).style[direction]=cPos+"px";
    }
  }
  bobj.onmouseover = function()
  {
     if (config.interactive)
       floating=false;
  }
  bobj.onmouseout = function()
  {
     if (config.interactive)
     {
       floating=true;
     }
  }
  var action=window.setInterval('document.getElementById("'+bobj.id+'").move()',config.speed*10);
}


