
function teaserScrollLeft(id) {
  var el=document.getElementById('teasercontent_'+id);

  curscrolls[id]--;
  if (curscrolls[id]<=0) {
    var leftbutton=document.getElementById('leftbutton_'+id);
    leftbutton.style.display='none';

    var leftbutton=document.getElementById('leftbuttondiv_'+id);
    leftbutton.style.cursor='';
  }

  if (curpos[id]<=0) return;

  var rightbutton=document.getElementById('rightbutton_'+id);
  rightbutton.style.display='';
  var rightbutton=document.getElementById('rightbuttondiv_'+id);
  rightbutton.style.cursor='pointer';

  curpos[id]-=208;
  JSTweener.addTween(el,{time:2,transition:'easeoutexpo',scrollLeft:curpos[id]});
}

function teaserScrollRight(id) {
  var el=document.getElementById('teasercontent_'+id);

  var leftbutton=document.getElementById('leftbutton_'+id);
  leftbutton.style.display='';
  var leftbutton=document.getElementById('leftbuttondiv_'+id);
  leftbutton.style.cursor='pointer';

  curscrolls[id]++;
  if (curscrolls[id]>=maxscrolls[id]) {
    var rightbutton=document.getElementById('rightbutton_'+id);
    rightbutton.style.display='none';

    var rightbutton=document.getElementById('rightbuttondiv_'+id);
    rightbutton.style.cursor='';
  }

  if (curpos[id]>=maxpos[id]) return;

  curpos[id]+=208;
  JSTweener.addTween(el,{time:2,transition:'easeoutexpo',scrollLeft:curpos[id]});
}

function intval (mixed_var, base) {
  var type = typeof( mixed_var );

  if (type === 'boolean') {        return (mixed_var) ? 1 : 0;
  } else if (type === 'string') {
      tmp = parseInt(mixed_var, base || 10);
      return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
  } else if (type === 'number' && isFinite(mixed_var) ) {        return Math.floor(mixed_var);
  } else {
      return 0;
  }
}

var scrollWidths=new Array();
function scrollBar(_barid,_direction,_fullwidth,_buttonwidth,_elementcount) {
  var el=document.getElementById(_barid);
  if (!el) return;

  var thewidth=0;

  if (!scrollWidths[_barid]) {
    scrollWidths[_barid]=new Array();
    scrollWidths[_barid]['fullwidth']=_fullwidth;
    scrollWidths[_barid]['curwidth']=0;
  }

  var scrollwidth=(_fullwidth-_buttonwidth)/(_elementcount-1);

  if (_direction=='right')scrollWidths[_barid]['curwidth']=scrollWidths[_barid]['curwidth']+scrollwidth;
  if (_direction=='left')scrollWidths[_barid]['curwidth']=scrollWidths[_barid]['curwidth']-scrollwidth;

  if (scrollWidths[_barid]['curwidth']>_fullwidth) scrollWidths[_barid]['curwidth']=_fullwidth;
  if (scrollWidths[_barid]['curwidth']<0) scrollWidths[_barid]['curwidth']=0;

  thewidth=scrollWidths[_barid]['curwidth']+intval(_buttonwidth);
  JSTweener.addTween(el,{time:2,transition:'easeoutexpo', width:thewidth});

  return;
}

function flashanalyze(myurl) {
  var p=myurl.indexOf("://");
  var path=myurl.substr(p+3);
  p=path.indexOf("/");
  path=path.substr(p);
  path="/coverflow"+path;
  pageTracker._trackPageview(path);
}

initFunctions=new Array();
function initPage() {
  for (var func in initFunctions) {
    var f=initFunctions[func];
    f();
  }
}

function createElementFromHTML(html) {
  var container = document.createElement("span");
  container.innerHTML=html;
  return container;
}

function parseAjaxResponse(response) {
  var doc=createElementFromHTML(response);
  var divs=doc.getElementsByTagName("div");
  var div;
  var section="";
  var result=new Array();
  for (var k=0;k<divs.length;k++) {
    div=divs[k];
    section=div.getAttribute("section");
    if (section) {
      var obj=new Object();
      obj["content"]=div.innerHTML;
      for (var k2=0;k2<div.attributes.length;k2++) {
        var key=div.attributes[k2].name;
        var val=div.attributes[k2].value;
        if (key=="height" && !val) continue;
        obj[key]=val;
      }
      result[section]=obj;
    }
  }
  delete doc;
  return result;
}

function loginRequired() {
  showView(''+'<'+'div style="padding:10px" align="left">Um fortzufahren, müssen Sie bei Womensnet angemeldet sein. Bitte geben Sie oben im Menü Ihre Zugangsdaten ein. Wenn Sie noch kein Benutzerkonto haben, können Sie sich kostenlos neu registrieren.'+'<'+'br>'+'<'+'/div>'+'<'+'div>'+'<'+'a href="http://www.womensnet.com/Login/Neu_registrieren/de">'+'<'+'![if !IE]>'+'<'+'img src="../../lib/nget.php/ub64/dGVtcC9meGxpYi80OC80OGI3NDQyYzE5MTM3ZmU2ZGRhY2ZlNjEzZTlmZjNlNC5wbmc./uid/x" width="107" height="20"   alt="" identify="Button" style="display:inline;" />'+'<'+'![endif]>'+'<'+'!--[if IE]>'+'<'+'img src="system/images/blind.gif" width="107" height="20"   alt="" identify="Button" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'../../../../../lib/nget.php/ub64/dGVtcC9meGxpYi80OC80OGI3NDQyYzE5MTM3ZmU2ZGRhY2ZlNjEzZTlmZjNlNC5wbmc./uid/x\',sizingMethod=scale);display:inline;" />'+'<'+'![endif]-->'+'<'+'/a>'+'<'+'br>'+'<'+'/div>',400,160,'#d988da','#f1f1f1','Anmeldung erforderlich')
}

// --------- Fehlerbox

function handleErrorDlg(ar) {
  if (ar["error_message"]) {
    var w;
    var h;
    if (!ar["error_message"].width) w=450;
    if (!ar["error_message"].height) h=140;
    showView('<p class="error_message_style">'+ar["error_message"].content+'</p>',ar["error_message"].width,ar["error_message"].height,"#d988da","#f1f1f1",ar["error_message"].title);
    return true;
  }
}

function ajaxDialogShow(myresult) {
  var ar=parseAjaxResponse(myresult);
  if (!ar["dialog"].width) w=450;
  if (!ar["dialog"].height) h=300;
  showView('<div class="dialog_style">'+ar["dialog"].content+'</div>',ar["dialog"].width,ar["dialog"].height,"#d988da","#f1f1f1",ar["dialog"].title);
}

function switchDisplay(from,to) {
  var efrom=document.getElementById(from);
  var eto=document.getElementById(to);
  efrom.style.display="none";
  eto.style.display="";
}

function favoriteDialog(re) {
  showView(re,400,220,"#d988da","#f1f1f1");
}

function bannerClick(bpath) {
      ajax_post_url('http://www.womensnet.com/lib/webstats.php?banner_click='+bpath,'dummy');
  }

function getElementChildren(parentElement,NodeName) {
  var children=new Array();
  var f=document.getElementById(parentElement);
  var counter=f.childNodes.length;
  for (var i=0;i<counter;i++) {
    if (f.childNodes[i].nodeName == NodeName && f.childNodes[i].id!="") children.push(f.childNodes[i]);
  }
  return children;
}

function calculateHeight(id,expander) {
  var temp=expander+"_"+id;
  var d=document.getElementById(temp);

  if (idGeneral==id && expanderGeneral==expander) {
   if (prevDivClicked[temp]!="" && prevDivClicked[temp]!=undefined) {
      if (d.scrollHeight==prevDivClicked[temp]) {
        sum=sum-prevDivClicked[temp];
        prevDivClicked[temp]="";
      } else {
        sum=sum+prevDivClicked[temp];
        }
    } else {
        prevDivClicked[temp]=d.scrollHeight;
        sum=sum+prevDivClicked[temp];
      }
    } else {
        sum=0;
        idGeneral=id;
        expanderGeneral=expander;
        prevDivClicked=new Array();
        prevDivClicked[temp]=d.scrollHeight;
        sum=sum+prevDivClicked[temp];
      }
  setHeightAutoDisplay(divGeneral,sum+aktuellHeight);
}

function showView(html,w,h,bColor,fColor,headline) {
  w=parseInt(w);
  h=parseInt(h);

  var winw=974;
  if (!document.all) var winh=window.innerHeight; else var winh=document.body.clientHeight;
  var b=document.getElementsByTagName("body");
  b=b[0];
  document.getElementById('popup').style.visibility='visible';
  document.getElementById('popup_shadow').style.visibility='visible';
  var e_popup=document.getElementById('popup');
  var e_close=document.getElementById('popup_close');
  var e_shadow=document.getElementById('popup_shadow');
  var e_content=document.getElementById('popup_content');
  var e_headline=document.getElementById('popup_headline');

  if (headline && headline!="undefined") e_headline.innerHTML=headline;

  if (html) {
    var titleh=26;
    var bordersize=1;

        e_close.style.backgroundColor=bColor;
    e_content.style.backgroundColor=fColor;

        e_content.style.width=w+"px";

        e_content.innerHTML=html;

        if (h==0) {
      e_content.style.height="auto";
      h=e_content.offsetHeight;
    }
    e_content.style.height=h;

    e_shadow.style.width=w+2*bordersize;

        var totalw=w+2*bordersize;
    var totalh=h+titleh+2*bordersize;

    myOffsets=pageOffset();

    winw=myOffsets.width;
    winh=myOffsets.height;

        var x=Math.round((winw-w)/2);
    var y=Math.round((winh-h)/2);

    x+=myOffsets.left;
    y+=myOffsets.top;

        e_popup.style.left=x+"px";
    e_popup.style.top=y+"px";
    e_popup.style.width=totalw+"px";
    e_popup.style.height=(totalh+30)+"px";
    e_content.style.height=totalh+"px";

        e_shadow.style.left=x+4+"px";
    e_shadow.style.top=y+4+"px";
    e_shadow.style.width=totalw+"px";
    e_shadow.style.height=(totalh+30)+"px";

        e_shadow.style.visibility='';
    e_popup.style.visibility='';
  }
}

function pageOffset(win) {
  if(!win) win = window;
  var pos = {left:0,top:0};

  if (typeof win.pageXOffset!='undefined') {
    // Mozilla/Netscape
    pos.left = win.pageXOffset;
    pos.top = win.pageYOffset;
  } else {
    var obj=(win.document.compatMode && win.document.compatMode == "CSS1Compat") ?
    win.document.documentElement : win.document.body || null;

    pos.left=obj.scrollLeft;
    pos.top=obj.scrollTop;
  }


  if (document.all) {
    pos.width=document.documentElement.clientWidth;
    pos.height=document.documentElement.clientHeight;
  } else {
    pos.width=innerWidth;
    pos.height=innerHeight;
  }

  return pos;
}

function closeView() {
 //document.getElementById('popup').innerHTML="";
  document.getElementById('popup').style.visibility='hidden';
  document.getElementById('popup_shadow').style.visibility='hidden';
}

function changeImage(s) {
  document.getElementById("popup").src=s;
}

function updateCountOfElementsInHeader(id,diff) {
  var headline=document.getElementById(id);
  var headlineContent=headline.innerHTML;
  var position=headlineContent.lastIndexOf('(');
  var positionClose=headlineContent.lastIndexOf(')');
  var numberOfElements=headlineContent.substring(position+1,positionClose)-0;
  var neuCount=numberOfElements+diff;
  headline.innerHTML=id+' ('+neuCount+')';
}

var ms_activeSlide=new Object();
var ms_upcomingSlide=new Object();
var ms_slideTimers=new Object();
var ms_autoSlideInterval=5000;
var ms_effectDuration=0.5;

function ms_switchComplete() {
  var ps=html.getElementById(this.target.group+"_"+ms_activeSlide[this.target.group]);
  if (ps) ps.setDisplay(false);
  ms_activeSlide[this.target.group]=this.target.idx;
  ms_upcomingSlide[this.target.group]=null;
}

function ms_blendUpdate() {
  this.target.object.setOpacity(this.target.opacity);
}

function ms_switchTo(group,idx) {
  var activeSlide=ms_activeSlide[group];
  var upcomingSlide=ms_upcomingSlide[group];

  if ((idx==activeSlide) || (idx==upcomingSlide)) return;

  JSTweener.removeTweensByProperties({tag:'mainstage_'+group});

  if (upcomingSlide) {
    html.getElementById(group+"_"+activeSlide).setDisplay(false);
    ms_activeSlide[group]=upcomingSlide;
    activeSlide=upcomingSlide;
  }

  // clear active slide
  var slide=html.getElementById(group+"_"+activeSlide);
  slide.setOpacity(100);

  slide.removeClass("mactive");
  html.getElementById(slide.id+"_btn").removeClass("mactive");
  html.getElementById(slide.id+"_teaser").removeClass("mactive");

  // prepare new slide
  slide=html.getElementById(group+"_"+idx);

  slide.addClass("mactive");
  html.getElementById(slide.id+"_btn").addClass("mactive");
  html.getElementById(slide.id+"_teaser").addClass("mactive");

  ms_upcomingSlide[group]=idx;

  var tweener=new Object();
  tweener.object=slide;
  tweener.opacity=0;
  tweener.group=group;
  tweener.idx=idx;

  slide.setOpacity(tweener.opacity);
  JSTweener.addTween(tweener, {tag:'mainstage_'+group,time:ms_effectDuration,transition:'linear',opacity:100,onUpdate:ms_blendUpdate,onComplete:ms_switchComplete});
}

function ms_autoSlideTimer(group) {
  var idx=(ms_activeSlide[group] || 0)+1;
  var o=html.getElementById(group+"_"+idx);
  if (!o) idx=0;
  ms_switchTo(group,idx);
}

function ms_startAutoSlide(group) {
    ms_slideTimers[group]=window.setInterval("ms_autoSlideTimer('"+group+"')",ms_autoSlideInterval);
  }

function ms_stopAutoSlide(group) {
  window.clearInterval(ms_slideTimers[group]);
  ms_slideTimers[group]=null;
}

function ms_initMainStage(group,idx) {
  idx=idx || 0;
  var o=html.getElementById(group+"_"+idx);
  if (!o) return;

  o.setOpacity(100);
  o.addClass("mactive");
  html.getElementById(o.id+"_btn").addClass("mactive");
  html.getElementById(o.id+"_teaser").addClass("mactive");

  ms_activeSlide[group]=idx;
  ms_upcomingSlide[group]=null;

  ms_startAutoSlide(group);
}

function showMyExpander(s,myid) {
  showExpanderArrow(s,myid);
  showExpander(s,myid,'V',-1);
}

function showExpanderArrow(s,myid) {
  if (previousExpander[s]==null) {
    var x=0;
    while (true) {
      var e=document.getElementById(s+"_arrowpic_up_"+x);
      if (!e) break;
      switchDisplay(s+"_arrowpic_up_"+x,s+"_arrowpic_down_"+x);
      x++;
    }
    switchDisplay(s+"_arrowpic_down_"+myid,s+"_arrowpic_up_"+myid);
  } else {
    switchDisplay(s+"_arrowpic_down_"+myid,s+"_arrowpic_up_"+myid);
    switchDisplay(s+"_arrowpic_up_"+previousExpander[s],s+"_arrowpic_down_"+previousExpander[s]);
  }
}
