standard.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // XWUZ standard code
  3. // Having thoughts? Ask here: xwuz@tjp.hu
  4. //
  5. // if (top.frames.length == 0 && navigator.userAgent.indexOf ('iPhone') == -1 && location.href.indexOf('i2.html') == -1 && location.href.indexOf('research') == -1) {
  6. // location.href='game.html';
  7. // }
  8. var ibox_active='game';
  9. var ibox_cur=0;
  10. var ibox_targets=Array();
  11. var ibox_scroll_timer;
  12. ibox_targets['game']=0;
  13. ibox_targets['highscore']=-320;
  14. ibox_targets['about']=-640;
  15. var now = new Date();
  16. var expire = new Date();
  17. expire.setTime(now.getTime() + 1000*60*60*24*90); //90 days
  18. var stispace=new Array();
  19. var myims;
  20. var gamesplayed;
  21. var theirbest;
  22. function imgpreload(ims) {
  23. myims=new Array();
  24. ims.push('./i/b_yes.png');
  25. ims.push('./i/b_no.png');
  26. ims.push('./i/b_okay.png');
  27. for(i in ims) {
  28. myims[i]=new Image();
  29. myims[i].src=ims[i];
  30. }
  31. }
  32. function menuswitch(obj) {
  33. var whereto=obj.href.split('#')[1];
  34. if(whereto=='game' && ibox_active == 'game') {pausegame();iconfirm('<h1>新游戏</h1>确定要<br />重新开始游戏吗?','restartgame();'); return false;}
  35. if(ibox_active == 'game' && whereto!='game') {pausegame();}
  36. mse='';
  37. if(ibox_active != 'game' && whereto=='game') {mse='resumegame();';}
  38. tmp=new Array('game','highscore','about');
  39. tmp2=new Array();
  40. tmp2['game']=0;
  41. tmp2['highscore']='-72px';
  42. tmp2['about']='-182px';
  43. for(i in tmp) {
  44. document.getElementById('button_'+tmp[i]).style.backgroundPosition=tmp2[tmp[i]]+' '+((tmp[i]==whereto)?(0):('-41px'));
  45. }
  46. if(whereto == ibox_active) {return false;} else {ibox_start=ibox_targets[ibox_active]; ibox_active=whereto; }
  47. for(i in ibox_targets) {
  48. document.getElementById('button_'+i).className=(i==whereto)?('active'):('');
  49. }
  50. obj.className='active';
  51. tmp2=new Array();
  52. tmp=ibox_start;
  53. for(i=0;i<=5;i++) {
  54. tmp=(tmp+ibox_targets[whereto])/2;
  55. tmp2.push('document.getElementById(\'container_scroller\').style.marginLeft=\''+tmp+'px\';');
  56. }
  57. tmp2.push('document.getElementById(\'container_scroller\').style.marginLeft=\''+ibox_targets[whereto]+'px\';');
  58. if(mse!='') {tmp2.push(mse);}
  59. ttt=Math.random();
  60. stispace[ttt]=tmp2;
  61. setTI(ttt,50);
  62. return false;
  63. }
  64. function idismiss() {
  65. document.getElementById('alertbox').style.display='none';
  66. resumegame();
  67. }
  68. function ialert(iquestion,idoit) {
  69. document.getElementById('alertbox_content').innerHTML=iquestion+'<br style="clear:both" /><br /><a href="#" onclick="idismiss();eval(\''+idoit+'\'); return false;" ontouchstart="idismiss();eval(\''+idoit+'\'); return false;"><img src="./i/b_okay.png" alt="确定" /></a>';
  70. document.getElementById('alertbox').style.display='block';
  71. }
  72. function iconfirm(iquestion,idoit) {
  73. document.getElementById('alertbox_content').innerHTML=iquestion+'<br style="clear:both" /><br /><a href="#" ontouchstart="idismiss();eval(\''+idoit+'\'); return false;" onclick="idismiss();eval(\''+idoit+'\'); return false;"><img src="./i/b_yes.png" alt="Yes" /></a><a href="#" ontouchstart="idismiss(); return false;" onclick="idismiss(); return false;"><img src="./i/b_no.png" alt="No" /></a>';
  74. document.getElementById('alertbox').style.display='block';
  75. }
  76. function getCookie(Name) {
  77. var search = Name + "="
  78. if (document.cookie.length > 0) {
  79. offset = document.cookie.indexOf(search)
  80. if (offset != -1) {
  81. offset += search.length
  82. end = document.cookie.indexOf(";", offset)
  83. if (end == -1)
  84. end = document.cookie.length;
  85. return unescape(document.cookie.substring(offset, end))
  86. }
  87. }
  88. return('');
  89. }
  90. function setCookie(name, value) {
  91. document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())+';domain=lapp.xinli001.com;path=/;');
  92. }
  93. function setTI(todos,interval) {
  94. if(stispace[todos].length == 0) {delete stispace[todos];return false;}
  95. eval(stispace[todos].shift());
  96. setTimeout('setTI('+todos+','+interval+')',interval);
  97. }
  98. function $(id) {
  99. return document.getElementById(id);
  100. }