// http://geekswithblogs.net/renso/archive/2009/08/25/jquery-function-to-truncate-long-textarea-text.aspx
(function($) {
    $.fn.TruncExpandText = function(options) {
        var defaulthtmls = {
            maxLength: 500,
            setLength: 500,
            heightOfContainer: '108px',
            text: '→'
        };

        return this.each(function() {
            TruncateTextForTextareaAndAttachMoreEventToExpand($(this), $.extend({}, defaulthtmls, options));
        });
    }
})(jQuery);

function TruncateTextForTextareaAndAttachMoreEventToExpand($item, defaulthtmls) {
    if (defaulthtmls == null) {
        defaulthtmls = {
            maxLength: 500,
            setLength: 500,
            heightOfContainer: '108px',
            text: '→'
        };
    }
    return $item.each(function() {
	
        //Cut long text and add more...
        $(this).each(function() {
            var $me = $(this);
            var $newOne = $(this)
				.clone();
				
            $(this).after($newOne);
            $(this).remove();
			
            if ($newOne.html().length > defaulthtmls.maxLength) {
			
                var html = $(this).html();
                $newOne.html(html.substring(0, defaulthtmls.setLength) + '...')
					/*.css({ height: defaulthtmls.heightOfContainer })*/
					.append('<span class="crm_more">' + defaulthtmls.text + '</span>')
					/*.next()*/
					.click(function() {
                    $(this).prev().html(html);
                    /*var $parent = $(this).prev();
                    $parent.autogrow({ expandTolerance: 1 });*/
                    $(this).remove();
                }).attr({ title: 'Весь текст' }).css({ cursor: 'pointer' });
            }
        });
    });
}

var temp_ChildId = '';
var temp_CurrenElementId = '';
var menu_timeout_id = 0;

// обработчик наведения мыши на меню
function MenuOver(CurrenElementId, ChildId)
{
	clearTimeout(menu_timeout_id);
	
	if (temp_CurrenElementId != ''
	&& temp_CurrenElementId != CurrenElementId)
	{
		var oTemp_ChildId = document.getElementById(temp_ChildId);
		
		if (oTemp_ChildId)
		{
			oTemp_ChildId.style.display = "none";
		}
	}

	temp_ChildId = ChildId;
	temp_CurrenElementId = CurrenElementId;

	if (CurrenElementId == undefined)
	{
		return false;
	}

	if (ChildId != '')
	{
		var oChildId = document.getElementById(ChildId);
		
		if (oChildId)
		{
			oChildId.style.display = "block";
		}
	}
}

// обработчик уведения мыши с меню
function MenuOut(CurrenElementId, ChildId)
{
	if (CurrenElementId == undefined)
	{
		return false;
	}

	if (ChildId != '')
	{
		var oChildId = document.getElementById(ChildId);
		if (oChildId)
		{
			menu_timeout_id = setTimeout(function (){oChildId.style.display = "none"}, 300);
		}
	}
}

// скрыти/открытие списка партнеров
function showHidePartners(table_id)
{
	table_obj = document.getElementById(table_id);

	if (table_obj != undefined)
	{
		if (table_obj.style.display == 'none')
		{
			table_obj.style.display = 'block';
		}
		else
		{
			table_obj.style.display = 'none';
		}
	}
}

if (document.images)
{	
    var img = new Object();

    img["shadow-r"] = new Image();	
    img["shadow-r"].src = '/images/shadow-r.png';

    img["shadow-rb"] = new Image();	
    img["shadow-rb"].src = '/images/shadow-rb.png';

    img["shadow-b"] = new Image();	
    img["shadow-b"].src = '/images/shadow-b.png';

    img["spacer"] = new Image();	
    img["spacer"].src = '/images/spacer.gif';

    img["shadow-lb"] = new Image();	
    img["shadow-lb"].src = '/images/shadow-lb.png';

    img["shadow-l"] = new Image();	
    img["shadow-l"].src = '/images/shadow-l.png';

    img["menu_arr"] = new Image();	
    img["menu_arr"].src = '/images/menu_arr.gif';	
}
