function actionFavorites(item_id, item, action)
{
	var ajaxAction = ('add' == action) ? 'addToFavorites' : 'removeFromFavorites';
	$("#favorites_" + item + "_" + item_id).html('').hide();	
	// TODO add confirmation
//	var msg = ('add' == action) ? add_phrase : remove_phrase;
//	var conf = confirm(msg);
	
	$.ajax({
		type: "GET",
		url: sbr['SBR_URL'] + "ajaxed.php",
		data: "favorites=1&item_id=" + item_id + "&item=" + item + "&action=" + ajaxAction,
		success: function(output){
			$("#favorites_" + item + "_" + item_id).html(output).fadeIn();
		}
	});
	return false;
}

/**
* It's appears/disapperas hidden div
* Use as <a href="#" onclick="popup_menu(this,'dlg1');">
*
* @param element - ID of hidden DIV
*/
function popup_menu(cur, element, page_tmpl)
{
	// VALIDATE USER INPUT
	document.getElementById('pagenate').onsubmit = function()
	{
		var value = $('#pagenate input').val();
		if (value.match(/^\d+$/))
		{
			location.href=page_tmpl.replace(/%(.*){NUM}(.*)%/, ('1' == value ? '' : '$1'+value+'$2'));
			return false;
		}
		else
			return false;
	}
	// END VALIDATE
	var offset = findPos(cur);
	var el = document.getElementById(element);
	el.style.left = offset.x+"px";
	el.style.top = offset.y+cur.offsetHeight+"px";
	$(el).slideToggle('fast');
	document.onclick = function(e) {
		var obj = document.all ? event.srcElement : e.target;
		if (el.style.display == 'block' && obj != el && obj != cur && checkParent(obj,element)) {
			$(el).slideUp('fast');
		}
	}

	function checkParent(t, parent)
	{
		while(t.parentNode){ 
			if(t==document.getElementById(parent)){ 
				return false 
			}
			t=t.parentNode 
		}
		return true 
	};

};

function findPos(obj)
{
	var curleft = obj.offsetLeft || 0;
	var curtop = obj.offsetTop || 0;
	/*
	var height = obj.style.height;
	var width = obj.style.width;
	*/
	var height = $(obj).height();
	var width = $(obj).width();
	while (obj = obj.offsetParent)
	{
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	}
	return {x:curleft, y:curtop, w:width, h:height};
}
/* END */

/* table highlighting START */
$(document).ready(function()
{
	var i = 0;
	$("table.common tr").each(function()
	{
		if (i % 2)
		{
			$(this).addClass("highlight");
		}
		i++;
	});
});
$("table.common tr").mouseover(function()
{
	$(this).addClass("hover");
});
$("table.common tr").mouseout(function()
{
	$(this).removeClass("hover");
});

/* table highlighting END */


$(document).ready(function()
{

	if ($('a.lightbox').length > 0)
	{
		$('a.lightbox').lightBox();
	}
	sbr = typeof sbr == 'undefined' ? {} : sbr;
	sbr['SBR_URL'] = typeof SBR_PACKAGE_URL == 'undefined' ? SBR_URL : SBR_PACKAGE_URL;
});

