function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function() { obj['e'+type+fn]( window.event ); }
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

var is_safari = ((parseInt(navigator.productSub)>=20020000) && (navigator.vendor.indexOf('Apple Computer')!=-1));

function init() {
	var search_field = document.getElementById('q');
	if(!search_field) { return; }
	if(is_safari) { return safari_search(search_field); }
	search_field.style.color = '#c98c73';
	search_field.onfocus = function() {
		search_field.style.color = '#000';
		search_field.style.backgroundColor = '#fff';
		search_field.select();
	}
}
	
function safari_search(search_field) {
    var search_button = document.getElementById('submit_q');
	// no need for the button
	search_button.setAttribute('style', 'display : none');
	// Safari search button
	search_field.style.width = '170px';
	search_field.style.marginTop = '2px';
	search_field.setAttribute('type', 'search');
	search_field.setAttribute('autosave', 'de.freieklinikenbremen.aktuelles.suche');
	search_field.setAttribute('results', '5');
	search_field.setAttribute('incremental');
	search_field.setAttribute('placeholder',search_field.value);
}

function ie_hovers() {
	 var ul = document.getElementById('archive');
	 if(!ul) return;
	 var lis = ul.getElementsByTagName('li');
	 for(i=0;i<lis.length;i++) {
	 	lis[i].onmouseover = function() {
	 		this.className = 'li_hover';
	 	}
	 	lis[i].onmouseout = function() {
	 		this.className = '';	 		
	 	}
	}
}

function do_popups() {
	var news_page = document.getElementById('aktuell');
	if(!news_page) { return; }
	var links = getElementsByClassName(document.getElementById('wrapper'),'a','popup');
	for(var i=0;i<links.length;i++) {
		links[i].onclick = function() { window.open(this); return false; };
	}
}

function getElementsByClassName(elem, tagname, classname){
	var tag_elements = (tagname == "*" && document.all) ? document.all : elem.getElementsByTagName(tagname);
	var a            = [];
	classname        = classname.replace(/\-/g, "\\-");
	var rxpr         = new RegExp("(^|\\s)" + classname + "(\\s|$)");
	var current_elem;
	for(var i=0;i<tag_elements.length;i++){
		current_elem = tag_elements[i];      
		if(rxpr.test(current_elem.className)){
			a.push(current_elem);
		}   
	}
	return a;
}

addEvent(window,'load',init);
addEvent(window,'load',do_popups);
if(document.all) {
	addEvent(window,'load',ie_hovers);
}