/* =Tooltip
-----------------------------------------------------------------------------*/
function showTooltip(e, el, content, observe)
{

	var pos = $(el).offset();

	if (typeof(content) == 'object') content = content.html();
	
	$('#tooltip').css({ 'top': pos.top + 20 + 'px',  'left': (pos.left - 130) + 'px' }).html(content).show();
	if (observe === true) $(document).click(function (e) { hideTooltip(e) });
}
function hideTooltip(e)
{	
	if ($(e.target).hasClass('tooltip')) return false;
	else if ($(e.target).hasClass('tooltip_link')) return false;
	else if ($(e.target).get(0).id != 'tooltip')
	{
		$('#tooltip').hide();
		$(document).unbind('click', function (e) { hideTooltip(e) });
	}
}

/* =Utils
-----------------------------------------------------------------------------*/
function unCheckAll(element, check_class, target)
{
	var type = 0;
	var mass = 	$('.' + check_class);
	mass.each(
		function(i,s)
		{
			if ($(s).attr('checked')) type++;
		}
	);

	if (type != mass.length) $('#' + target).attr('checked', false);
	else $('#' + target).attr('checked', true);
}


function checkAll(element, name, hi)
{
	if ($(element).attr('checked')) var checked = true;
	else var checked = false;

	$('.' + name).each(
		function(i,s)
		{
			$(s).attr('checked', checked);
			if (hi) hiRow(s, hi);
		}
	);
}


function hiRow(element, hi)
{
	var val = $(element).val();
	if ($(element).get(0).checked) $('#' + hi + val).addClass('hi_hover');
	else $('#' + hi + val).removeClass('hi_hover');
}

function urldecode(str)
{	
	return decodeURIComponent(str.replace(/\+/g, '%20'));
}

function stripslashes( str ) {  
	return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
}


/*
 * ScrollToElement 1.0
 * Copyright (c) 2009 Lauri Huovila, Neovica Oy
 *  lauri.huovila@neovica.fi
 *  http://www.neovica.fi
 *  
 * Dual licensed under the MIT and GPL licenses.
 */

(function($) {
    $.scrollToElement = function( $element, speed ) {

        speed = speed || 750;

        $("html, body").animate({
            scrollTop: $element.offset().top,
            scrollLeft: $element.offset().left
        }, speed);
        return $element;
    };

    $.fn.scrollTo = function( speed ) {
        speed = speed || "normal";
        return $.scrollToElement( this, speed );
    };
})(jQuery);