
var xmlHttp;
var nocache;
try
{  // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
}
catch (e)
{  // Internet Explorer
    try
    {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
        try
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
            window.alert("Your browser does not support AJAX!");
        }
    }
}


var clipTop,clipLeft,clipWidth,clipBottom,topper,lyrheight;
var clipTop2,clipLeft2,clipWidth2,clipBottom2,topper2,lyrheight2;
var actualmenupoint;
var time,amount,theTime,theHeight,DHTML;
pictures = new Array();

function setScrollingValues(scroller)
{
    if(scroller==2)
    {
        clipTop2 = 0;
        clipLeft2 = 0;
        clipWidth2 = 716;
        clipBottom2 = 430;
        topper2 = 0;
    }
    else
    {
        clipTop = 0;
        clipLeft = 0;
        clipWidth = 716;
        clipBottom = 430;
        topper = 0;
    }
}

function getObj(name)
{
    if (document.getElementById)
    {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
    }
    else if (document.all)
    {
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
    else if (document.layers)
    {
        this.obj = document.layers[name];
        this.style = document.layers[name];
    }
}

function goTotop(name,scroller)
{
    setScrollingValues(scroller);
    if(scroller==2)
    {
        var cTop=clipTop2;
        var cLeft=clipLeft2;
        var cWidth=clipWidth2;
        var cBottom=clipBottom2;
    }
    else
    {
        var cTop=clipTop;
        var cLeft=clipLeft;
        var cWidth=clipWidth;
        var cBottom=clipBottom;
    }
    DHTML = (document.getElementById || document.all || document.layers)
    if (!DHTML) return;
    var x = new getObj(name);
    if (document.layers)
    {
        x.style.clip.top = cTop+'px';
        x.style.clip.left = cLeft+'px';
        x.style.clip.right = cWidth+'px';
        x.style.clip.bottom = cBottom+'px';
    }
    else if (document.getElementById || document.all)
    {
        x.style.clip = 'rect('+cTop+'px, '+cWidth+'px, '+cBottom+'px, 0px)'
    }
    x.style.top = '0px';
}

function goToPos(name,spanid){
    var nPos = document.getElementById(spanid).offsetTop
    if(nPos+400>lyrheight)
    {
        scrollayer(name,lyrheight-clipTop-432,50,1);
    }

    else if(nPos-50<0)
    {
        scrollayer(name,-clipTop,50,1);
    }
    else
    {
        scrollayer(name,nPos-clipTop,50,1);
    }
    stopScroll();
}

function prepLyr(name,scrolldiv,scroller)
{
    setScrollingValues(scroller);
    if(scroller==2)
    {
        var cTop=clipTop2;
        var cLeft=clipLeft2;
        var cWidth=clipWidth2;
        var cBottom=clipBottom2;
        var lyrH=lyrheight2;
    }
    else
    {
        var cTop=clipTop;
        var cLeft=clipLeft;
        var cWidth=clipWidth;
        var cBottom=clipBottom;
        var lyrH=lyrheight;
    }
    lyrH = 0;
    DHTML = (document.getElementById || document.all || document.layers)
    if (!DHTML) return;
    var x = new getObj(name);
    if (document.layers)
    {
        lyrH = x.style.clip.bottom;
        lyrH += 20;
        x.style.clip.top = cTop+'px';
        x.style.clip.left = cLeft+'px';
        x.style.clip.right = cWidth+'px';
        x.style.clip.bottom = cBottom+'px';
    }
    else if (document.getElementById || document.all)
    {
        lyrH = x.obj.offsetHeight;
        lyrH += 60;
        x.style.clip = 'rect('+cTop+'px, '+cWidth+'px, '+cBottom+'px, 0px)'
    }
    if((lyrH-20)>cBottom)
    {
        showscrollarrows(1,name,scrolldiv);
    }
    else
    {
        showscrollarrows(0,name,scrolldiv);
    }
    x.style.top = '0px';
    if(scroller==2)
    {
        clipTop2=cTop;
        clipLeft2=cLeft;
        clipWidth2=cWidth;
        clipBottom2=cBottom;
        lyrheight2=lyrH;
    }
    else
    {
        clipTop=cTop;
        clipLeft=cLeft;
        clipWidth=cWidth;
        clipBottom=cBottom;
        lyrheight=lyrH;
    }

}

function scrollayer(name,amt,tim,scroller)
{
    if (!DHTML) return;
    thelayer = new getObj(name);
    if (!thelayer) return;
    amount = amt;
    theTime = tim;
    realscroll(scroller);
}

function stopScroll()
{
    if (time) clearTimeout(time);
}

function realscroll(scroller)
{
    if(scroller==2)
    {
        var cTop=clipTop2;
        var cLeft=clipLeft2;
        var cWidth=clipWidth2;
        var cBottom=clipBottom2;
        var cTopper=topper2;
        var lyrH=lyrheight2;
    }
    else
    {
        var cTop=clipTop;
        var cLeft=clipLeft;
        var cWidth=clipWidth;
        var cBottom=clipBottom;
        var cTopper=topper;
        var lyrH=lyrheight;
    }
    if (!DHTML) return;
    cTop += amount;
    cBottom += amount;
    cTopper -= amount;
    if (cTop < 0 || cBottom > lyrH)
    {
        cTop -= amount;
        cBottom -= amount;
        cTopper += amount;
        return;
    }
    if (document.getElementById || document.all)
    {
        clipstring = 'rect('+cTop+'px, '+cWidth+'px, '+cBottom+'px, 0px)'
        thelayer.style.clip = clipstring;
        thelayer.style.top = cTopper+'px';
    }
    else if (document.layers)
    {
        thelayer.style.clip.top = cTop+'px';
        thelayer.style.clip.bottom = cBottom+'px';
        thelayer.style.top = cTopper+'px';
    }
	
    if(scroller==2)
    {
        time = setTimeout('realscroll(2)',theTime);
        clipTop2=cTop;
        clipLeft2=cLeft;
        clipWidth2=cWidth;
        clipBottom2=cBottom;
        topper2=cTopper;
    }
    else
    {
        time = setTimeout('realscroll()',theTime);
        clipTop=cTop;
        clipLeft=cLeft;
        clipWidth=cWidth;
        clipBottom=cBottom;
        topper=cTopper;
    }
}

function showscrollarrows(action,divtoscroll,scrolldiv)
{
    if(scrolldiv==undefined)
        scrolldiv="subnav";
    if(action==0)
    {
        document.getElementById(scrolldiv).innerHTML="";
    }
    else
    {
        if(document.getElementById("gobacktotop")==null);
        {
            var oldcontent=document.getElementById(divtoscroll).innerHTML;
            if(divtoscroll!="specials_div")
                document.getElementById(divtoscroll).innerHTML=oldcontent+"<div id=\"gobacktotop\"><hr class=\"content_line\"></hr><a href=\"javascript:goTotop('"+divtoscroll+"',1);\">An Anfang zur&uuml;ck</a></div>";
            else
                document.getElementById(divtoscroll).innerHTML=oldcontent+"<div id=\"gobacktotop\"><hr class=\"content_line\"></hr><a href=\"javascript:goTotop('"+divtoscroll+"',2);\">An Anfang zur&uuml;ck</a></div>";
        }
        if(scrolldiv!="subnav")
            document.getElementById(scrolldiv).innerHTML="<img src=\"pics/site/nav/arrowup.gif\" id=\"navarrowup_middle\" onmouseover=\"scrollayer('"+divtoscroll+"',-10,50,2);\" onmouseout=\"stopScroll();\" /><img src=\"pics/site/nav/arrowdown.gif\" id=\"navarrowdown_middle\" onmouseover=\"scrollayer('"+divtoscroll+"',10,50,2);\" onmouseout=\"stopScroll();\" />";
        else
            document.getElementById(scrolldiv).innerHTML="<img src=\"pics/site/nav/arrowup.gif\" id=\"navarrowup\" onmouseover=\"scrollayer('"+divtoscroll+"',-10,50);\" onmouseout=\"stopScroll();\" /><img src=\"pics/site/nav/arrowdown.gif\" id=\"navarrowdown\" onmouseover=\"scrollayer('"+divtoscroll+"',10,50);\" onmouseout=\"stopScroll();\" />";
    }
}

function hidescrollarrows()
{
    document.getElementById("subnav").innerHTML="";
}

if(xmlHttp!=null)
{
    var ajaxresult;
    function gobackbutton(funct,arg)
    {
        var oldsubnav=document.getElementById("subnav").innerHTML;
        document.getElementById("subnav").innerHTML=oldsubnav+"<img src=\"pics/site/nav/arrowback.gif\" id=\"navarrowback\" onclick=\""+funct+"('"+arg+"');\" />";
    }

    function initiatecontent(name,content)
    {
        document.getElementById("middle").innerHTML="<div id=\""+name+"\">"+content+"</div>";
    }

    function getdata(url,contentdiv,divtoscroll,gobackfunct,gobackarglocation,gobackarg,scrolldiv,scroller)
    {
        nocache = Math.random();
        url=url+"&nocache="+nocache
        xmlHttp.open("GET",url,false)
        xmlHttp.send(null)
        if(contentdiv!=0)
        {
            var tmpcontent=xmlHttp.responseText.split("//||//");
            var content1=tmpcontent[0];
            var content2=tmpcontent[1];
            if(contentdiv=="middle")
            {
                document.getElementById("middle").innerHTML=content1;
            }
            else
            {
                if(document.getElementById(contentdiv)==null)
                {
                    initiatecontent(contentdiv,content1);
                }
                else
                {
                    document.getElementById(contentdiv).innerHTML=content1;
                }
                        
            }
            if(typeof(content2)!="undefined")
                document.getElementById("top").innerHTML=content2;
            else
                document.getElementById("top").innerHTML="";
            hidescrollarrows();
            if(divtoscroll!=0)
                prepLyr(divtoscroll,scrolldiv,scroller);
            if(gobackfunct!=0)
            {
                if(gobackarglocation==0)
                {
                    gobackbutton(gobackfunct,gobackarg);
                }
                else
                {
                    gobackbutton(gobackfunct,document.getElementById(gobackarg).value);
                }
            }
        }
        else
        {
            ajaxresult=xmlHttp.responseText;
        }
    }

    function navigate(menupoint)
    {
        actualmenupoint=menupoint;
        changestate(menupoint);
        if(menupoint=="team")
        {
            getdata("html/functions/navigator.php?q=navigate&sid="+menupoint,"middle","teamcontent",0,0,0);
        }
        else if(menupoint=="news")
        {
            getdata("html/functions/navigator.php?q=navigate&sid="+menupoint,"middle",0,0,0,0);
            getdata("html/functions/navigator.php?q=navigate&sid=news_specials","specials_div","specials_div",0,0,0,"specials_div_subnav",2);
            getdata("html/functions/navigator.php?q=navigate&sid=news_news","news_div","news_div",0,0,0);
        }
        else
        {
            getdata("html/functions/navigator.php?q=navigate&sid="+menupoint,"middle","content",0,0,0);
        }
        
    }

    function course(courseid)
    {
        if(courseid==0)
        {
            getdata("html/functions/navigator.php?q=course&sid="+courseid,"content","content",0,0,0);
        }
        else
        {
            getdata("html/functions/navigator.php?q=course&sid="+courseid,"content","content","course",1,"parentid");
        }
          
    }

    function showteacher(teacherid)
    {
        getdata("html/functions/navigator.php?q=showteacher&sid="+teacherid,"teamcontent","teamcontent",0,0,0);
    }

    function showgallery(courseid)
    {
        if(courseid==0)
        {
            getdata("html/functions/navigator.php?q=gallery&sid="+courseid,"middle","content",0,0,0);
        }
        else
        {
            getdata("html/functions/navigator.php?q=gallery&sid="+courseid,"middle","content","showgallery",1,"parentid");
        }
    }

    function showpictures(galleryid,courseid)
    {
        if(courseid==0)
        {
            getdata("html/functions/navigator.php?q=pictures&sid="+galleryid,"middle","content","showgallery",1,"parentid");
        }
        else
        {
            getdata("html/functions/navigator.php?q=pictures&sid="+galleryid,"middle","content","showgallery",0,courseid);
        }
    }

    var gallery_id;
    var actual_picture;
    var resetSlideShowArrow=0;
    function slideshow(action,galleryid,pictureid)
    {
        if(action==0)
        {
            if(document.getElementById("navarrowup")!=null)
            {
                document.getElementById("navarrowup").style.display='block';
                document.getElementById("navarrowdown").style.display='block';
            }
            document.getElementById("slideshow").style.display='none';
        }
        else if(action==1)
        {
            if(document.getElementById("navarrowup")!=null)
            {
                document.getElementById("navarrowup").style.display='none';
                document.getElementById("navarrowdown").style.display='none';
                goTotop("content");
            }
            fillpictures()
            gallery_id=galleryid;
            actual_picture=pictureid;
            document.getElementById("slideshow").style.display='block';
        }
        else if(action==2){
            actual_picture--;
        }
        else if(action==3){
            actual_picture++;
        }
        if(action==1 || action==2 || action==3)
        {
            if(actual_picture>=0 && actual_picture<=(pictures.length-1))
            {
                if(resetSlideShowArrow==2)
                {
                    setSlideShowArrows(0,"slideshowback");
                }
                else if(resetSlideShowArrow==3)
                {
                    setSlideShowArrows(0,"slideshownext");
                }
                
                if(actual_picture==0)
                {
                    setSlideShowArrows(2,"slideshowback");
                }
                else if(actual_picture==(pictures.length-1))
                {
                    setSlideShowArrows(3,"slideshownext");
                }
                
                document.getElementById("slideshowmainpic").src="pics/gallery/"+gallery_id+"/images/"+pictures[actual_picture];
            }
            else
            {
                if(actual_picture<0)
                {
                    actual_picture=0;
                    setSlideShowArrows(2,"slideshowback");
                }
                else
                {
                    actual_picture=(pictures.length-1);
                    setSlideShowArrows(3,"slideshownext");
                }
            } 
        }
    }

    function setSlideShowArrows(action,arrowid)
    {
        if(action==0)
        {
            if(arrowid=="slideshowback")
            {
                document.getElementById(arrowid).src="pics/site/nav/arrowdown.gif";
            }
            else if(arrowid=="slideshownext")
            {
                document.getElementById(arrowid).src="pics/site/nav/arrowup.gif";
            }
        }
        else if(action==2)
        {
            document.getElementById(arrowid).src="pics/site/nav/closediv.gif";
        }
        else if(action==3)
        {
            document.getElementById(arrowid).src="pics/site/nav/closediv.gif";
        }
        resetSlideShowArrow=action;
    }

    function fillpictures()
    {
        pictures=new Array();
        var picturetag=document.getElementById("content").getElementsByTagName("img");
        for (var i=0; i<picturetag.length; i++){
            if(picturetag[i].id!="" && picturetag[i].id!="undefined")
            {
                pictures[i]=picturetag[i].id
            }
        }
    }
}