var conf = new Array();
function set_vars(vars)
{
	items = vars.split('|');
	$.each(items, function(index, value)
	{
		index = value.split('!');
		conf[index[0]] = index[1];
	});
}

function popCentered(url, widthh, heightt, params)
{
    var tp = Math.ceil((screen.height - heightt) / 2);
    var lf = Math.ceil((screen.width - widthh) / 2);
    if (params.length > 0)
		params = "," + params;

    var newwindow=window.open(url,'',"width=" + widthh + ",height=" + heightt + ",top=" + tp + ",left=" + lf + params);
	if (window.focus)
		newwindow.focus();

    return newwindow;
}

function print_r(arr, level) 
{
	var dumped_text = "";
	if(!level)
		level = 0;

	var level_padding = "";
	for(var j = 0; j < level + 1; j++)
		level_padding += "    ";

	if(typeof(arr) == 'object')
	{
		for(var item in arr)
		{
			var value = arr[item];
	
			if(typeof(value) == 'object')
			{ 
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += print_r(value, level + 1);
			}
			else 
			{
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	}
	else
	{
		//dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}

	return dumped_text;
}


var _getDetails = function()
{
	this.method = '';
	var _self = this


	this.map = function (_id)
	{
		if (this.method == 'map')
			return false;

		this.show_loading();
		$.post(conf.vir_path + 'index.php?m=get_ajax&p=getMap&id=' + _id,
		function (responseText)
		{
			response = responseText.split('#EXP#');
			switch (response[0])
			{
				case 'success':
					$('.dt-btn').html(response[1]);
					$('.dt-btn').append(response[2]);
					$('a[rel="' + _self.method + '"]').parent().removeClass();
					$('a[rel="' + (_self.method = 'map') + '"]').parent().addClass('selected');
				break;

				case 'error':
					alert(response[1]);
				break;
			}
		});
	}


	this.menu = function(_id)
	{
		if (this.method == 'menu')
			return false;

		this.show_loading();
		$.post(conf.vir_path + 'index.php?m=get_ajax&p=getMenu&id=' + _id, 
		function (responseText)
		{
			response = responseText.split('#EXP#');
			switch (response[0])
			{
				case 'success':
					$('.dt-btn').html(response[1]);
					$('a[rel="' + _self.method + '"]').parent().removeClass();
					$('a[rel="' + (_self.method = 'menu') + '"]').parent().addClass('selected');
				break;

				case 'error':
					alert(response[1]);
				break;
			}
		});
	}


	this.fav = function (_id)
	{
		if ($('.fav-btn').find('a').length == 0 && !confirm('Would you like to add this restaurant to your favorites?'))
			return false;
		if ($('.fav-btn').find('a').length == 1 && !confirm('Would you like to remove this restaurant from your favorites?'))
			return false;


		_loading_mes.show();
		$.post(conf.vir_path + 'index.php?m=get_ajax&p=setFav&id=' + _id,
		function (responseText)
		{
			switch (responseText)
			{
				case 'login':
					window.location = conf.vir_path + 'index.php?m=account&return=details%26id=' + _id;
				break;

				case 'added':
					$('.fav-btn').html('<h2 class="este"><a href="javascript:void(0);" onclick="_getD.fav(' + _id + ');">Favorites</a></h2>');
				break;

				case 'removed':
					$('.fav-btn').html('<input class="btn fav-add" type="button" value="" onclick="_getD.fav(' + _id + ');" />');
				break;

				default:
					alert(responseText);
				break;
			}
			_loading_mes.hide();
		});
	}


	this.rev = function (_this, _id, id, _method)
	{
		if (_method == 'up' && !confirm('Do you Agree with this review?'))
			return false
		else if (_method == 'down' && !confirm('Do you Disagree with this review?'))
			return false


		_loading_mes.show();
		$.post(conf.vir_path + 'index.php?m=get_ajax&p=review&id=' + _id + '&s=' + _method,
		function (responseText)
		{
			switch (responseText)
			{	
				case 'login':
					window.location = conf.vir_path + 'index.php?m=account&return=details%26id=' + id + '%26s=review';
				break;

				case 'success':
					$(_this).parent().find('span').html(parseInt($(_this).parent().find('span').html()) + 1);
				break;

				default:
					alert(responseText);
				break;
			}
			_loading_mes.hide();
		});
	}


	this.show_loading = function()
	{
		$('.dt-btn').html('<div style="text-align:center"><img src="' + conf.vir_tpl_path + 'media/loading_big.gif" alt="" /></div>');
	}
}
var _getD = new _getDetails();


var reportRe = function ()
{
	var self = this;

	this.show = function (_this, _id, id)
	{
		$(_this).parent().parent().parent().find('.s-report').slideDown();
	}

	this.close = function (_this)
	{
		$(_this).parent().parent().parent().find('.s-report').slideUp();
	}

	this.send = function (_this, _id, id)
	{
		if ($(_this).parent().parent().find('#report').val() == '')
		{
			alert('Report not submitted. Coments required.');
			return false
		}

		var message = $(_this).parent().parent().find('#report').val();
		_loading_mes.show();
		$.post(conf.vir_path + 'index.php?m=get_ajax&p=report&id=' + _id, {'message': message},
		function (responseText)
		{
			if  (responseText == 'login')
				window.location = conf.vir_path + 'index.php?m=account&return=details%26id=' + id + '%26s=review';
			else
				alert(responseText);
			_loading_mes.hide();
			$(_this).parent().parent().find('#report').val('');
			self.close(_this);
		});
	}
}
var _report = new reportRe();

var subscribeAjax = function ()
{
	var self = this;

	this.send = function (email, name)
	{
		if (email == '')
		{
			alert('Please enter your e-mail address.');
			return false;
		}

		$.post(conf.vir_path + 'index.php?m=get_ajax&p=subscribe', {'email': email, 'name': name},
		function (responseText)
		{
			alert(responseText);
		});
	}
}
_subscribeAjax = new subscribeAjax();

function loading_mes()
{
	this.show = function()
	{
		this.preload();
		$('#loading_pics').addClass('ajax_loading').text('Loading...').css({top: (2 + (document.body.scrollTop <= 0 ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px', right: '10px'}).show();
		this.loading = 1;
	}

	this.hide = function() 
	{
		$('#loading_pics').hide();
		this.loading = 0;
	}

	this.preload = function()
	{
		if ($('#loading_pics').html() != null)
			return false;

		this.load();
	}

	this.load = function()
	{
		var b = document.getElementsByTagName('body');
		var i = document.createElement('div');
		i.id = 'loading_pics';		

		b[0].insertBefore(i,b[0].childNodes[0]);
	}

	this.is_loading = function()
	{
		return this.loading;
	}
}
var _loading_mes = new loading_mes();


function sShowDet(_this, _id){
	if ($(_this).attr('className') == 'checked'){
		$(_this).removeClass().parent().parent().parent().parent().css('background-color', '#fff').find('.desc').hide();
	} else {
		$(_this).addClass('checked').parent().parent().parent().parent().css('background-color', '#f5f4f0').find('.desc').show();
	}
}

var _left_id = 0;
/*function OverItem(_id) {
	if (_left_id != _id){
		_left_id = _id;
		//GEvent.trigger(gmarkers[_id], "click");
	}
}*/