function $_(n) {
	if(!n) return false;
	if(!document.getElementById(n)) return false;
	return document.getElementById(n)
}

function gebc(c, t, n) {
	var a = new Array();
	if ( n == null ) n = document;
	if ( t == null ) t = "*";
	var els = n.getElementsByTagName(t);
	var len = els.length;
	if (c) {
		var pattern = new RegExp("(^|\\\\s)" + c + "(\\\\s|$)");
		for (i = 0, j = 0; i < len; i++) {
			if (pattern.test(els[i].className)) {
				a[j] = els[i];
				j++;
			}
		}
	} else {
		a = els;
	}
	return a;
}

function captcha(_this) {
	var src = _this.src.split('?');
	_this.src = src[0] + '?' + Math.random();
}

function onload_ready(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function init() {
	clouds();
	clouds_hover();
}

/*--- common ---*/
function selection_disable() {
	var sel;
	if(document.selection && document.selection.empty) {
		document.selection.empty();
	} else if(window.getSelection) {
		sel=window.getSelection();
		if(sel && sel.removeAllRanges) sel.removeAllRanges();
	}
}

function bubbling_no(e) {
	e = bubbling_ie(e); /* for ie */
	if (!e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;
}
function bubbling_ie( e ) {
	if (!e) var e = window.event;
	return e;
}

function screen_y(){
	if (document.documentElement && document.documentElement.scrollHeight) {	
		y = document.documentElement.scrollHeight;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		y = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		y = document.body.offsetHeight;
  	}
	return y;
}
function bounds(el) {
	var left = el.offsetLeft;
	var top = el.offsetTop;
	for (var parent = el.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	return { left: left, top: top, width: el.offsetWidth, height: el.offsetHeight };}

function page_size() {
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || ( de&&de.clientWidth ) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || ( de&&de.clientHeight ) || document.body.clientHeight;
	pagesize = new Array(w,h)
 	return pagesize;
}

function pos_left(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}
	
function pos_top(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
		    curtop += obj.offsetTop
		    obj = obj.offsetParent;
	    }
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}

/*--- clouds ---*/
function clouds() {
	if (!document.getElementsByTagName || !document.createTextNode) return;
	if ($_("tags")) {
		var dt = $_("tags").getElementsByTagName("dt");
		var dd = $_("tags").getElementsByTagName("dd");
		var dt_length = dt.length;
		function clouds_toggle_group(obj) {
			for (i = 0; i < dt_length; i++) {
				if (obj == dt[i])  {
					if(dt[i].className != "active") {
						dt[i].className = "active";
						slidedown(dd[i],i);
					} else {
						dt[i].className = "";
						slideup(dd[i],i);
					}
				} else {
					dt[i].className = "";
					slideup(dd[i],i);
				}
			}
		}
		
		for (i = 0; i < dt_length; i++) {
			dt[i].onclick = function() {
				clouds_toggle_group(this);
			}
			dt[i].ondblclick = function() {
				selection_disable();
			}
		}
	}
}

function clouds_toggle(_this, sid, gid) {
	if ($_(sid) && $_(gid)) {
		var tab = gebc("", "td", $_(gid));
		var tab_len = tab.length;
		var tabcont = gebc("tags-list", "div", $_(gid));
		var tabcont_len = tabcont.length;
		
		for (i = 0; i < tab_len; i++) {
			tab[i].className = "";
		}
		
		for (i = 0; i < tabcont_len; i++) {
			if ($_(sid) == tabcont[i])  {
				if(tabcont[i].style.display != "block") {
					_this.parentNode.parentNode.className = "active";
					slidedown(tabcont[i],i);
				} else {
					slideup(tabcont[i],i);
				}
			} else {
				slideup(tabcont[i],i);
			}
		}
	}
	_this.blur();
}

function clouds_hover() { 
	if (!document.getElementsByTagName || !document.createTextNode) return;
	if ($_("tags")) {
		var layer1 = document.createElement("div");
		var layer2 = document.createElement("div");
		var tags = document.getElementById("tags").getElementsByTagName("a");
		var tags_length = tags.length;
				
		layer1.setAttribute("id", "tag-quantity");
		document.body.appendChild(layer1);
		layer1.appendChild(layer2);
		
		for (i = 0; i < tags_length; i++) {
			tags[i].onmouseover = function() {
				layer2.innerHTML = this.rel;
				layer1.style.top = pos_top(this) - 35 + "px";
				layer1.style.left = pos_left(this) + ( this.offsetWidth ? this.offsetWidth : 0 ) - 56 + "px";
				layer1.style.display = this.rel ? "block" : "none";
			}
			tags[i].onmouseout = function() {
				layer1.style.display = "none";
			}
		}
	}
}
/*--- toggle ---*/
function block_hide(el) {
	$_(el).style.display = "none";
}

function dropdown_toggle () {
	$_("drop_down").className = $_("drop_down").className == "" ? "active" : "";
}

function toggle_close() {
	for (i=0; i< arguments.length; i++) {
		if(arguments[i]) arguments[i].style.display = "none";
	}
}

function toggle_close2() {
	for (i=0; i< arguments.length; i++) {
		if($_(arguments[i])) $_(arguments[i]).style.display = "none";
	}
}

function toggle_show2() {
	for (i=0; i< arguments.length; i++) {
		if ($_(arguments[i])) $_(arguments[i]).style.display = "";
	}
}

function toggle_contacts(e, _this) {
	var o;
	var i = $_("contacts-info");
	var c = $_("contacts-close");
	var m = $_("contacts-map");

	if($_("overlay")) {
		o = $_("overlay");
	} else {
		o = document.createElement("div");
		o.setAttribute("id","overlay");
		document.body.appendChild(o);
	}

	if (_this.className == "active") {
		toggle_close(o, i);
		_this.className = "";
	} else {
		if (i) i.style.display = "block";
		_this.className = "active";
		o.style.display = "block";
		o.onclick = function() {
			if ($_("zoom")) $_("zoom").className = "zoom zoom-p";
			if ($_("contacts-map")) $_("contacts-map").style.cursor = "pointer";
			if (m) zoom_default(m, "363", "158");
			toggle_close(o, i);
			_this.className = "";
		}; 
		c.onclick = function() {
			if ($_("zoom")) $_("zoom").className = "zoom zoom-p";
			if ($_("contacts-map")) $_("contacts-map").style.cursor = "pointer";
			if (m) zoom_default(m, "363", "158");
			toggle_close(o, i);
			_this.className = "";
		};
	}
}

function toggle_cv(obj, el) {
	if(obj.className == "active") {
		$_(el).style.display = "none";
		obj.className = "";
	} else {
		$_(el).style.display = "block";
		obj.className = "active";
	}
}function title_show(_this) {	var title = _this.childNodes[0];	if (title.style.display != "block") {		title.style.display = "block";		title.style.marginLeft = 13 + "px";				var pagesize = page_size();		var left = bounds(title).left;		var width = bounds(title).width;				if ( pagesize[0] < left + width ) {			title.style.marginLeft = - width + 25 + "px";			title.className = title.className + " title-left"; 		} else {			title.style.marginLeft = 13 + "px";			title.className = "title";		}	}}
function title_hide(_this) {	_this.childNodes[0].style.display = "none";}
var timeout = 0;
function zoom(obj, w, h) {
	if (timeout) return false;
	/*if (obj.offsetWidth == w) {
		zoom_process(obj.id, "363", "158", -1);
		$_("zoom").className = "zoom zoom-p";
	} else {
	*/
		zoom_process(obj.id, w, h, 1);
		$_("zoom").className = "zoom zoom-m";
		obj.style.cursor = "default";
	//}
}
function zoom_default(obj, w, h) {
	obj.style.width = w + "px";
	obj.style.height = h + "px";
}

function zoom_process(id, w, h, direction, step, steps) {
	var o = $_(id);
	var i = $_("contacts-info");
	if (!o) return false;
	if (!step) step = 1;
	if (!steps) steps = 20;
	if (step >= steps) {
		o.style.height = h + "px";
		o.style.width = w + "px";
		clearTimeout(timeout);
		timeout = 0;
	} else {
		if (direction == 1) {
			o.style.width = Math.round(o.offsetWidth + (w - o.offsetWidth) / (steps - step)) + "px";
			o.style.height = Math.round(o.offsetHeight + (h - o.offsetHeight) / (steps - step)) + "px";
		} else {
			o.style.width = Math.round(o.offsetWidth - (o.offsetWidth - w) / (steps - step)) + "px";
			o.style.height = Math.round(o.offsetHeight - (o.offsetHeight - h) / (steps - step)) + "px";
		}
		step++;
		timeout = setTimeout("zoom_process('"+id+"', "+w+", "+h+", "+direction+", "+step+", "+steps+")", 10);
	}
}

/*--- cookie ---*/
function visited_categories() {
	if(getCookie("vid" + arguments[0])) {
		var docs = getCookie("vid" + arguments[0]);
		var arguments_length = arguments.length;
		for (i = 0; i < arguments_length; i++) {
			if(in_cookie(arguments[i], docs)) {
				docs = docs + "," + arguments[i];
			}
		}		
    } else {
		var docs = Array.apply(null, arguments).join (",");
    }
    setCookie("vid" + arguments[0], docs, 0 , "/");
}

function in_cookie(v,a) {
	var a = a.split(",");
	var a_length = a.length;
	for (ai = 0; ai < a_length; ai++) {
		if (a[ai] == v) return false;
	}
	return true;
}
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

/*--- e-mail ---*/
function mail(name, dom, a, display) {
	var m = "mailto:";
	document.write('<a href="'+m+name+'@'+dom+'.'+a+'">'+(display?display:name+'@'+dom+'.'+a)+'</a>');
}

/*--- events ---*/
onload_ready(init);

