/*
lib.js for taxi40100.at

Author:			  manfred.schneiderbauer@world-direct.at
Version:      1.1
Last Changed:	2008-04-30
*/

// position sub menu
// Version 1.1
function posSubmenu(){
var offL=326;
if(isGecko){offL=319;}
if(isIE7up){offL=318;}

  d('dvSubnaviTarget').style.left=document.body.offsetWidth/2-offL+'px';
  window.setTimeout("posSubmenu();",250);
}
clib_onload("callPosSubmenu()");

function callPosSubmenu(){try{
  d("dvSubnaviTarget").style.visibility="visible";posSubmenu();
}catch(error){window.setTimeout("callPosSubmenu();",500);}}

// handle the sub navigation
// currentPage=id for the submenu to currently display
function handleSubNavi(currentPage){try{

// set currently active main menu item
var allLis=d('clib_MenuWrapper').getElementsByTagName('li');
for(var b=0;b<allLis.length;b++)
  {
   allLis[b].onmouseover=function(){insertVSepsOnIE();}; allLis[b].onmouseout=function(){insertVSepsOnIE();};
   if(allLis[b].className.indexOf('menu_button_active')!=-1)
    {
     window.currentMainmenuItem=allLis[b].getElementsByTagName('a')[0].href;
    }
  }

if(!window.disableSubnaviHandler){
var sub=false;
if(!currentPage)
  {
  if(!window.currentSubPage&&!window.currentMainmenuItem){currentPage=location.href;}
  if(window.currentSubPage){currentPage=window.currentSubPage;}
  if(window.currentMainmenuItem){currentPage=window.currentMainmenuItem}
  }
d('dvSubnaviTarget').innerHTML='';
// collect all submenus in allSubDivs[]
var ii=0; var allSubDivs=new Array();
var allDivs=document.getElementsByTagName('div');
for(var i=0;i<allDivs.length;i++)
  {
    if(allDivs[i].className.indexOf('menu_dropdown')!=-1)
      {
       allSubDivs[ii]=allDivs[i];
       if(!isIE55up)
          {
          allSubDivs[ii].title=allSubDivs[ii].previousSibling.getElementsByTagName('a')[0].href;
          }else{
          try{
          allSubDivs[ii].title=allSubDivs[ii].previousSibling.getElementsByTagName('a')[0].href;
          }catch(error){
          allSubDivs[ii].title=allSubDivs[ii].previousSibling.href;
          }
          }
       ii++;
       }
  }
// find the anchor set to currently display
var thisSet=''; var cs=0;
for(var c=0;c<allSubDivs.length;c++)
  {
  if(currentPage.indexOf(allSubDivs[c].title)!=-1)
    {
    thisSet=allSubDivs[c];
    }
  }
// now, fill the links into the target DIV
if(thisSet!='')
  {
  var thisAs=thisSet.getElementsByTagName('a');
  var newA=''; var thisL=''
  for(var i=0;i<thisAs.length;i++)
    {
    newA=document.createElement('a');
    newA.href=thisAs[i].href;
    newA.target=thisAs[i].target;
    newA.className='aSubmenu';
    newA.innerHTML='<img src="/fileadmin/dev/img/topnav-arrow.gif" border="0" class="imTopnavArrow">'+thisAs[i].innerHTML;
    newA.style.paddingLeft=0;
    newA.onclick=function(){fade('dvSubnaviTarget',false);}
    newA.style.color='#000000'; newA.style.textTransform='uppercase'; newA.style.fontWeight='normal';
    newA.style.fontSize='10px'; newA.style.textDecoration='none'; newA.style.marginRight='10px';
    newA.onmouseout=function(){this.style.color='#000000';insertVSepsOnIE();}
    newA.onmouseover=function(){this.style.color='#808080';insertVSepsOnIE();}
    thisL=location.href;
    if(thisL.indexOf('&')!=-1){thisL=thisL.substring(0,thisL.indexOf('&')-1);}
    if(thisAs[i].href.indexOf(thisL)!=-1&&thisL.substring(thisL.length-1,thisL.length)!='/')
      {
       newA.style.color='#808080';
       newA.onmouseout=function(){this.style.color='#808080';insertVSepsOnIE();}
      }
    d('dvSubnaviTarget').appendChild(newA);
    }
  }
}
}catch(error){if(currentPage==undefined){currentPage=false;};window.setTimeout("handleSubNavi('"+currentPage+"');",500);}}
clib_onload("handleSubNavi()");

function correctMainmenuOnGecko(){try{
var mLis=d('clib_MenuWrapper').getElementsByTagName('li');
var thisA='';
for(var i=0;i<mLis.length;i++)
  {
   if(mLis[i].className.indexOf('menu_button')!=-1)
    {
     thisA=mLis[i].getElementsByTagName('a')[0];
     thisA.style.position='relative';
     if(!isIE7up){thisA.style.left='4px';}else{thisA.style.left='7px';}
     if(!isIE5up||isIE7up)
      {
      thisA.style.top='-1px';
      }
    }
  }
fade('dvMenunav',true);
}catch(error){window.setTimeout("correctMainmenuOnGecko();",250);}}
clib_onload("correctMainmenuOnGecko()");

// set current page to be recognized by the top menu thru the breadcrumbs
function setCurrentSubPage(){try{
var allSp=document.getElementsByTagName('span');
var bcCount=0;
for(var i=0;i<allSp.length;i++)
  {
  if(allSp[i].className=='breadcrumb'&&bcCount<2)
    {
     if(bcCount==0)
      {
       bcCount++;
      }else{
       try
        {
        window.currentSubPage=allSp[i].getElementsByTagName('a')[0].href;
        }catch(error){
        window.currentSubPage='';
        }
      }
    }
  }
handleSubNavi();
}catch(error){window.setTimeout("setCurrentSubPage();",500);}}
clib_onload("setCurrentSubPage()");

// fade element
function fade(id,mode,count){
if(!count&&mode){count=0;}
if(!count&&!mode){count=100;}
try{
if(isIE55up)
  {
   d(id).style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+count+')';
   if(count==100){d(id).style.filter='';}
  }else{
   d(id).style.opacity=count/100;
   d(id).style.MozOpacity=count/100;
   d(id).style.khtmlOpacity=count/100;
  }
if(count==0&&mode){d(id).style.visibility='visible';}
if(count<11&&!mode){d(id).style.visibility='hidden';}
}catch(error){}
if(mode){count=count+10;}
if(!mode){count=count=count-10;}
if((mode&&count<101)||(!mode&&count>0)){window.setTimeout("fade('"+id+"',"+mode+","+count+");",15);}
}

// opacity hover effect
function opaque(obj,mode){
var op=1;
if(mode){op=.66;}
if(isIE55up)
  {
   obj.getElementsByTagName('img')[0].style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+op*100+')';
  }else{
   obj.style.opacity=op; obj.style.MozOpacity=op; obj.style.khtmlOpacity=op;
  }
}

// stretch the main table to full visible height
function stretchMainTableAndPosEls(){
// content page
if(d('tdMaincontent_content'))
  {
  var conH=d('dvBannersRightContentpage').offsetHeight+d('infoBoxes').offsetHeight;
  var bH=166; // banner height
  if(d('tdMaincontent_content').offsetHeight+bH>conH){conH=d('tdMaincontent_content').offsetHeight+bH;}
  if(document.body.offsetHeight-336>conH){conH=document.body.offsetHeight-336;}
  d('tbMain').style.height=(356+conH)+'px';
  if(!isIE55up)
    {
    d('infoBoxes').style.top=(d('dvBannersRightContentpage').offsetHeight+25)+'px';
    }else{
    if(!isIE7up)
      {
      d('infoBoxes').style.top=(d('dvBannersRightContentpage').offsetHeight-50)+'px';
      }else if (isIE7up){
      d('infoBoxes').style.top=(d('dvBannersRightContentpage').offsetHeight)+23+'px';
      }
    }

  }
// start page
if(d('startpage-left'))
  {
  var hh=470; var eh=0; if(isIE5up){hh=450;}
  var lh=d('startpage-left').offsetHeight; var lm=d('startpage-main').offsetHeight; var lr=d('startpage-right').offsetHeight;
  eh=lh;
  if(lh>lm){eh=lm;}
  if(lr>eh){eh=lr;}
  d('tbMain').style.height=100+eh+hh+'px';
  }
}

// IE quirk: insert vertical seps in topnav
function insertVSepsOnIE(){if(isIE55up){try{
  var tn=d('dvMenuNav').getElementsByTagName('li'); var thisA=''; var yCorr=-1; if(isIE7up){yCorr=-4;};
  for(var i=0;i<tn.length-1;i++)
    {
      thisA=tn[i].getElementsByTagName('a')[0];
      if(thisA.innerHTML.indexOf('&nbsp;&nbsp;')==-1) // if not yet quirked...
        {
        // inject vsep image including orange gap into link
        thisA.style.position='relative';
        thisA.innerHTML=thisA.innerHTML+'&nbsp;&nbsp;<img border="0" src="/fileadmin/dev/img/ie-menuquirk.gif" style="position:absolute;top:'+yCorr+'px;">';
        }
    }
   var allEls=getElementsByClass('li','menu_button');
   for(i=0;i<allEls.length;i++){allEls[i].style.visibility='visible';}
   allEls=getElementsByClass('li','menu_button menu_button_active');
   for(i=0;i<allEls.length;i++){allEls[i].style.visibility='visible';}
   allEls=getElementsByClass('li','menu_button menu_button_first');
   for(i=0;i<allEls.length;i++){allEls[i].style.visibility='visible';}

}catch(error){window.setTimeout("insertVSepsOnIE();",500);}}}
clib_onload("insertVSepsOnIE()");

// style buttons
function styleButtons(){try{
var allInps=document.getElementsByTagName('input'); var b=''; var w=0; var tbc=''; // collect elements
for(var i=0;i<allInps.length;i++)
  {
  b=allInps[i];
  if(b.type=='button'||b.type=='submit'||b.type=='reset'||b.type=='file') // if it's a button-like element...
    {
    w=b.offsetWidth; // get offset width; below the class corresponding to the width is chosen
    if(w<50){tbc=60;}
    if(w>49&&w<110){tbc=120;}
    if(w>109){tbc=240;}
    b.className='button_'+tbc;
    }
  if(b.type=='checkbox'||b.type=='radio') // restyle radio and checkbox elements
    {
      allInps[i].style.backgroundColor='transparent';
      allInps[i].style.border=0;
    }
  }
}catch(error){window.setTimeout("styleButtons();",500);}}
clib_onload("styleButtons()");

// create the flash movie links
// extended to recognize image banners as well
function flashLink(obj){
  var thisE=''; var thisV='';
  if(obj.getElementsByTagName('object').length>0)
    {
    if(!isIE55up) // on non-IE...
      {
      thisE=obj.getElementsByTagName('object')[0].innerHTML; // ... the data attrib holds what we need
      if(thisE.indexOf('clickTag=')!=-1) // if the banner has a link...
        {
        thisE=thisE.substring(thisE.indexOf('clickTag=')+9,thisE.length); // strip the adress
        thisE=thisE.substring(0,thisE.indexOf('"'));
        location.href=unescape(thisE); // redirect
        }
      }else{ // on IE...
      thisE=obj.getElementsByTagName('object')[0].getElementsByTagName('param'); // ...it's spread into param values
      for(var i=0;i<thisE.length;i++) // look for the param containing the link
        {
        if(thisE[i].value.indexOf('clickTag=')!=-1)
          {
          thisV=thisE[i].value.substring(thisE[i].value.indexOf('clickTag=')+9,thisE[i].value.length); // strip
          location.href=unescape(thisV); // redirect
          }
        }
      }
    }else{
     try{
      var thisLink=obj.getElementsByTagName('a')[0].href;
      location.href=thisLink;
      }catch(error){}
    }
}

// Firefox sucks sometimes, so we need to remove the first separator graphic on 1st level main menu item ACT
function correctFirstMainMenuItemOnFF(){try{
  if(document.defaultView.getComputedStyle(d('dvMenunav').getElementsByTagName('li')[0], '').getPropertyValue("background-color").indexOf('rgb(179, 212, 84)')!=-1)
    {
     d('dvMenunav').getElementsByTagName('li')[0].style.listStyleImage='url(/fileadmin/dev/img/clib/s.gif)';
    }
}catch(error){}}
if(!isIE55up){clib_onload("correctFirstMainMenuItemOnFF()");}

// create start content left and main blocks
function createStartContentLeftAndMain(){
 // style content HTML, marker will later be replaced by content
 var leftHTML='<img class="imFrameStartcontentT" src="/fileadmin/dev/img/frame_startcontent_t.gif"/><div class="dvStartcontent_content">###CONTENT_LEFT###</div><img class="imFrameStartcontentB" src="/fileadmin/dev/img/frame_startcontent_b.gif"/>';
 var left=d('dvStartcontentLeft');
 // get APA plugin content
 var leftApaHTML='<div class="tx-apanews-pi1">'+getElementsByClass('div','tx-apanews-pi1')[0].innerHTML+'</div>';

 var leftEls=left.getElementsByTagName('div');
 var leftHeads=new Array(); var leftContents=new Array(); var h=0; var c=0;
 // loop thru all elements and fill headline and content arrays
 for(var i=0;i<leftEls.length;i++)
  {
    if(leftEls[i].className.indexOf('csc-header ')!=-1){leftHeads[h]=leftEls[i];h++;}
    if(leftEls[i].className.indexOf('csc-textpic ')!=-1){leftContents[c]=leftEls[i];c++;}
  }
 var leftFullContents='';
 for(i=0;i<leftContents.length;i++)
  {
    // merge template HTML and content
    leftFullContents+=leftHTML.replace('###CONTENT_LEFT###','<div class="csc-header">'+leftHeads[i].innerHTML+'</div><div class="csc-textpic csc-textpic-intext-left-nowrap csc-textpic-equalheight">'+leftContents[i].innerHTML+'</div><div class="csc-textpic-clear"></div>');
  }
// add APA HTML
left.innerHTML=leftFullContents+leftApaHTML;
// style APA HTML
var leftApa=getElementsByClass('div','tx-apanews-pi1')[0];
var allEls=leftApa.getElementsByTagName('div'); var allApas=new Array(); var a=0;
for(i=0;i<allEls.length;i++)
  {
   if(allEls[i].className=='apa-news-list-beitrag'){allApas[a]=allEls[i];a++;}
  }
for(i=0;i<allApas.length;i++)
  {
   allApas[i].innerHTML=leftHTML.replace('###CONTENT_LEFT###',allApas[i].innerHTML);
  }

var mainHTML='<img class="imFrameStartcontentT" src="/fileadmin/dev/img/frame_startcontent_t.gif"/><div class="dvStartcontent_content">###CONTENT_MAIN###</div><img class="imFrameStartcontentB" src="/fileadmin/dev/img/frame_startcontent_b.gif"/>';
 var main=d('dvStartcontentMain');
 var mainApaHTML='<div class="tx-apanews-pi1">'+getElementsByClass('div','tx-apanews-pi1')[1].innerHTML+'</div>';
 var mainEls=main.getElementsByTagName('div');
 var mainHeads=new Array(); var mainContents=new Array(); h=0; c=0;
 for(i=0;i<mainEls.length;i++)
  {
    if(mainEls[i].className.indexOf('csc-header ')!=-1)
      {
        mainHeads[h]=mainEls[i]; h++;
      }
    if(mainEls[i].className.indexOf('csc-textpic ')!=-1)
      {
        mainContents[c]=mainEls[i]; c++;
      }
  }
 var mainFullContents='';
 for(i=0;i<mainContents.length;i++)
  {
    mainFullContents+=mainHTML.replace('###CONTENT_MAIN###','<div class="csc-header">'+mainHeads[i].innerHTML+'</div><div class="csc-textpic csc-textpic-intext-left-nowrap csc-textpic-equalheight">'+mainContents[i].innerHTML+'</div><div class="csc-textpic-clear"></div>');
  }
main.innerHTML=mainFullContents+mainApaHTML;
var mainApa=getElementsByClass('div','tx-apanews-pi1')[1];
allEls=mainApa.getElementsByTagName('div'); allApas=new Array(); a=0;
for(i=0;i<allEls.length;i++)
  {
   if(allEls[i].className=='apa-news-list-beitrag'){allApas[a]=allEls[i];a++;}
  }
for(i=0;i<allApas.length;i++)
  {
   allApas[i].innerHTML=mainHTML.replace('###CONTENT_MAIN###',allApas[i].innerHTML);
  }

}