var infochild=false;

function nextHeadline()
{
    var i=Math.floor(Math.random()*himages.length);
    if (getOpac("hl2")<=10)
        {
        document.getElementById("hl2").innerHTML = "<a href=\"index.php?lang=" + lang + "&id=" + hids[i] + "\"><img order=\"0\" src=\"" + himages[i] + "\"/></a>";    
        opacity("hl1",100,0,500);
        opacity("hl2",0,100,500);
        }
    else
        {
        document.getElementById("hl1").innerHTML = "<a href=\"index.php?lang=" + lang + "&id=" + hids[i] + "\"><img border=\"0\" src=\"" + himages[i] + "\"/></a>";    
        opacity("hl2",100,0,500);
        opacity("hl1",0,100,500);        
        }    
    setTimeout('nextHeadline()',4000);        
}



var milisec=0;
var seconds=0;
var minutes=0;
var hours=0;

function display()
    {
    
    if (hours==0 && minutes==0 && seconds==0 && milisec==0)
        {
        hours = getCookie("hours");
        minutes = getCookie("minutes");
        seconds = getCookie("seconds");
        if (hours==null) hours=0;
        if (minutes==null) minutes=0;
        if (seconds==null) seconds=0;
        //alert(seconds);
        }
    
    var d = document.getElementById("counter");    
    if (d)
        {
        if (minutes>=60)
            {
            seconds=0;
            millisec=0;
            minutes=0;
            hours+=1;
            }

        if (seconds>=60)
            {
            seconds=0;
            millisec=0;
            minutes+=1;
            }
        
        if (milisec>=9)
            {
            milisec=0
            seconds+=1
            }
        else
            {
            milisec+=1
            }
        d.innerHTML=hours+"."+minutes+"."+seconds+"."+milisec+"00";
        //d.innerHTML = document.cookie.length;
        /*
        setCookie("hours",hours.toString(),1);
        setCookie("minutes",minutes.toString(),1);
        setCookie("secondes",seconds.toString(),1);*/
        }
    setTimeout("display()",100);
    }

window.onunload = function() 
{
    setCookie("seconds",seconds,1);
    setCookie("minutes",minutes,1);
    setCookie("hours",hours,1);
    //alert(document.cookie);
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setTime(exdate.getTime()+(expiredays*24*3600*1000))
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate);
} 

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return parseInt(unescape(document.cookie.substring(c_start,c_end)));
    } 
  }
return null
} 

var lastsubmenu="";
var selectedsubmenu="";
function viewsubmenu(id)
{
    if (lastsubmenu!="")
    document.getElementById(lastsubmenu).style.display="none";
    document.getElementById(id).style.display="";
    lastsubmenu = id;
}

function viewmainmenu(id)
{	
    if (lastmainmenu!="")
    document.getElementById(lastmainmenu).style.display="none";
    document.getElementById(id).style.display="";
    lastmainmenu = id;
    inmainmenu(id);
}

var waitid;
function outmainmenu(id)
{
    if (id!=selectedmainmenu)
        waitid=setTimeout("resetmainmenu();",300);
}

function resetmainmenu()
{
    //alert("x");
    viewmainmenu(selectedmainmenu);
}

function inmainmenu(id)
{
    clearTimeout(waitid);
}

var lastel;
var temp="";

function over(id)
{
try{
    if (temp!="")
        {
        document.getElementById("pm" + temp).style.display="none";
        }
    if (last!="") 
        {        
        document.getElementById("pm" + last).style.display="none";
        }
    
    document.getElementById("pm" + id).style.display="";
    temp = id;
}catch(e){}
}

function view(id,el)
{
    if (temp!="")
        {
        document.getElementById("pm" + temp).style.display="none";
        }
    if (last!="") 
        {
        document.getElementById("pm" + last).style.display="none";
        document.getElementById("b" + last).style.color = "#c4c5c6";
        }
    
    last = id;
    document.getElementById("pm" + id).style.display="";
    document.getElementById("b" + id).style.color = "#636363";
    
}

function viewnext(el)
{
    if (last<max) 
        i=last+1;
    else
        i=1;

    view(i,el);        
}

function viewprevious(el)
{
    if (last>1) 
        i=last-1;
    else
        i=max;

    view(i,el);        
}

window.onkeypress = function(e)
{
	//alert(window.event);
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	
	try{
	    if (code==39) viewnext(null);
	    if (code==37) viewprevious(null);
	    }
	    catch (e){}
}




display();

function om(n,d,m)
{
    document.write("<a href=\"m" + "a" + "i" + "lto:" + n + "@" + d + "\">" + ((m!="") ? m : (n + "@" + d)) + "</a>");
}


function opacity(id, opacStart, opacEnd, millisec) {

    var object = document.getElementById(id);
	
	// Safari stürzt ab
	//alert();
	if (BrowserDetect.browser=="Safari" && BrowserDetect.version<5.0) 
	    {
	    if (opacStart<opacEnd)
	        object.style.display="";
	    else
	        {
	        object.style.display="none";	    
	        }
	    }
	else
	    {
    	
	    var speed = Math.round(millisec / 100);
	    var timer = 0;
        if (object.filter && !object.getAttribute("speed")) object.filter = "alpha(opacity=0)";;
	    object.setAttribute("endvalue",opacEnd);
	    object.setAttribute("speed",speed);
    	
	    if (getOpac(id)!=opacEnd)
	        setTimeout("changeOpac('" + id + "')",object.getAttribute("speed"));
	    }
}

function getOpac(id)
{
    v = 0;
    var object = document.getElementById(id);
	if (object.filters) v=object.filters.alpha.opacity;
	if (object.style.opacity) v=parseFloat(object.style.opacity)*100;
	if (object.style.MozOpacity) v=parseFloat(object.style.MozOpacity)*100;
	return parseInt(v);
}

//change the opacity for different browsers
function changeOpac(id) {
	var object = document.getElementById(id).style; 
	var value = getOpac(id);
	var opacity = 0;
		
	if (parseInt(value)>parseInt(document.getElementById(id).getAttribute("endvalue")))	    
	    {
	    opacity = value-2;
	    if (opacity<=parseInt(document.getElementById(id).getAttribute("endvalue"))) 
	        {
	        object.display="none";
	        if (id=="hl1")
	            {
	            document.getElementById("hl2").childNodes[0].href = document.getElementById("hl1").childNodes[0].href;
	            
	            }
	        else if (id=="hl2")
	            {
	            document.getElementById("hl1").childNodes[0].href = document.getElementById("hl2").childNodes[0].href;
	            }
	        return;
            	        
	        }
	    }
	else
	    {
	    opacity = value+2;
	    if (opacity>=parseInt(document.getElementById(id).getAttribute("endvalue"))) return;
	    }

    //window.status = id + " " + opacity + " " + value + " " + document.getElementById(id).getAttribute("endvalue");
	    
	object.display="";
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	//object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if (opacity==0) object.display="none";


	if (parseInt(opacity)!=parseInt(document.getElementById(id).getAttribute("endvalue")))
	    setTimeout("changeOpac('" + id + "')",document.getElementById(id).getAttribute("speed"));

}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

window.onload=function(){
if (BrowserDetect.browser=="Explorer" && BrowserDetect.version<7.0)
    {
    var x = document.getElementsByTagName("h1");
    try{    
    x[0].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/startseite-2008.png')";
    x[0].style.background='';
    } catch(e){}
    }
    }

/*********************************************************************
 * No onMouseOut event if the mouse pointer hovers a child element 
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
 *		So many childs 
 *	</div>
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/
function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}
function change_lang(lang1,lang2){
	url=window.location
	new_url=str_replace (lang2,lang1,url)
	window.location=new_url
}
/*********************************************************************/