var a=0;
var item_on = null;
var timeoutitem = null;

function startList() {
	if (document.getElementById && document.getElementById("menu_main")!=null) {
		var navRoot = document.getElementById("menu_main");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName == "LI" && node.className != "active") {
//				var anode=null;
//				for (j=0; j<node.childNodes.length && anode==null; j++) {
//					subnode=node.childNodes[j];
//					if (subnode.nodeName == 'A') anode=subnode;
//				}
				
				node.onmouseover = function() {
					if (timeoutitem && timeoutitem!=this) {
						doHideMenu();
					}	
                                        item_on=this;
					this.className = "over";
					document.getElementById('stroke').style.display='none';
				}
				node.onmouseout=function() {
					//alert('mouseout:'+"\n"+mytrace(this));
					if (timeoutitem && timeoutitem!=this) {
						doHideMenu();
					}	
					timeoutitem = this;
					var callstr="doHideMenu()";
					window.setTimeout(callstr,1500);
                                        item_on=null;
				}
			}
		}
	}
	//firstItem();
	changeStrokeSize();
}

function doHideMenu () {
        clear_item=timeoutitem;
        if (clear_item && clear_item!=null && clear_item!=item_on) {
                //window.setTimeout("alert('hide!')",4000);
                timeoutitem = null;
		clear_item.className = '';
		document.getElementById('stroke').style.display='block';
	} else {
		//alert('no hideitem');
	};
} 



function hideMe (clear_item) {
        alert('['+mytrace(clear_item)+']');
        clear_item.id=saveid;
        saveid='';
        //alert(dump(clear_item,0));
	//if (a==0) {
		//t = setTimeout ("clear_item.className = ''; alert (clear_item);", 1000);
		clear_item.className = "";
		document.getElementById('stroke').style.display='block';
	//}
} 

/*sirina = ukupna sirina (474) - ukupna sirina slika pre slike koja ima activ * 14 (za padding) - 8 (za 
prvi) + 6 (za padding-left activa)*/
/* width = total width (474) - total width of image in front of active image*14 (for padding) - 8 (for first) + 6 (for padding-left of active) */

function changeStrokeSize() {
	if (document.getElementById && document.getElementById('menu_sub') != null) {
			var total_w = 474;
			var w=0; /* part that will be subtracted from total_w */
			var i=0; /* counter */
			var p=16; /* padding sum for each menu item */
			var p_f=6; /* first item has no left padding */
			var p_a=6; /* stroke starts after left padding of active item */
			var menuStatus='go';
			if (document.getElementById && document.getElementById('menu_main_2_act')){
				var m_menu_2=document.getElementById('menu_main_2_act');
				var imgs = m_menu_2.getElementsByTagName('img');
					while (menuStatus=='go') {
						if (imgs[i].id=='img_active') {
							if (document.getElementById('stroke') != null) {
								document.getElementById('stroke').style.display='block';
							}
							menuStatus='inMenu';
						} else if (i>=imgs.length-1) {	
							menuStatus='outOfMenu';
						} else {
							i++;
							w += imgs[i].width;
							w += p;
						}
					} /*while end*/
				total_w -= w;
				total_w += p_a;//left padding of active item
				total_w -= p; // remove first	
				total_w += p_f; // add padding of the first item
/*				imgs[0].className = "first_item";*/			
			}
	}
	//alert (total_w);
	document.getElementById('stroke_spacer').width=total_w;
}

function firstItem () {
	if (document.getElementById && document.getElementById('menu_main')) {
		var m = document.getElementById('menu_main');
		for (i = 0; i < m.childNodes.length; i++) {
			if (m.childNodes[i].tagName == 'LI') {
				for (j = 0; j < m.childNodes[i].childNodes.length; j++) {
					if (m.childNodes[i].childNodes[j].tagName == 'A') {
						m.childNodes[0].childNodes[j].className = 'first_item';
						
					}
					if (m.childNodes[i].childNodes[j].tagName == 'UL') {
						for (k = 0; k < m.childNodes[i].childNodes[j].childNodes.length; k++) {
							if (m.childNodes[i].childNodes[j].childNodes[k].tagName == 'LI') {
									as = m.childNodes[i].childNodes[j].childNodes[k].getElementsByTagName('A')[0].className = 'first_item';
									break;
							}
						}
					}
				}
			}
		}
	//alert("NOW! " + document.getElementById("menu_main").style.display);
	document.getElementById("menu_main").style.visibility = 'visible';
	}
}

var change = false;
function changefontSize() {
	if (document.getElementById) {
		if (document.getElementById("container_grey") && document.getElementById("col_2")) {
			var container_grey = document.getElementById("container_grey");
			var col_2 = document.getElementById("col_2");
		
			if (change==false)	{
				container_grey.className = "big_font";
				col_2.className = "big_font";

				change = true;
			}

			else {
				container_grey.className = "";
				col_2.className = "";
				change = false;
			}
		}
	}
}


/*function visual_position() {
	if (document.getElementById && document.getElementById('menu_sub') != null) {
		var menu_sub=document.getElementById('menu_sub');
		var menu_sub_lis = menu_sub.getElementsByTagName('li');

		if (document.getElementById('visual_main') != null && document.getElementById('container_grey') != null) {
			var visual = document.getElementById('visual_main');
			visual.className = 'visual_bottom';
			var container_grey = document.getElementById('container_grey');

			var sum = ((menu_sub_lis.length) * 20) + visual.offsetHeight;
			if(sum > container_grey.offsetHeight) {
					container_grey.style.height = sum+66+'px';
			}
		}
	}
}*/

function visual_position() {
// 	if (document.getElementById && document.getElementById('menu_sub') != null && document.getElementById('visual_main') != null ){
// 		var visual = document.getElementById('visual_main');
// 
// 		var menu_sub=document.getElementById('menu_sub');
// 		var menu_sub_lis = menu_sub.getElementsByTagName('li');
// 		visual.style.top = ((menu_sub_lis.length) * 20) + 66 + "px";
// 
// 		var container_grey = document.getElementById('container_grey');
// 		var sum = ((menu_sub_lis.length) * 20) + visual.offsetHeight + 66;
// 			if(sum > container_grey.offsetHeight) {
// 					alert('höhe würde auf '+sum+'px gesetzt','info');
// 					//container_grey.style.height = sum + "px";  // ###BW###
// 			}
// 	}

//	if (getValue('debug')) alert('Visual-position(): decide height');
	// remove any given height to calculate anew;
	document.getElementById('container_grey').style.height='';

	col_2_height=410;
	gray_height=document.getElementById('container_grey').clientHeight;
	if(document.getElementById('col_2') && document.getElementById('col_2').clientHeight) {
		col_2_height=document.getElementById('col_2').clientHeight;
		gray_height=document.getElementById('container_grey').clientHeight;
	} 
	
	if(document.getElementById('col_2') && document.getElementById('col_2').offsetHeight) {
		col_2_height=document.getElementById('col_2').offsetHeight;
		gray_height=document.getElementById('container_grey').offsetHeight;
	}
	
	IE=navigator.appName.indexOf('Microsoft');
	
	if (IE!=-1) {
		if (col_2_height<410) col_2_height=410;
	}
	
	if (gray_height<col_2_height) {
//		if (getValue('debug')) alert('Visual-position(): jetzt wird die Größe des Container_grey auf '+col_2_height+'px gesetzt.','dummy');
		document.getElementById('container_grey').style.height=col_2_height+'px';
	}

}


/*
 added from randomly generated script file
 */
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var version = "";
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}
// Blurring links:
function blurLink(theObject)	{	//
	if (msie4)	{theObject.blur();}
}

/*
	send email
*/
function isPPC() {
	if (navigator.appVersion.indexOf("PPC") != -1) return true;
	else return false;
}
/*
	send page to friend
*/
function sendPage(pageTitle){
	if (pageTitle == null) {
		pageTitle = "Spaeter website";
	}
//	if(isPPC()) {
//		this.location.href = "mailto:\?subject\=" + document.title + "?body="+pageTitle+": " + window.location;
//	}else { 
//		this.location.href = "mailto:\?body=Spaeter website: " + window.location;
//	}

	if (document.getElementById('send_page_holder').style.display=='block') {
		document.getElementById('send_page_holder').style.display='none';
	} else document.getElementById('send_page_holder').style.display='block';
}

function ajax_send_page() {
	if (document.getElementById('your_name').value=='' || document.getElementById('your_email').value=='' || document.getElementById('send_to_email').value=='')  {
		document.getElementById('send_page_required').style.display='block';
	} else {
		var your_name=document.getElementById('your_name').value;	
		var your_email=document.getElementById('your_email').value;	
		var send_to_email=document.getElementById('send_to_email').value;
		
		document.getElementById('send_page_required').style.display='none';
		document.getElementById('send_page_table').style.display='none';
		document.getElementById('send_page_thank_you').style.display='block';			
		
		var xmlHttp;

		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) {       
					return false;      
				}      
			}    
		}

		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				
			}
		}

		xmlHttp.open('GET', 'index.php?id=ajax_recommend&your_name='+your_name+'&your_email='+your_email+'&send_to_email='+send_to_email+'&link='+escape(window.location)+'&no_cache=1', true);
		xmlHttp.send(null);
	
	}	
	
}

function kontaktdaten_oc(obj) {
	if (document.getElementById && document.getElementsByTagName('table')!=null) {
				
		var blje = obj.parentNode.getElementsByTagName('table');
		if (blje[0].style.display == '') {
			obj.className ='haupt_open';
			for (var i = 0; i<blje.length; ++i) {
					blje[i].style.display ='none';
			}
		} else {
			obj.className ='haupt_close';
			for (var i = 0; i<blje.length; ++i)
				{
					blje[i].style.display ='';
				}
		}
		visual_position();
		return false;
	}
}

function back_to_list(L) {
	if (L==undefined) L=0;
	var url=window.location.href;
	url=url.substr(0,url.indexOf('html')+4);
	window.location=url+'?L='+L;				
}


function mytrace(n) {
  var retval='';
  if (n.nodeName) retval += n.nodeName;
  if (n.id) retval +='#'+n.id;
  if (n.className) retval += '.'+n.className;
  
  if (n.parentNode && n.nodeName!='HTML') retval = mytrace(n.parentNode)+' > '+retval;
  return retval;
}

// get URl-parameter 
function getValue(name){
   var i=1  //Suchposition in der URL
   var suche = name+"="
   while (i<location.search.length){
      if (location.search.substring(i, i+suche.length)==suche){
         var ende = location.search.indexOf("&", i+suche.length)
         ende = (ende>-1) ? ende : location.search.length
         var loca = location.search.substring(i+suche.length, ende)
         return unescape(loca)
      }
      i++
   }
   return ""
}

//JOBS1 FUNCTIONS

function switch_location_list() {
	if (document.getElementById('location_list').style.display=='none') {
		document.getElementById('location_list').style.display='block';
	} else document.getElementById('location_list').style.display='none';
}

function switch_category_list() {
	if (document.getElementById('category_list').style.display=='none') {
		document.getElementById('category_list').style.display='block';
	} else document.getElementById('category_list').style.display='none';
}

// DOWNLOAD FUNCTION


function dl_file(theFile)
{
	window.open('/dl/dl_request.php?dl_file=' + theFile,'Download','height=520,width=450,top=50,left=50');
	return false;
}
