/*CVS Add-ins*/
/* 
$Revision: 1.7 $
$RCSfile: behaviour.js,v $
author: JDE
Copyright (c) A&B.face2net GmbH
*/

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/*
    behaviour.js fuer Mosaik
    08.05.2007 JDE
*/
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

/**
* executes functions when the page loads.
* @param func_name name of function
*/

function addLoadEvent(func_name) {
	var lastonload = window.onload;
	if (typeof window.onload != 'function') 
		{ window.onload = func_name; } 
	else {	window.onload = function() {
      			lastonload(); func_name(); }
  	}
}


var a = new Array("bg_dot.gif","bg_home.gif", "bg_icon_integration.gif", "bg_icon_mosaikev.gif","bg_icon_oekohof.gif", "bg_icon_werkstaetten.gif", "bg_link.gif", "bg_link_content.gif", "bg_navi_down.gif", "bg_navi_right.gif", "bg_navMain_1.gif", "bg_navMain_1hover.gif", "bg_navMain_2active.gif","bg_navMain_2hover.gif","bg_navMain_3active.gif","bg_print.gif","bg_skip.gif", "bg_slogan_top.gif", "bg_submitSearch.jpg", "bg_top.gif", "bg_white.gif"  );
var b = new Array();
var i;
for (i = 0; i < a.length; i++) {
  b[i] = new Image();
  b[i].src = '../css/images/styleimages/'+a[i];
}

var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var nn = (agt.indexOf("gecko") != -1);
if (nn) nn = (agt.indexOf("firefox") == -1);
else nn = (agt.indexOf("firefox") == -1);
	
/**
* sets an attribute to a node.
* @param elem name of node
* @param attr kind of attribute
* @param value attribute value
*/
function set_attr(elem, attr, value) {
  var myNode = elem; myNode.setAttribute(attr, value ); }
/**
* sets an URL to a node.
* @param elem name of node
* @param url url
*/
function set_href(elem, url) {
  var myNode = elem; myNode.setAttribute("href",url );  }
  
  
/**
* returns the list of objects with a certain class name and tagname
* @param class_name name of class
* @param tag_name name of tag
*/  
function get_elementsByClassName(class_name, tag_name){
  var all_elements; var class_elements=new Array();
  var j=0; var i; var teststr;
  if(document.getElementsByTagName){ 
    all_elements=document.getElementsByTagName(tag_name);   
  }
  
  for(i=0;i<all_elements.length;i++){
    if(all_elements[i].className.indexOf(class_name)!=-1) {
	  teststr=","+all_elements[i].className.split(" ").join(",")+",";
	  if(teststr.indexOf(","+class_name+",")!=-1){
        class_elements[j]=all_elements[i];
		j++;
      }
    }
  }
  
  return class_elements;
  
}  

/**
* sets a class to a certaion element.
* @obj element object
* @param new_class class name
*/
function set_class(obj, new_class  ){
    obj.setAttribute("class", new_class);
     if(ie) obj.className = new_class;
}

  
  
/**
* sets a title to a node.
* @param elem name of node
* @param title node title
*/
function set_title(elem, title) {
  var myNode = elem; myNode.setAttribute("title", title ); }
/**
* sets a textnode to a parent node.
* @param par name of parent
* @param text value of title
*/
function set_textNode(par, text) {
  if (!document.createTextNode) return false;
  var myNode = par; myNode = document.createTextNode(text);
  return true; }
/**
* creates a link with link text, title and url.
* @param txt link text
* @param ltitle link title
* @param url  link destination
* @return link element (a);
*/
function create_link(txt, ltitle, url ) {
  if (!document.createElement || !document.createTextNode) return false;
  var myNode = document.createElement("a");
  var myNode_text = document.createTextNode(txt);
  myNode.appendChild(myNode_text);
  set_title(myNode, ltitle);
  set_href(myNode, url) ;
  return myNode;}
/**
* creates a print link using create_link(txt, ltitle, url ) and set_attr(elem, attr, value)
*/
function create_printLink() {
  var printlink = create_link("Drucken", "Diese Seite drucken", "javascript:window.print();" );
  set_attr(printlink, "onclick", "window.print();return false;");
  /*do not use onkeypress otherwise in FF the tab will get stuck in the printlink */ }
/**
* creates a list item.
* @param listid id of parent ul or ol
* @return list item (li);
*/
function create_ListItem(listId) {
  if (!document.getElementById) return false;
  var myList = document.getElementById(listId);
  if(myList){
    var myItem = document.createElement("li");
    myList.appendChild(myItem);
    return myItem;
  } else{
  return false;}
 }

/**
* creates a list item with a print link.
*/
function create_printLinkItem() {
  var printlink = create_link("Drucken", "Diese Seite drucken", "javascript:window.print();" );
  if(document.getElementById("footerul")) {
    create_ListItem("footerul").appendChild(printlink);
    set_attr(printlink, "onclick", "window.print();return false;");
   
  }
}

/**
* hide skip-liste in Netscape and Mozilla
* var nn = (agt.indexOf("netscape") != -1);
*/

function check_nn() {
  if(!nn) return false;
  if(document.getElementById("skiplist")) {
   mylist = document.getElementById("skiplist");
   mylist.style.display = "none";
  }
  return true;
}



/**
* checks, if there is enough space for a solid text-block in list template
*  if there is, it stops floating effect and sets a fix margin-left 
*/
function stop_floating() {
  var my_spans=new Array();
  my_spans = get_elementsByClassName("fluvial", "span");
  
  if(my_spans.length > 0) {
   for(i=0;i<my_spans.length;i++){
     set_class(my_spans[i], "noFloat");
   }
  }
  return true;
}


addLoadEvent(create_printLinkItem);
addLoadEvent(check_nn);
//addLoadEvent(stop_floating);