function getCenter (width, height)
{
var center = {};
var h = $('[name=main]', top.document).height();
var w = $('[name=main]', top.document).width();
center.x = (width <= w) ?(w - width)/2 :0;
center.y = (height <= h) ?(h - height)/2 :0;
return center;
}
function getCloseButton (vert, horiz, func)
{
return "
"
}
function hideShow (selector, func, v)
{
$(selector).fadeOut('10000', function (){func(v); $(this).fadeIn('10000', function (){checkWindow();});});
}
function drop (id, img, txt)
{
var table = '
Предмет \''+txt+'\' будет утерян, вы уверены ?
'+
' Все предметы этого вида';
dialogconfirm('Выбросить предмет?', 'deleteItem(\''+id+'\');', table);
}
function drophlam ()
{
var table = '
'+
'
Выбросить разный хлам типа выписок, квитанций и увядших букетов?
'+
'
Внимание! Имеющие срок годности предметы, купленные за зубы (эликсиры, корм для животных и т.д.), будут уничтожены.
'+
'';
dialogconfirm('Выбросить хлам?', 'main.pl', table);
}
function unstack (name, n, txt)
{
var table = '
Разделить предмет \''+txt+'\'
'+
''+
'Кол-во: ';
// window.clipboardData.setData('Text', table);
dialogconfirm('Разделить предмет?', (specialscript?specialscript:'main.pl'),table);
}
function showError (error, parameters)
{
if (!parameters)
parameters = '';
$.post('ajax.php', {'do': 'geterror', 'error': error, 'parameters': parameters}, function (data){
var id = top.exploder(data);
visual.show_any('#error', id[0]);
});
}
function clearError ()
{
$('#error').fadeOut('10000', function (){$(this).html('');});
}
function showHelp (link)
{
$.post('encicl/help/'+link+'.html', function (data){
var id = top.exploder(data);
visual.show_help(id[0]);
});
}
function hideHelp ()
{
visual.hide_help();
}
function showInventory (section, type, mail_guid)
{
clearError();
var cur_section = getCookie('section');
if (cur_section == section && $("#inventory").html() != '')
return;
$('#section_'+cur_section+', #section_1').attr('bgcolor', '#d4d2d2');
$('#section_'+section).attr('bgcolor', '#a5a5a5');
setCookie('section', section, getTimePlusHour());
$.post('ajax.php', {'do': 'showinventory', 'section': section, 'type': type, 'mail_guid': mail_guid}, function (data){
var inventory = top.exploder(data);
visual.show_any('#inventory', inventory[0]);
});
}
function showShapes (available)
{
if (available)
{
$('#shape_a').css('backgroundColor', '#A9AFC0');
$('#shape_na').css('backgroundColor', '');
}
else
{
$('#shape_a').css('backgroundColor', '');
$('#shape_na').css('backgroundColor', '#A9AFC0');
}
$.post('ajax.php', {'do': 'showshapes', 'available': available}, function (data){
var shapes = top.exploder(data);
visual.show_any('#shapes', shapes[0]);
});
}
function chooseShape (shape)
{
$.post('ajax.php', {'do': 'chooseshape', 'shape': shape}, function (data){
var shapes = top.exploder(data);
if (shapes[0] == 'complete')
location.href = 'main.php?action=inv';
else if (shapes[0] == 'error')
showError(shapes[1]);
});
}
//-- Смена хитпоинтов
var delay = 3; // Каждые n сек. увеличение HP и MP на 1%
var redHP = 0.33; // меньше 30% красный цвет
var yellowHP = 0.66; // меньше 60% желтый цвет, иначе зеленый
var TimerOnHP = -1; // id таймера HP
var TimerOnMP = -1; // id таймера MP
var nowHP, maxHP, nowMP, maxMP, hspeed, mspeed;
function showHP (now, max, newspeed, mini)
{
nowHP = now;
maxHP = max;
hspeed = newspeed;
if (TimerOnHP >= 0)
{
clearTimeout(TimerOnHP);
TimerOnHP = -1;
}
if (mini)
setHPmini();
else
setHPlocal();
}
function setHPlocal ()
{
var plusHP = 0;
if (nowHP == maxHP)
TimerOnHP = -1;
else
{
plusHP = maxHP * hspeed * 0.00001;
nowHP += ((plusHP+nowHP) <= maxHP) ?plusHP :maxHP-nowHP;
TimerOnHP = 0;
}
var le = 120;
var h1 = Math.round((le / maxHP) * nowHP);
var h2 = le - h1;
if (nowHP / maxHP < redHP)
imag = 'img/icon/bk_life_red.gif';
else if (nowHP / maxHP < yellowHP)
imag = 'img/icon/bk_life_yellow.gif';
else
imag = 'img/icon/bk_life_green.gif';
var rhp = Math.round(nowHP) + "/" + maxHP;
var alt = 'Уровень жизни'+((plusHP > 0 && (difHP = maxHP-nowHP) > 0) ?' Осталось: '+top.getFormatedTime(Math.round(difHP*delay/(plusHP*10))) :'');
$('#HP').html("
"+
"
"+rhp+"
"+
"
"+
"
"+
"
");
updateMmoves('HP', alt);
if (TimerOnHP != -1)
TimerOnHP = setTimeout(setHPlocal, delay * 100);
}
function showMP (now, max, newspeed)
{
if (max == 0)
return;
nowMP = now;
maxMP = max;
if (TimerOnMP >= 0)
{
clearTimeout(TimerOnMP);
TimerOnMP = -1;
}
mspeed = newspeed;
setMPlocal();
}
function setMPlocal ()
{
var plusMP = 0;
if (maxMP == 0)
return;
if (nowMP == maxMP)
TimerOnMP = -1
else
{
plusMP = maxMP * mspeed * 0.00001;
nowMP += ((plusMP+nowMP) <= maxMP) ?plusMP :maxMP-nowMP;
TimerOnMP = 0;
}
var le = 120;
var m1 = Math.round((le / maxMP) * nowMP);
var m2 = le - m1;
var rmp = Math.round(nowMP) + "/" + maxMP;
var alt = 'Уровень маны'+((plusMP > 0 && (difMP = maxMP-nowMP) > 0) ?' Осталось: '+top.getFormatedTime(Math.round(difMP*delay/(plusMP*10))) :'')
$('#MP').html("
"+
"
"+rmp+"
"+
"
"+
"
"+
"
");
updateMmoves('MP', alt);
if (TimerOnMP != -1)
TimerOnMP = setTimeout(setMPlocal, delay * 100);
}
function setHPmini ()
{
var plusHP = 0;
if (nowHP == maxHP)
TimerOnHP = -1;
else
{
plusHP = maxHP * hspeed * 0.00001;
nowHP += ((plusHP+nowHP) <= maxHP) ?plusHP :maxHP-nowHP;
TimerOnHP = 0;
}
var le = 120;
var h1 = Math.round((le / maxHP) * nowHP);
var h2 = le - h1;
if (nowHP / maxHP < redHP)
imag = 'img/icon/bk_life_red.gif';
else if (nowHP / maxHP < yellowHP)
imag = 'img/icon/bk_life_yellow.gif';
else
imag = 'img/icon/bk_life_green.gif';
var rhp = Math.round(nowHP) + "/" + maxHP;
var alt = 'Уровень жизни'+((plusHP > 0 && (difHP = maxHP-nowHP) > 0) ?' Осталось: '+top.getFormatedTime(Math.round(difHP*delay/(plusHP*10))) :'');
$('#HP').html(" "+rhp+"
"+
"
"+
"
"+
"
");
updateMmoves('HP', alt);
if (TimerOnHP != -1)
TimerOnHP = setTimeout(setHPmini, delay * 100);
}
//-- Сломанные вещи
var broken = new Array ();
var i = 1;
function BrokenItems ()
{
$('.broken').each(function (){
bgcolor = $(this).parents('tr[bgColor]').attr('bgColor');
$(this).animate({backgroundColor: ((broken[i]) ?"#f88383" :bgcolor)}, 2000);
broken[i] = !broken[i];
i++;
});
i = 1;
}
function rdf (ifloat)
{
return Math.round(ifloat * 100) / 100;
}
function checkWindow ()
{
if ($('body').height() > $('[name=main]', top.document).height())
$('body').css('margin-right', '0px');
else
$('body').css('margin-right', '17px');
}
var pos = {};
$(function (){
$('.broken').each(function (){
broken[i] = true;
i++;
});
i = 1;
if ($('.broken').html() != undefined)
setInterval(BrokenItems, 4100);
$('body').on('mouseover mouseleave', '#clear', function (e){
if (e.type == 'mouseover')
$(this).attr('src', 'i/clear.gif');
else if (e.type == 'mouseleave')
$(this).attr('src', 'i/clearg.gif');
}).on('click', '#link', function (){
top.linkAction($(this).attr('link'));
}).on('click', '#hint', function (){
showHelp($(this).attr('link'));
}).on('click', '#refresh', function (){
location.reload();
}).on('click', '#forum', function (){
window.open('/forum');
}).on('click', 'input[type=button], input[type=radio], input[type=submit], a', function (){
$(this).blur();
});
$(document).on('mousemove', function (e){
pos.x = e.pageX - $(window).scrollLeft();
pos.y = e.pageY - $(window).scrollTop();
});
$(window).resize(checkWindow);
checkWindow();
});