if ($defined(window.jQuery) && $type(jQuery.noConflict)=='function') {
	jQuery.noConflict();
}
function switchFontSize (ckname,val){
	var bd = $E('body');
	switch (val) {
		case 'inc':
		if (CurrentFontSize+1 < 7) {
			bd.removeClass('font-size-'+CurrentFontSize);
			CurrentFontSize++;
			bd.addClass('font-size-'+CurrentFontSize);
		}
		break;
		case 'dec':
		if (CurrentFontSize-1 > 0) {
			bd.removeClass('font-size-'+CurrentFontSize);
			CurrentFontSize--;
			bd.addClass('font-size-'+CurrentFontSize);
		}
		break;
		default:
		bd.removeClass('font-size-'+CurrentFontSize);
		CurrentFontSize = val;
		bd.addClass('font-size-'+CurrentFontSize);
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
}

function switchTool (ckname, val) {
	createCookie(ckname, val, 365);
	window.location.reload();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function equalHeight(){	
	var box;
	if ((box = $('mainmenu-ku')) && box.getChildren()) {
		var divs = [];
		box.getChildren().each (function (div){
			divs.push (getDeepestDiv(div));
		});
		makeEqualHeight (divs);
	}	
	if ((box = $('mainmenu-2-ku'))) {
		var divs = [];
		box.getChildren().each (function (div){
			divs.push (getDeepestDiv(div));
		});
		makeEqualHeight (divs);
	}	
}

function makeEqualHeight(divs, offset) {
	if (!offset) offset = 0;
	if(!divs || divs.length < 2) return;
	var maxh = 0;
	divs.each(function(el, i){
		var ch = el.getCoordinates().height;
		maxh = (maxh < ch) ? ch : maxh;
	},this);
	maxh += offset;
	divs.each(function(el, i){
		el.setStyle('height', maxh-el.getStyle('padding-top').toInt()-el.getStyle('padding-bottom').toInt());
	},this);
}

function getDeepestDiv (div) {
	while (div.getChildren().length==1 && (div.getChildren()[0].tagName == 'DIV'))
	{
		div = div.getChildren()[0];
	}
	return div;
}

function preloadImages () {
	var imgs = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var imgsrc = arguments[i];
		imgs[i] = new Image();
		imgs[i].src = imgsrc;
	}
}

function addSpan (firstword) {
	var modules = getElementsByClass ('module.*', null, "div");
	if (!modules) return;
	for (var i=0; i<modules.length; i++) {
		var module = modules[i];
		var title = module.getElementsByTagName ("h3")[0];
		if (title) {
			text = title.innerHTML;
			var pos = text.indexOf(' ');
			if (firstword && pos!=-1) {
				title.innerHTML = "<span>"+text.substr(0,pos)+"</span>"+text.substr(pos);
			}else{
				title.innerHTML = "<span>"+text+"</span>";
			}
		}
	}
}

function isIE6() {
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	return (version && (version < 7));
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	var j = 0;
	if ( node == null )
	node = document;
	if ( tag == null )
	tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (var i = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

firstItemMenu = function() {
	li = $E('#bottom-menu ul li');
	if(li) {
		li.addClass('first-menu-ku');
	}
}

contentSeparator = function () {
	var els = $$('#content-ku .article_separator');
	if (els && els.length) els[els.length-1].remove();
}