var microfos = (document.all)? true:false;

function elrejt(layernev) {
    if (microfos) document.all[layernev].style.visibility = 'hidden';
    else document.layers[layernev].visibility = 'hide';}

function megmutat(layernev) {
    if (microfos) document.all[layernev].style.visibility = 'visible';
    else document.layers[layernev].visibility = 'show';}

function mozgat(layernev, x, y) {
    if (microfos) {
        document.all[layernev].style.pixelLeft = x;
        document.all[layernev].style.pixelTop = y;}
    else document.layers[layernev].moveTo(x, y);}

function nyit(layernev) {
    if (microfos) document.all[layernev].innerHTML = ''; 
    else document.layers[layernev].document.open();}

function zar(layernev) {
    if (microfos) {}
    else document.layers[layernev].document.close();}

function ir(layernev, szoveg) {
    if (microfos) document.all[layernev].innerHTML = document.all[layernev].innerHTML + szoveg; 
    else document.layers[layernev].document.write(szoveg);}

window.onload = elsokerdes;


  
function elsokerdes() {
    if (microfos) {
        kepszelesseg = document.all['alapterkep'].document.alapkep.width;
        szovegszelesseg = document.body.clientWidth - kepszelesseg -terkepeltolasx - terkepeltolasx - szovegeltolasx;
        document.all['szoveg'].style.pixelWidth = szovegszelesseg;}
    else {
        kepszelesseg = document.alapterkep.document.alapkep.width;
        szovegszelesseg = window.innerWidth - kepszelesseg -terkepeltolasx - terkepeltolasx - szovegeltolasx;}
    mozgat('alapterkep', terkepeltolasx, terkepeltolasy);
    if (microfos) mozgat('szoveg', kepszelesseg + terkepeltolasx + szovegeltolasx - 2, 50);
    else mozgat('szoveg', kepszelesseg + terkepeltolasx + szovegeltolasx - 5, 50);
    varoskerdezes(Math.ceil(adatszam*Math.random()));
}

window.onresize = atmeretezes;

function atmeretezes() {
    if (microfos) {
        szovegszelesseg = document.body.clientWidth - kepszelesseg -terkepeltolasx - terkepeltolasx - szovegeltolasx;
        document.all['szoveg'].style.pixelWidth = szovegszelesseg;}
    else {
	  if (window.innerHeight < document.alapterkep.document.alapkep.height + terkepeltolasy + 7) window.innerHeight = document.alapterkep.document.alapkep.height + terkepeltolasy + 7;
        if (window.innerWidth < document.alapterkep.document.alapkep.width + terkepeltolasx + 208) window.innerWidth = document.alapterkep.document.alapkep.width + terkepeltolasx + 208;
    location.reload();}
}

function varoskerdezes(sorszam) {
nyit('varoshely');
ir('varoshely', '<HTML><BODY><IMG ALIGN="top" SRC="'+vkep[varos[sorszam].kepszam].src+'" > '+varos[sorszam].nev+'</BODY></HTML>');
zar('varoshely');

nyit('szoveg');
ir('szoveg', '<HTML><BODY><TABLE WIDTH="'+szovegszelesseg+'"><TD>');
ir('szoveg', varos[sorszam].kerdes);
ir('szoveg', '</TABLE></BODY></HTML>');
zar('szoveg');
megmutat('szoveg');
window.defaultStatus='Na hol?';

function ujkerdes() {
    if (!microfos) document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEDOWN);
    elrejt('varoshely');
    elrejt('szoveg');
    var ujsorszam = Math.ceil(adatszam*Math.random());
    if (varos[ujsorszam].halasztas != 0) {
	  varos[ujsorszam].halasztas--;
	  ujkerdes();}
    else varoskerdezes(ujsorszam);
}

function tavolsag(x0, y0, x1, y1, sorsz) {
    var dx = x0 - x1;
    var dy = y0 - y1;
    var t = Math.round(tavolsagszorzo*Math.sqrt(dx*dx+dy*dy));
    pontszam = Math.round(10-t*pontossag);
    if (pontszam < 0) pontszam = 0
    tippszam++;	
    osszpontszam = osszpontszam + pontszam;
    atlag = Math.round(100*osszpontszam/tippszam)/100;
    varos[sorsz].halasztas = pontszam + 1;
    mozgat('varoshely', x1 + terkepeltolasx - kepkozeppontx, y1 + terkepeltolasy - kepkozepponty);
    megmutat('varoshely');  
    nyit('szoveg');
    ir('szoveg', '<HTML><BODY><TABLE ID="ta" WIDTH="'+szovegszelesseg+'"><TD>');
    ir('szoveg', varos[sorsz].kerdes+'<BR><BR>');
    if (pontszam==10) ir('szoveg', 'Telital&aacute;lat!<BR><BR>');
    else ir('szoveg', 'Elt&eacute;r&eacute;s: '+t+tavolsagegyseg+'.<BR><BR>');
    ir('szoveg', 'Pontsz&aacute;m:  '+pontszam+'<BR><BR><BR>');
    ir('szoveg', '&Aacute;tlag:  '+atlag+'<BR><BR>');
    ir('szoveg', '<BR><BR><BR><BR><BR>&Uacute;j k&eacute;rd&eacute;s?');
    ir('szoveg', '</TABLE></BODY></HTML>');
    zar('szoveg');
    if (!microfos) document.releaseEvents(Event.MOUSEMOVE);
    if (microfos) document.onmousemove = null;
    window.defaultStatus='Mehet a kovetkező?'; 
    
    document.onmousedown = ujkerdes;
}



if (microfos) {
    function mozog(e) {
	   x = event.x - 2;
	   y = event.y - 2 ;
	   window.defaultStatus='ITT: '+eval(x-terkepeltolasx)+' '+eval(y-terkepeltolasy);
    }
    function klikkel(e) {
	   x = event.x - 2;
	   y = event.y - 2;
	   tavolsag(x-terkepeltolasx, y-terkepeltolasy, varos[sorszam].x, varos[sorszam].y, sorszam);
    }
    document.onmousemove = mozog;
    document.onmousedown = klikkel;}
else {
    document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN);
    fvtorzs = 'varoskerdezes.tavolsag(eval(event.pageX-terkepeltolasx), eval(event.pageY-terkepeltolasy), '+varos[sorszam].x+', '+varos[sorszam].y+', '+sorszam+')';
    document.onmousemove = new Function("event", "window.defaultStatus='ITT: '+eval(event.pageX-terkepeltolasx)+' '+eval(event.pageY-terkepeltolasy);");
    document.onmousedown = new Function("event", fvtorzs);}

}



