var theRoot = "/jazz/";
//load non-standard css
if(navigator.appName == "Microsoft Internet Explorer")   {
   document.writeln("<link rel='stylesheet' href='"+theRoot+"css/default/msie.css' type='text/css' />");
}

function msieHoverNavigation(inNode,isOver)   {
   //alert(navigator.appName);
   if(navigator.appName == "Microsoft Internet Explorer")   {
      //alert("msie");
      if(isOver)  {
         inNode.style.backgroundImage = "url("+theRoot+"css/default/tiles/button-rounded-orange.png)";
         inNode.style.backgroundColor = "rgb(241,113,72)";
         inNode.getElementsByTagName("a")[0].style.color = "rgb(0,0,0)";
         //inNode.style.backgroundRepeat = "no-repeat";
      }  else  {
         inNode.style.backgroundImage = "url("+theRoot+"css/default/tiles/button-rounded-black.png)";
         inNode.style.backgroundColor = "rgb(0,0,0)";
         inNode.getElementsByTagName("a")[0].style.color = "rgb(241,113,72)";
         
      }
   }
}

function msieHoverSubnavigation(inNode,isOver)   {
   //alert(navigator.appName);
   if(navigator.appName == "Microsoft Internet Explorer")   {
      //alert("msie");
      if(isOver)  {
         inNode.style.backgroundImage = "url("+theRoot+"css/default/tiles/subnavigation-active.png)";
      }  else  {
         inNode.style.backgroundImage = "url("+theRoot+"css/default/tiles/subnavigation-passive.png)";
      }
   }
}

function msieHoverSubnavigationSpecial(inNode,isOver)   {
   //alert(navigator.appName);
   if(navigator.appName == "Microsoft Internet Explorer")   {
      //alert("msie");
      if(isOver)  {
         inNode.style.backgroundImage = "url("+theRoot+"css/default/tiles/anmeldung-active.png)";
      }  else  {
         inNode.style.backgroundImage = "url("+theRoot+"css/default/tiles/anmeldung-passive.png)";
      }
   }
}


function linkNeedsFrames(inHref) {
   //relative urls not supported!
   //returns false or the url to reach the frame
   
   var theUrlBase = parent.location.protocol + "//" + parent.location.host + "/";
   var theUrl = false;

   //link maybe in the format http:// or /
   if(inHref.substr(0,1) == "/") {
   
      if(inHref.substr(1,theRoot.length) == theRoot
      //|| inHref.substr(1,7) != "contentfiles"
      )  {
         return false;
      }  else  {
         theUrl = "src="+inHref;
      }
   }  else if(inHref.substr(0,theUrlBase.length) == theUrlBase)   {
      //probably msie
      if(inHref.substr(theUrlBase.length,theRoot.length) == theRoot) {
         //alert("new");
         return false;
      }  else  {
         //alert("old");
         theUrl = "src="+inHref.substr(theUrlBase.length-1,inHref.length-theUrlBase.length+1);
      }
      
   }  else  {
      //not applicable
      //alert("not applicable for" + inHref);
      return false;
   }
   //if in doubt return a url to reach that frame
   return theUrl;
}

function parentNeedsFrames()  {
   var thePath = parent.location.pathname+"";
   if(thePath.substr(1,theRoot.length) == theRoot && parent.length <= 1)   {
      return false;  
   }
   var theUrl = "src="+parent.location.pathname;
}

function markActive(){
   
   
   
   //mark buttons in navigation active...
   //
   //make sure we are in the frame for the navigation
   if(parent.frames.length > 1
   && parent.frames["oben"]
   && parent.frames["oben"].location == window.location)  {
      //now find out where we are
      
      var theAnchors = document.getElementsByTagName("a");
      for(var theIndex = 0; theIndex < theAnchors.length; theIndex++)   {
         var theCwd = parent.location.pathname+"";   
         var theHref = theAnchors[theIndex].getAttribute("href");
         if(navigator.appName == "Microsoft Internet Explorer")   {
            theCwd = window.location.protocol+"//"+window.location.host+""+theCwd+"";
         }
         
         //the Href matching the current working directory exactly
         if(theHref.substr(0,theCwd.length) == theCwd )  {
            
            theAnchors[theIndex].setAttribute("class","active");
            
            if(theAnchors[theIndex].parentNode.getAttribute("class"))   {
               var theClass = theAnchors[theIndex].parentNode.getAttribute("class");
               theAnchors[theIndex].parentNode.setAttribute("class",theClass+" active");
            }  else if(
               //alternative method for msie6
               theAnchors[theIndex].parentNode.attributes["class"]
               )   {
               var theClass = theAnchors[theIndex].parentNode.attributes["class"].nodeValue;
               theAnchors[theIndex].parentNode.setAttribute("class",theClass+" active");
               msieHoverNavigation(theAnchors[theIndex].parentNode,true);
               theAnchors[theIndex].setAttribute("onmouseout","return false");
            }
         }
         
      }
   }
   
   //fix hrefs in infonavigation
   //
   //make sure we are in the frame for subnavigation
   
   if(parent.frames.length > 1
      && parent.frames["menuerechts"]
      && parent.frames["menuerechts"].location == window.location
      
   )  {
      //make sure we put the right subnavigation into the link
      //search for the frame
      //it might be in...
      if(parent.frames["untermenue"])  {
         //we need to know the frame src for untermenue
         var theSubmenuPath = parent.frames["untermenue"].location.pathname + "";
      }
      //or it might be a subframe
      else if(parent.frames["inhalte"].frames["untermenue"])  {
         //we need to know the frame src for untermenue
         var theSubmenuPath = parent.frames["inhalte"].frames["untermenue"].location.pathname;
      }
      //in case we found a submenu
      if(theSubmenuPath)   {
         //find out where we are
         //var theCwd = parent.location.pathname+"";
         //var theCwd = theRoot + "programm/2008/";
         var theCwd = theRoot + "angebot/2009/";
         //loop thru anchors
         var theAnchors = document.getElementsByTagName("a");
         for(var theIndex = 0; theIndex < theAnchors.length; theIndex++)   {
            //var theHref = theCwd + "?frame=untermenue,content&src="+theSubmenuPath+","+theAnchors[theIndex].getAttribute("href")+"";
            
            var theSrc = theAnchors[theIndex].getAttribute("href");
            var theUrl = ""+window.location.protocol+"//"+window.location.host;
            if(theSrc.substr(0,theUrl.length) == theUrl) {
               theSrc = theSrc.substr(theUrl.length,theSrc.length-theUrl.length);
            }
            var theHref = theCwd + "?frame=content&src="+theSrc+"";
            if(!theAnchors[theIndex].setAttribute("href",theHref))   {
               theAnchors[theIndex].attributes["href"].value = theHref;
               //alert("once");
            }
            if(!theAnchors[theIndex].setAttribute("target","_top"))  {
               theAnchors[theIndex].attributes["target"].value = "_top";
            }
         }
         
      }
      
      
      
   }
   
   return;
   
   //check if this is the frameless version or not
   if(parentNeedsFrames() == false
      
   )   {
      
      //alert("parent does not need frames");
      var theAnchors = document.getElementsByTagName("a");
      for(var theIndex = 0; theIndex < theAnchors.length; theIndex++)   {
         
         var theHref = theAnchors[theIndex].getAttribute("href");
         var theUrlBase = window.location.protocol+"//"+window.location.host+"/"+window.location.pathname;
         
         //alert(theHref+"==?=="+parent.location.pathname);
         
         //ignore links like "/"
         if(theHref.length > 1 
         && (
            //check if theHref and parent.location match
               theHref == parent.location.pathname.substr(0,theHref.length)
            //use alternative method to make sure it works in browser adding http:// to links automagically
            || theHref == theUrlBase.substr(0,theHref.length)
            )
         )   {
            //set anchor to active
            theAnchors[theIndex].setAttribute("class","active");
            if(theAnchors[theIndex].parentNode.getAttribute("class"))   {
               var theClass = theAnchors[theIndex].parentNode.getAttribute("class");
               theAnchors[theIndex].parentNode.setAttribute("class",theClass+" active");
            }
         }
         
         if(theAnchors[theIndex].getAttribute("target")  
         && theAnchors[theIndex].getAttribute("target") != "_blank"
         && linkNeedsFrames(theHref) != false
         ) {
               //alert("target:"+theAnchors[theIndex].getAttribute("target")+"");
               
               var theTarget = theAnchors[theIndex].getAttribute("target");
               theAnchors[theIndex].setAttribute("target","_top");
               //theTarget = "_top";
               
               var theSrc = linkNeedsFrames(theHref);
               theAnchors[theIndex].setAttribute("href",""+theRoot+"?frame="+theTarget+"&"+theSrc+"")
         }
         
         
      }
      
      
   }  else  {
      
      //we are in a frameset
      //
      
      //alert("parent needs frames");
      if(!document.getElementById("navigation")) {
         return;
      }
      var theNavigation = document.getElementById("navigation");
      
      var theAnchors = theNavigation.getElementsByTagName("a");
      if(markActive.arguments.length == 1)  {
         var inNode = markActive.arguments[0];
      }  else  {
         var inNode = theAnchors[theAnchors.length-1].parentNode;
         //var inNode = null;
      }
      
      for(var theIndex = 0; theIndex < theAnchors.length; theIndex++)   {
         
         //ignore links with target=_top
         if(theAnchors[theIndex].getAttribute("target")
         && theAnchors[theIndex].getAttribute("target") != "_top") {
            //alert("link has target:" + theAnchors[theIndex].getAttribute("href") + " " + theAnchors[theIndex].getAttribute("target"));
            //if(theAnchors[theIndex].getAttribute("target")) {
            var theTarget = theAnchors[theIndex].getAttribute("target");
            theAnchors[theIndex].setAttribute("target","_top");
            //}
            var theHref = theAnchors[theIndex].getAttribute("href");
            var theSrc = linkNeedsFrames(theHref);
            theAnchors[theIndex].setAttribute("href",""+theRoot+"?frame="+theTarget+"&"+theSrc+"")
            
            
            //use frames inhalte for navigation-activation
            if(parent.length > 1
            && parent.frames["inhalte"])  {
               //alert(parent.frames["inhalte"].location.pathname);
               if(navigator.appName == "Microsoft Internet Explorer"
               //&& theHref != parent.location
               )   {
                  var theBaseUrl = parent.location.protocol + "//" + parent.location.host;
                  theHref = theHref.substr(theBaseUrl.length,theHref.length-theBaseUrl.length);
                  
               }
               
               
               if(theHref == parent.frames["inhalte"].location.pathname
               
                  )   {
                  //alert("href:" + theHref);
                  if(navigator.appName == "Microsoft Internet Explorer")   {
                     msieHoverNavigation(theAnchors[theIndex].parentNode,true);
                     theAnchors[theIndex].setAttribute("onmouseout","return false");
                  }  else  {
                     
                     theAnchors[theIndex].parentNode.setAttribute("class","button active");
                  }
               }
               
            }
            
         }
         
      }
      
      //
      
      
      if(markActive.arguments.length == 0)   {
         return;
      }
      
      if(navigator.appName == "Microsoft Internet Explorer")   {
         msieHoverNavigation(inNode,true);
      }  else {
         inNode.setAttribute("class","button active");
         
      }
      
      
   }
}
   

function msieActivatePopups() {
   var theLists = document.getElementsByTagName("ul");
   //find a linklist
   for(var theIndex = 0; theIndex < theLists.length; theIndex++)  {
      //alert(theIndex);
      if(theLists[theIndex]["attributes"]["class"]
      && theLists[theIndex]["attributes"]["class"].value == "linklist"
      )  {
         var theAnchors = theLists[theIndex].getElementsByTagName("a");
         for(var theNumber = 0; theNumber < theAnchors.length; theNumber++)   {
            var theSpans = theAnchors[theNumber].getElementsByTagName("span");
            if(theSpans.length > 0) {
               var theTitle = theAnchors[theNumber].firstChild.data
               var theText = theSpans[0].firstChild.data;
               theAnchors[theNumber].removeChild(theSpans[0]);
               theAnchors[theNumber].setAttribute("href","javascript:windowPopup('"+theTitle+"','"+theText+"');");
            }
         }
      }
   }
}

function windowPopup(inTitle,inString)   {
   //var thePopup = window;
   //inString = inString.replace(/ /,"%20");
   window.open(""+theRoot+"popup.php?title="+inTitle+"&string="+inString+"","popup","navigation=false,width=200,height=300");
   
   
   
}


window.onload = function() {
   
   markActive();
   
   //if(navigator.appName == "Microsoft Internet Explorer")   {
      msieActivatePopups();
   //}
   
   //window.resizeTo(screen.availWidth,screen.availHeight);
   if(parent.location.hash.length > 0) {
      for(var theIndex = 0; theIndex < parent.length; theIndex++)   {
        //parent[theIndex].location = parent[theIndex].location + parent.location.hash;
        parent[theIndex].location.hash = parent.location.hash;
        //parent[theIndex].markActive();
      }
   }
   
}




