var textf_t = 100; // oberer Abstand des Textfeldes im Fenster
var textf_l =100; //linke obere Ecke des Textfeldes im Fenster
var textf_b = 780; // Breite des Textfeldes
var textf_h = 400; // Höhe des Textfeldes (abhängig von der Menge des Textes; sollte zuerst immer mit sehr großen Werten getestet werden, da ansonsten der Text nicht bis zum Ende gelesen werden kann
var textr_h = 400; // Höhe des Textrahmens, der bestimmt wieviel Text sichtbar ist
var farbe = "0062ff"; // RGB-Farbe der Schrift und der Ränder

if(window.location.search != "")
{
 var temp = window.location.search;
 temp = temp.substring(1,temp.length);
 temp = temp.split("&");
 for(i=0;i<temp.length;i++)
 {
  var z = temp[i].indexOf("=");
  temp[i] = temp[i].substring((z+1),temp[i].length);
 }
 if(temp[0] != "")
 {
  textr_h = Number(temp[0]);
  if(textr_h > textf_h)
   textf_h = textr_h;
 }
 if(temp[1] != "")
  textf_b = Number(temp[1]);
 if(temp[2] != "")
  textf_l = Number(temp[2]);
 if(temp[3] != "")
  textf_t = Number(temp[3]);
 if(temp[4] != "")
  farbe = temp[4];
}

var scf_min = 5; // Mindesthöhe des Scrollbalkens
var scf_b = 16; // Breite des Scrollers
var tf_sc = 10; // Abstand des Scrollers vom Textfeld

var pfeil_h = 16; // Höhe des Scroll-Pfeils
var pfeil_b = scf_b; // Breite des Scroll-Pfeils

var scf_l = (textf_l+textf_b+tf_sc); // Linke obere Ecke des Scrollers
var max_up,max_down,make_scroll,texttext,scroll_balk,sc_h,scf_h,hoch,text_oben,stop=hold_m=xxx=tf_oben=0,pi=1;
var inhalt = '<table style="width:'+textf_b+'px;"  border="0" cellspacing="0" cellpadding="0">\t<tr>\t<td colspan="3" style="height:35px; padding-left:15px; padding-top:5px" valign="top" class="us">Das Skript!</td>\t</tr>\t<tr>\t<td colspan="3" style="height:150px;padding-left:15px; padding-right:10px" valign="top" align="center" class="plain"><p>Du kannst den Code direkt hier kopieren oder dir unten als zip-Datei herunterladen. Es enth&auml;lt auch Hinweise zur Anpassung und zum Einbau.</p></td>\t</tr>\t<tr>\t<td style="background-color:#'+farbe+'; width:35%; height:50px" align="right"><input onclick="history.back()" type="button" value="Zum Ergebnis zur&uuml;ck"></input></td>\t<td style="background-color:#'+farbe+'; width:30%; height:50px" align="center"><input type="button" onclick="start()" value="Zur&uuml;ck auf Start"></input></td>\t<td style="background-color:#'+farbe+'; width:35%; height:50px; color:#ffffff" align="center"><a class="pln" href="scroller.zip" type="application/zip">Download</a></td>\t</tr>\t';


function init()
{
 texttext = document.getElementById("textfeld");
 sc_h = scf_min;
 scf_h = textr_h-(2*pfeil_h);
 texttext.style.clip = "rect(0px,"+textf_b+"px,"+textr_h+"px, 0px)";
 if(textf_h > textr_h)
 {
  if((textf_h-textr_h) > (scf_h - sc_h))
   pi = Math.floor((textf_h-textr_h)/(scf_h - sc_h));
  else
   sc_h = scf_h-(textf_h - textr_h);
  write_scroller();
  scroll_balk = document.getElementById("scroller");
  max_up = textf_t+pfeil_h;
  hoch = (sc_h + (2*pfeil_h));
  max_down = (max_up+(textr_h-hoch));
 }
 else
  write_noscroll();
}

function write_scroller()
{
 document.write('<div id="scroller" style="position:absolute; visibility:visible; z-Index:5; width:'+scf_b+'px; height:'+sc_h+'px; top:'+(textf_t+pfeil_h)+'px; left:'+scf_l+'px; border:solid 1px #'+farbe+'"><table style="width:'+scf_b+'px; height:'+sc_h+'px; background-color:#'+farbe+'"  border="0" cellspacing="0" cellpadding="0"><tr><td style="width:'+scf_b+'px; height:'+sc_h+'px;" align="center" valign="middle" class="imgcell"><a onmousedown="beginDrag('+"'scroller'"+',event);return false" href="#"><img border="0" width="'+scf_b+'" height="'+sc_h+'" src="but/pix0.gif"></a></td></tr></table></div>');
 document.write('<div style="position:absolute; visibility:visible; z-Index:3; width:'+scf_b+'px; height:'+textr_h+'px; top:'+textf_t+'px; left:'+scf_l+'px; border:solid 1px #'+farbe+'"><table style="width:'+scf_b+'px; height:'+textr_h+'px;" border="0" cellspacing="0" cellpadding="0"><tr><td style="width:'+scf_b+'px; height:'+pfeil_h+'px; border-bottom:solid 1px #'+farbe+'; background-color:#'+farbe+'" align="center" valign="center" class="imgcell"><a onmousedown="pf_scroll(4);return false" onmouseout="stop_scrolling()" onmouseup="stop_scrolling()" href="#"><img src="but/pfeilwd.gif" border="0" alt="Pfeil nach unten"></a></td></tr><tr><td style="width:'+scf_b+'px; height:'+(textr_h-(2*pfeil_h)-2)+'px;" align="center" valign="center" class="imgcell"><img src="but/pix0.gif" width="'+scf_b+'" height="'+(textr_h-(2*pfeil_h)-2)+'" border="0" alt="Scrollfläche"></td></tr><tr><td style="width:'+(textr_h-(2*pfeil_h)-2)+'px; height:'+pfeil_h+'px; border-top:solid 1px #'+farbe+'; background-color:#'+farbe+'" align="center" valign="center" class="imgcell"><a onmousedown="pf_scroll(-4);return false" onmouseout="stop_scrolling()" onmouseup="stop_scrolling()" href="#"><img src="but/pfeilwu.gif" border="0" alt="Pfeil nach oben"></a></td></tr></table></div>');
}

function write_noscroll()
{
 document.write('<div style="position:absolute; visibility:visible; z-Index:3; width:'+scf_b+'px; height:'+textf_h+'px; top:'+textf_t+'px; left:'+scf_l+'px; border:solid 1px #'+farbe+'"><table style="width:'+scf_b+'px; height:'+textf_h+'px;" border="0" cellspacing="0" cellpadding="0"><tr><td style="width:'+pfeil_h+'px; height:'+pfeil_h+'px; border-bottom:solid 1px #'+farbe+'" align="center" valign="center" class="imgcell"><img src="but/pix0.gif" border="0" alt="Leerbild statt Pfeil nach unten"></td></tr><tr><td style="width:'+scf_b+'px; height:'+(textf_h-(2*pfeil_h)-2)+'px;" align="center" valign="center" class="imgcell"><img src="but/pix0.gif" width="16" height="'+(textf_h-(2*pfeil_h)-2)+'" border="0" alt="Leerbild statt Scrollfläche"></td></tr><tr><td style="width:'+pfeil_b+'px; height:'*pfeil_h+'px; border-top:solid 1px #'+farbe+'" align="center" valign="center" class="imgcell"><img src="but/pix0.gif" border="0" alt="Leerbild statt Pfeil nach oben"></td></tr></table></div>');
}

function write_textfeld()
{
 if(screen.width <= 800)
 document.write('<div id="textfeld800" style="position:absolute; visibility:visible; z-Index:3; width:'+textf_b+'px; height:'+textf_h+'px; top:'+textf_t+'px; left:'+textf_l+'px;"><table style="width:'+textf_b+'px; height:'+textf_h+'px; border:solid 1px #'+farbe+'" border="0" cellspacing="0" cellpadding="0">');
else
{
 document.write('<div id="textrahmen" style="position:absolute; visibility:visible; z-Index:3; width:'+textf_b+'px; height:'+textr_h+'px; top:'+textf_t+'px; left:'+textf_l+'px; border:solid 1px #'+farbe+'"><table style="width:'+textf_b+'px; height:'+textr_h+'px;"  border="0" cellspacing="0" cellpadding="0"><tr><td style="width:'+textf_b+'px; height:'+textr_h+'px;">&nbsp;</td></tr></table></div>');
 document.write('<form action="scroller.html" name="test" id="test">\t<div id="textfeld" style="position:absolute; visibility:visible; z-Index:3; width:'+textf_b+'px; height:'+textf_h+'px; top:'+textf_t+'px; left:'+textf_l+'px;">\t'+inhalt+'</td>\t</tr>\t</table>\t</div>\t</form>');

 }
}

function start()
{
 location.href = "scroller.html";
}

function skript()
{
 location.href = "sroller.zip";
}

function scrollen(x)
{
 x = x*(-1);
 xxx += (x*pi);
 var on = "rect("+(tf_oben+xxx)+"px," +textf_b+"px, "+(textr_h+xxx)+"px, 0px)";
 texttext.style.clip = on;
 texttext.style.top = (textf_t-xxx)+"px";
}

function pf_scroll(x)
{
 var sb = parseInt(scroll_balk.style.top)
 var sbb = (sb-x);
 if((sbb >= max_up) &&  (sbb <= max_down))
 {
  scroll_balk.style.top = sb-x+"px";
  scrollen(x);
  stop = 0;
  make_scroll = setTimeout("pf_scroll("+x+")",100);
 }
}

function stop_scrolling()
{
 if(stop == 0)
 {
 stop = 1;
 if(make_scroll)
  clearTimeout(make_scroll);
 var sb = parseInt(scroll_balk.style.top);
 hold_m = sb;
 }
}

function beginDrag(etd,event)
{
  if (!etd) etd = this;
  if (!event) event = window.event;
  etd = document.getElementById(etd);
  etd.style.zIndex = 5;
  var y = parseInt(etd.style.top);
  var dy = event.clientY - y;
  if (document.addEventListener)
  {
    document.addEventListener("mousemove",moveHandler, true);
    document.addEventListener("mouseup",upHandler, true);
  }
  else if (document.attachEvent)
  {
    document.attachEvent("onmousemove", moveHandler);
    document.attachEvent("onmouseup", upHandler);
  }
  if (event.stopPropagation)
   event.stopPropagation();
  else event.cancelBubble = true;
  if (event.preventDefault)
   event.preventDefault();
  else
   event.returnValue = false;

  function moveHandler(event)
  {
    if (!event) event=window.event;
    var m = (event.clientY - dy);
    if(!hold_m)
     hold_m = m;
    if((m >= max_up) && (m < max_down))
    {
     etd.style.top = m + "px";
     var st = hold_m - m;
     if(st != 0)
      scrollen(st);
     hold_m = m;
    }
    if (event.preventDefault) event.preventDefault();
    else event.returnValue = false;
  }
  function upHandler(event)
  {
    if (!event) event=window.event;
    if (document.removeEventListener)
    {
     document.removeEventListener("mouseup", upHandler, true);
     document.removeEventListener("mousemove", moveHandler, true);
    }
    else
    {
     document.detachEvent("onmouseup", upHandler);
     document.detachEvent("onmousemove", moveHandler);
    }
    if (event.stopPropagation) event.stopPropagation();
    else event.cancelBubble = true;
  }
}
