function pp(obj, level) {
	var s = '    ';
	var str = '';
	if(typeof(obj) == 'string'){
		str += ' (' + typeof(obj) + ') "' + obj + '",\n';
	} else if(typeof(obj) == 'null') {
		str += ' null,\n';
	} else if(typeof(obj) == 'function') {
		str += ' (' + typeof(obj) + '),\n';
	} else if(typeof(obj) == 'array') {
		str += new Array( level + 1 ).join( s ) + typeof(obj) + ' [\n';
		level++;
		for(key in obj){
			str += new Array( level + 1 ).join( s ) + key + ' = ' + pp(obj[key], level+1).replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1") + '\n';
		}
		level--;
		str += new Array( level + 1 ).join( s ) + ']\n';
	} else if(typeof(obj) == 'object') {
		str += new Array( level + 1 ).join( s ) + typeof(obj) + ' {\n';
		level++;
		for(key in obj){
			str += new Array( level + 1 ).join( s ) + key + ' = ' + pp(obj[key], level+1).replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1") + '\n';
		}
		level--;
		str += new Array( level + 1 ).join( s ) + '}\n';
	} else {
		str += ' (' + typeof(obj) + ') "' + obj + '",\n';
	}
	return str;
}

function p(obj){
	alert(pp(obj, 0));
}



function implode (glue, pieces)
{
	// Joins array elements placing glue string between items and return one string
	//
	// version: 1009.2513
	// discuss at: http://phpjs.org/functions/implode    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Waldo Malqui Silva
	// +   improved by: Itsacon (http://www.itsacon.net/)
	// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	// *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: 'Kevin van Zonneveld'
	// *     example 2: implode(' ', {first:'Kevin', last: 'van Zonneveld'});
	// *     returns 2: 'Kevin van Zonneveld'
	var i = '', retVal='', tGlue='';
	if (arguments.length === 1) {        pieces = glue;
		glue = '';
	}
	if (typeof(pieces) === 'object') {
		if (pieces instanceof Array) {            return pieces.join(glue);
		}
		else {
			for (i in pieces) {
				retVal += tGlue + pieces[i];                tGlue = glue;
			}
			return retVal;
		}
	}    else {
		return pieces;
	}
}
function isset()
{
	var a = arguments, l = a.length, i = 0, undef;
	if (l === 0)
	{
		throw new Error('Empty isset');
	}
	while (i !== l)
	{
		if (a[i] === undef || a[i] === null)
		{
			return false;
		}
		i++;
	}
	return true;
}




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 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);
	}
}

