/*
// ####################################################################################################
// # Datei inc.js-home.js V 1.0
// ####################################################################################################
// # Copyright © 2009 ISS-Oberlausitz
// # Author: T.Hojenski
// # Email: info@iss-ol.de
// # URL:   http://www.bluepage-cms.com
// # Diese Datei gehört zu dem kommerziellen bluepage - CMS der ISS-Oberlausitz
// # Bitte beachten Sie die Lizenzbedingungen.
// # Unberechtigte Nutzung, Änderung oder Weitergabe über die Lizenzbedingungen hinaus
// # sind strafbar.
// # Eine unberechtigte Verwendung auch von Teilen des CMS-Systems kann zu Schadensersatz-
// # und/oder Unterlassungsansprüchen führen.
// # Das Entfernen der Copyrighthinweise ist untersagt.
// ####################################################################################################
*/
/* DATEI: inc.js-ticker.js */


/* Javascript Datei BLUEPAGE CMS  */
/* Copyright by ISS-Oberlausitz */
/* Author: T.Hojenski */

xloadincTicker = true;

var iedom=document.all||document.getElementById
var ie=document.all&&!document.getElementById;
var DOM2=document.getElementById;


/* ******************************************************************************************************************************************************************* */

function bluepageTickerF(config) {
   /***********************************************
   * Originalscript: 
   * Fading Scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
   * This notice MUST stay intact for legal use
   * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
   * Anpassung ISS-Oberlausitz - Thomas Hojenski 05/2008 für bluepageCMS
   ***********************************************/
   this.config               = config;

   if(this.config!=undefined){
      if(this.config["content"]==undefined)              this.tickercontent = new Array(' ');  
      else                                               this.tickercontent = this.config["content"];
      if(this.config["tickerwidth"]==undefined)          this.tickerwidth = "996px"; //scroller width
      else                                               this.tickerwidth = this.config["tickerwidth"];
      if(this.config["tickerheight"]==undefined)         this.tickerheight = "30px"; //scroller height
      else                                               this.tickerheight = this.config["tickerheight"];
      if(this.config["bgcolor"]==undefined)              this.bgcolor = ""; //scroller background
      else                                               this.bgcolor = this.config["bgcolor"];
      if(this.config["boxClass"]==undefined)             this.boxClass = "box_jsticker"; //Border CSS, applied to scroller to give border.
      else                                               this.boxClass = this.config["boxClass"];

      if(this.config["tickerdelay"]==undefined)          this.tickerdelay = 2000; 
      else                                               this.tickerdelay = this.config["tickerdelay"];
      if(this.config["maxsteps"]==undefined)             this.maxsteps = 30; // number of steps to take to change from start color to endcolor
      else                                               this.maxsteps = this.config["maxsteps"];
      if(this.config["stepdelay"]==undefined)            this.stepdelay = 40; // time in miliseconds of a single step  //**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
      else                                               this.stepdelay = this.config["stepdelay"];
      if(this.config["startcolor"]==undefined)           this.startcolor = new Array(130,72,34); // start color (red, green, blue)
      else                                               this.startcolor = this.config["startcolor"];
      if(this.config["endcolor"]==undefined)             this.endcolor   = new Array(255,255,255);  // end color (red, green, blue)
      else                                               this.endcolor = this.config["endcolor"];
   }

   this.fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.
   this.fadecounter;
   this.index=0;

   var thisobj = this;

   if (iedom) {
     //document.write('<div id="fscroller" class="'+this.boxClass+''+this.bgcolor+'" style="width:'+this.tickerwidth+';height:'+this.tickerheight+'"></div>');
   }
   if (window.addEventListener) {
      window.addEventListener("load", function () { thisobj.changecontent() }, false)
   } else if (window.attachEvent) {
      window.attachEvent("onload", function () { thisobj.changecontent() })
   } else if (document.all || document.getElementById) {
      window.onload=this.changecontent
   }
}

bluepageTickerF.prototype.changecontent = function () {
   if (this.index>=this.tickercontent.length) {
      this.index=0
   }
   if (DOM2){
      document.getElementById("fscroller").style.color="rgb("+this.startcolor[0]+", "+this.startcolor[1]+", "+this.startcolor[2]+")"
      document.getElementById("fscroller").innerHTML='<span class="box_jsticker_div">'+this.tickercontent[this.index]+'</span>'
      if (this.fadelinks) this.linkcolorchange(1);
      this.colorfade(1, 15);
   } else if (ie4) {
      document.all('fscroller').innerHTML='<span class="box_jsticker_div">'+this.tickercontent[this.index]+'</span>';
   }
   this.index++
}

bluepageTickerF.prototype.linkcolorchange = function (step) {
   var obj=document.getElementById("fscroller").getElementsByTagName("A");
   if (obj.length>0){
      for (i=0;i<obj.length;i++) { 
         obj[i].style.color=this.getstepcolor(step);
      }
   }
}

bluepageTickerF.prototype.colorfade = function (step) {
   var thisobj = this;
   if(step<=this.maxsteps) {	
       document.getElementById("fscroller").style.color=this.getstepcolor(step);
       if (this.fadelinks) this.linkcolorchange(step);
       step++;
       this.fadecounter=setTimeout( function () { thisobj.colorfade(step) } ,this.stepdelay);
   } else {
      clearTimeout(this.fadecounter);
      document.getElementById("fscroller").style.color="rgb("+this.endcolor[0]+", "+this.endcolor[1]+", "+this.endcolor[2]+")";
      setTimeout( function () { thisobj.changecontent() } ,this.tickerdelay);
   }   
}

bluepageTickerF.prototype.getstepcolor = function (step) {
   var diff
   var newcolor=new Array(3);
   for(var i=0;i<3;i++) {
      diff = (this.startcolor[i]-this.endcolor[i]);
      if(diff > 0) {
         newcolor[i] = this.startcolor[i]-(Math.round((diff/this.maxsteps))*step);
      } else {
         newcolor[i] = this.startcolor[i]+(Math.round((Math.abs(diff)/this.maxsteps))*step);
      }
   }
   return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}


