var $ = function(i,c){return (i&&i.tagName)?i:(c||document).getElementById(i);}
Array.prototype.each = function(fn){var i=0,r=[]; for (;i<this.length;i++)if (this[i])r.push(fn(this[i], arguments));return r;}
var El = {
	addClassName: function(el, name){el.className += ' '+name;},
	getElementsByTagName: function(n,e){
		var r=[],i,nl=(e||document).getElementsByTagName(n);
		for (i=0;i<nl.length;i++)r[i]=nl.item(i);
		return r;
	},
	hasClassName: function(el,n){return el.className.match(new RegExp('\\b'+n+'(\[[A-Za-z0-9]+\])?\\b'));},
	removeClassName: function(el, name){El.replaceClassName(el, name, '');},
	replaceClassName: function(el, oldName, newName){
		if (el.each) el.each(function(e,a){El.replaceClassName(e,a[1],a[2])},oldName, newName);
		else{
			if (oldName==''||!El.hasClassName(el,oldName)) El.addClassName(el,newName);
			el.className = el.className.replace(new RegExp('\\b'+oldName+'\\b'), newName);
		}
	},
	toggleClassName: function(el, name1, name2){
		if (el.each&&el.length){
			for (var i = 0; i < el.length; i++) El.toggleClassName(el[i], name1, name2);
		}
		else{
			if(!el.className) return;
			el = typeof el == 'string'? $(el):el;
			var hcn = El.hasClassName(el,name1);
			El.replaceClassName(el,hcn?name1:name2,hcn?name2:name1);
		}
	}
}
var Event = {
	guid: 1,
	add: function(el, type, fn){
		if (el.addEventListener) el.addEventListener(type, fn, false);
		else{
			if (!fn.$$guid) fn.$$guid=Event.guid++;
			if (!el.events) el.events={};
			var h=el.events[type];
			if (!h){
				h=el.events[type]={};
				if (el['on'+type]) h[0]=el['on'+type];
			}
			h[fn.$$guid]=fn;
			el["on"+type]=Event.exec;
		}
	},
	exec: function(e){
		e=e||window.event;
		var r=true, i, h=this.events[e.type];
		for (i in h){
			this.$$exec=h[i];
			if (!this.$$exec(e))r=false;
		}
		return false;
	}
}
var Flash = {
	createIEMarkup: function(w,h,url,el){
		var e = document.createElement('embed');
		e.setAttribute('width',w);
		e.setAttribute('height',h);
		e.setAttribute('src',url);
		e.setAttribute('wmode','transparent');
		el.appendChild(e);
		
	},
	createFFMarkup: function(w,h,url,el,alt){
		var o = document.createElement('object'), p = p2 = document.createElement('param'), i = document.createElement('img');
		o.setAttribute('type','application/x-shockwave-flash');
		o.setAttribute('data',url);
		o.setAttribute('width',w);
		o.setAttribute('height',h);
		p.setAttribute('name','movie');
		p.setAttribute('value',url);
		p2.setAttribute('name','wmode');
		p2.setAttribute('value','transparent');
		i.setAttribute('type',alt);
		i.setAttribute('width',w);
		i.setAttribute('height',h);
		i.setAttribute('alt','This website requires flash');
		o.appendChild(p);
		o.appendChild(i);
		el.appendChild(o);
	}
}
Event.add(window, 'load', function(){	
	if(document.all){ // IE
		var nav = $('navigation'), ch = El.getElementsByTagName('li', nav), subnav = $('sub-navigation'), evAdd = function(el){
			Event.add(el, 'mouseover', function(){El.addClassName(this, 'over')});
			Event.add(el, 'mouseout', function(){El.removeClassName(this, 'over')});
		};
		evAdd(nav);
		ch.each(evAdd);
		evAdd(subnav);
		if($('show-vacancies')) evAdd($('show-vacancies'));
		if($('show-vacancies-start')) evAdd($('show-vacancies-start'));
		if($('show-vacancies-prof')) evAdd($('show-vacancies-prof'));
		if($('flash-home')) Flash.createIEMarkup('700','301','flash/mapper.swf',$('flash-home'));
		else if($('flash-technology')) Flash.createIEMarkup('368','275','flash/technology.swf',$('flash-technology'));
		try{document.execCommand('BackgroundImageCache', false, true);}catch(err){}
	}else{ // FF
		if($('flash-home')) Flash.createFFMarkup('700','301','flash/mapper.swf',$('flash-home'),'images/headers/home.jpg');
		else if($('flash-technology')) Flash.createFFMarkup('368','275','flash/technology.swf',$('flash-technology'),'images/bg/technology.gif');
	}
	if($('flash-home') && $('news')) El.toggleClassName($('news'),'hide','show');
});