/*
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lib.js
Script library for KABEG

Version:             1.0
Last Changed:        2006-08-16

manfred.schneiderbauer@world-direct.at
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/

// firefox/AllOS and Gecko/Mac have a smaller default font size, so increase it there
try{
if((!isMac&&navigator.userAgent.indexOf('Firefox')!=-1)||(isGecko&&isMac))
	{
	var r=document.styleSheets[2].cssRules; // ref to clib's CSS #2 (browser specific CSS)
	var rr='';var thisFs='';var fsMode='';
	for(var i=0;i<r.length;i++)
		{
		if(r[i].style.fontSize)
			{
			thisFs=r[i].style.fontSize;
			if(thisFs.indexOf('em')!=-1){fsMode='em';}
			if(thisFs.indexOf('pt')!=-1){fsMode='pt';}
			if(thisFs.indexOf('px')!=-1){fsMode='px';}
			thisFs=Number(r[i].style.fontSize.replace('em','').replace('pt','').replace('px',''));
			thisFs+=.2;
			r[i].style.fontSize=thisFs+fsMode;
			}
		}
	}
}catch(error){}

// permanently center the teaser images in the home page
function centerTeasers(){
try{
if(document.body)
  {
    if(document.body.innerHTML)
      {
        if(isIE5up)
          {
            d('tdFooter').style.position='relative';d('tdFooter').style.top='-4px';
            d('tdMiddleMenu').style.position='relative';d('tdMiddleMenu').style.top='-4px';
            if(d('tdMain')){d('tdMain').style.position='relative';d('tdMain').style.top='-4px';}
          }

        if(d('dvHeadImgTeasers'))
          {
            var ww=0;
            if(isIE5up){ww=document.body.clientWidth;}else{ww=window.innerWidth;}
            d('dvHeadImgTeasers').style.left=Number(ww/2-369)+'px';
          }
      } else {window.setTimeout("centerTeasers();",250);}
  } else {window.setTimeout("centerTeasers();",250);}
window.setTimeout("centerTeasers();",100);
}catch(error) {window.setTimeout("centerTeasers();",250);}
}
//centerTeasers();

// scale the fonts
function fontScaler(cmd){
var toScale=''

// -- BEGIN CONFIG --------------------------------------------------------
//
// Modification elements and values:
// Command set that defines which elements in the page are to be modified which way
// Data format:   '[mode]|[id]|[value]#'
//                [mode] can be 'class' or 'id' or 'html'
//                [id] is the identifier, either class name or ID or element name
//                         - class name accessses multiple elements, if any
//                           and additionally needs a tag name, separated by a comma
//                [value] is the per-step-value to add to or to subtract from the current fontSize value
//
//                Examples:
//                In-/decrease DIV elements with class name 'myClass' by 1: 'class,div|myClass|1#'
//                In-/decrease the element with ID 'myElement' by 2: 'id|myElement|2#'
//                In-/decrease all UL elements by 3: 'html|ul|3#'
toScale+='class,h1|csc-firstHeader|1#';
toScale+='html|h2|1#';
toScale+='class,p|bodytext|2#';
toScale+='id|searchform|1#';
toScale+='html|li|2#';
//
// Scaling offset:
// Positive number; defines the maximum of steps to scale
var scalingOffset=2;
//
// Scaling menu class names:
// Strings; define the class names for the 'Increase' and 'decrease' texts
var increaseClassName='fontscaler_bigger';
var decreaseClassName='fontscaler_smaller';
var inactiveClassName='fontscaler_inactive'; // additional properties for inactive link
//
// Scaling menu texts:
// Strings; define the text output
var increaseText='A+';
var decreaseText='-A';
//
// -- END CONFIG --------------------------------------------------------

// handle cookie

var scalingVal=0; var noSet=false;
try{scalingVal=Number(getCookie('fontscaler_scalingVal'));}catch(error){}
if(!scalingVal||Number(scalingVal==0)){scalingVal=0;}
if(cmd=='+')
  {
   if(scalingVal<scalingOffset)
    {
     scalingVal++;
     setCookie('fontscaler_scalingVal',scalingVal);
    } else {
     noSet=true;
    }
  } else if (cmd=='-')
  {
   if(scalingVal>(0-scalingOffset))
    {
     scalingVal=scalingVal-1;
     setCookie('fontscaler_scalingVal',scalingVal);
    } else {
     noSet=true;
    }
  }

// init
var i=0; var c=0;
var tsArr=toScale.split('#'); var thisCmd=''; var thisMethod=''; var thisId=''; var thisVal=''; var thisMethodM=''; var thisMethodE=''; var thisElements=''; var thisFs=''; var thisOrgFs='';

// write links
if(!cmd){document.write('<span id="spFontscalerDec" class="clib_link '+decreaseClassName+'" onclick="fontScaler(\'-\');">'+decreaseText+'</span> <span id="spFontscalerInc" class="clib_link '+increaseClassName+'" onclick="fontScaler(\'+\');">'+increaseText+'</span>');}

// set style.height to enable opacity on IE
// try catch -> splash screen exception (hansjoerg.broederbauer)
try {
if(isIE5up||isIE55up)
  {
  d('spFontscalerDec').style.height=d('spFontscalerDec').offsetHeight+'px';
  d('spFontscalerInc').style.height=d('spFontscalerInc').offsetHeight+'px';
  }

// mark links as active or inactive

if(scalingVal==(0-scalingOffset))
  {
   d('spFontscalerDec').className=decreaseClassName+' '+inactiveClassName;
  } else {
   d('spFontscalerDec').className=decreaseClassName+' '+'clib_link';
  }
 
if(scalingVal==scalingOffset)
  {
   d('spFontscalerInc').className=increaseClassName+' '+inactiveClassName;
  } else {
   d('spFontscalerInc').className=increaseClassName+' '+'clib_link';
  }
}catch (exception){}
	
	
if(cmd){

for (i=0;i<tsArr.length-1;i++) // go thru all configured elements
  {
    thisCmd=tsArr[i].split('|');
    thisMethod=thisCmd[0]; thisId=thisCmd[1]; thisVal=Number(thisCmd[2]);

    // set by class name
    try{
    if(thisMethod.indexOf('class')!=-1)
      {
        thisMethodM=thisMethod.split(',')[0]; thisMethodE=thisMethod.split(',')[1];
        thisElements=getElementsByClass(thisMethodE,thisId);
        for(c=0;c<thisElements.length;c++)
          {
           if(isIE5up||isIE55up)
            {
             thisFs=thisElements[c].currentStyle.fontSize.replace('px','');
            } else {
             thisFs=document.defaultView.getComputedStyle(thisElements[c],'').getPropertyValue('font-size').replace('px','');
            }
           thisFs=Number(thisFs);
           if(!noSet)
            {
            if(cmd=='+'){thisFs+=thisVal;}else if(cmd=='-'){thisFs=thisFs-thisVal;}
            if(cmd=='restore'&&scalingVal>0){thisFs+=(thisVal*scalingVal);}
            if(cmd=='restore'&&scalingVal<0){thisFs=thisFs-(thisVal*(0-scalingVal));}
            thisElements[c].style.fontSize=thisFs+'px';
            }
          }
      }
      }catch(error){}

      // set by id
    try{
    if(thisMethod.indexOf('id')!=-1)
      {
        thisElements=d(thisId);
        if(isIE5up||isIE55up)
         {
          thisFs=thisElements.currentStyle.fontSize.replace('px','');
         } else {
          thisFs=document.defaultView.getComputedStyle(thisElements,'').getPropertyValue('font-size').replace('px','');
         }
        thisFs=Number(thisFs);
        if(!noSet)
         {
         if(cmd=='+'){thisFs+=thisVal;}else if(cmd=='-'){thisFs=thisFs-thisVal;}
         if(cmd=='restore'&&scalingVal>0){thisFs+=(thisVal*scalingVal);}
         if(cmd=='restore'&&scalingVal<0){thisFs=thisFs-(thisVal*(0-scalingVal));}
         thisElements.style.fontSize=thisFs+'px';
         }
      }
    }catch(error){}

    // set by tag name
    try{
    if(thisMethod.indexOf('html')!=-1)
      {
        thisElements=document.getElementsByTagName(thisId);
        for(c=0;c<thisElements.length;c++)
          {
           if(isIE5up||isIE55up)
            {
             thisFs=thisElements[c].currentStyle.fontSize.replace('px','');
            } else {
             thisFs=document.defaultView.getComputedStyle(thisElements[c],'').getPropertyValue('font-size').replace('px','');
            }
           thisFs=Number(thisFs);
           if(!noSet)
            {
            if(cmd=='+'){thisFs+=thisVal;}else if(cmd=='-'){thisFs=thisFs-thisVal;}
            if(cmd=='restore'&&scalingVal>0){thisFs+=(thisVal*scalingVal);}
            if(cmd=='restore'&&scalingVal<0){thisFs=thisFs-(thisVal*(0-scalingVal));}
            thisElements[c].style.fontSize=thisFs+'px';
            }
          }
      }
      }catch(error){}
  }
}
}
clib_onload('fontScaler("restore")');