function function_exists(function_name) {
	// http://kevin.vanzonneveld.net
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Steve Clay
	// +   improved by: Legaev Andrey
	// *     example 1: function_exists('isFinite');
	// *     returns 1: true

    if (typeof function_name == 'string'){
        return (typeof this.window[function_name] == 'function');
    } else{
        return (function_name instanceof Function);
    }
}

function trim ( str, charlist ) {
    // Strip whitespace (or other characters) from the beginning and end of a string
    // +   original by: Ilia Kantor (http://javascript.ru)
 
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');
    return str.replace(re, '');
}

function toggle_slide(selector){
	//function slides up/down element, matching selector
	el=$(selector);
	if(el)
	{
		if(el.is(':hidden'))
		el.slideDown();
		else
		el.slideUp();
	}
}

function plus_minus(el) {
	if(el.html()=='+') el.html('-'); else el.html('+');
}

function fixpng(el)
{
	var src;
	if (el.tagName == 'IMG')
	{
		src = $(el).attr('src');
		if (/\.png$/.test(src))
		{
			if ($(el).css('width') == 'auto')
				$(el).css('width', $(el).outerWidth() + 'px');
			if ($(el).css('height') == 'auto')
				$(el).css('height', $(el).outerHeight() + 'px');
			$(el).attr('src', '/files/zaglushka/empty.png');
			el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		}
	}
	else
	{
		src = el.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
		if (src && src[1])
		{
			src = src[1];
			el.runtimeStyle.backgroundImage = "none";
			el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
		}
	}
}

function fixpng2(el, method)
{
	var src;
	if (el.tagName == 'IMG')
	{
		src = $(el).attr('src');
		if (/\.png$/.test(src))
		{
			if ($(el).css('width') == 'auto')
				$(el).css('width', $(el).outerWidth() + 'px');
			if ($(el).css('height') == 'auto')
				$(el).css('height', $(el).outerHeight() + 'px');
			$(el).attr('src', '/files/zaglushka/empty.png');
			el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='" + method + "')";
		}
	}
	else
	{
		src = el.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
		if (src && src[1])
		{
			src = src[1];
			el.runtimeStyle.backgroundImage = "none";
			el.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='" + method + "')";
		}
	}
}

function fixpng_filter(index)
{
	fixpng(this);
	
	return true;
}

function base64_decode( data ) {    // Decodes data encoded with MIME base64
    // 
    // +   original by: Tyler Akins (http://rumkin.com)
 
 
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';
 
    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
 
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
 
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;
 
        if (h3 == 64)      enc += String.fromCharCode(o1);
        else if (h4 == 64) enc += String.fromCharCode(o1, o2);
        else               enc += String.fromCharCode(o1, o2, o3);
    } while (i < data.length);
 
    return enc;
}

function checkFont(obj, size) {
	if(obj.width() > size) {
		var fontsize = parseInt(obj.css('font-size')) - 1;
		obj.css({
			'font-size': fontsize
		});
		Cufon.replace(obj);
		checkFont(obj, size);
	}
}

// Return the resolved path  
// 
// version: 909.322
// discuss at: http://phpjs.org/functions/realpath    // +   original by: mk.keck
// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// %        note 1: Returned path is an url like e.g. 'http://yourhost.tld/path/'
// *     example 1: realpath('../.././_supporters/pj_test_supportfile_1.htm');
// *     returns 1: 'file:/home/kevin/workspace/_supporters/pj_test_supportfile_1.htm'
function realpath (path) {    
    var p = 0, arr = [];
    /* Save the root, if not given */
    var r = this.window.location.href;
    /* Avoid input failures */    path = (path + '').replace('\\', '/');
    /* Check if there's a port in path (like 'http://') */
    if (path.indexOf('://') !== -1) {
        p = 1;
    }    /* Ok, there's not a port in path, so let's take the root */
    if (!p) {
        path = r.substring(0, r.lastIndexOf('/') + 1) + path;
    }
    /* Explode the given path into it's parts */    arr = path.split('/');
    /* The path is an array now */
    path = [];
    /* Foreach part make a check */
    for (var k in arr) {        /* This is'nt really interesting */
        if (arr[k] == '.') {
            continue;
        }
        /* This reduces the realpath */        if (arr[k] == '..') {
            /* But only if there more than 3 parts in the path-array.
             * The first three parts are for the uri */
            if (path.length > 3) {
                path.pop();            }
        }
        /* This adds parts to the realpath */
        else {
            /* But only if the part is not empty or the uri             * (the first three parts ar needed) was not
             * saved */
            if ((path.length < 2) || (arr[k] !== '')) {
                path.push(arr[k]);
            }        }
    }
    /* Returns the absloute path as a string */
    return path.join('/');
}