var b1n="ant";
var b2n="lightning";
var b3n="pelikanok";
var b4n="kolibri";
var b5n="pelikan_uj";
var b6n="fox";
var b7n="suvolto";
var b8n="egret";
var b9n="erdeipinty";

window.onload=function() {
  scr=getCookie('SCR');
  setCookie('Loaded',1);
  b1=new Image(10,10); b1.src='http://matebence.hu/pic/'+b1n+scr+'.jpg';
  b2=new Image(10,10); b2.src='http://matebence.hu/pic/'+b2n+scr+'.jpg';
  b3=new Image(10,10); b3.src='http://matebence.hu/pic/'+b3n+scr+'.jpg';
  b4=new Image(10,10); b4.src='http://matebence.hu/pic/'+b4n+scr+'.jpg';
  b5=new Image(10,10); b5.src='http://matebence.hu/pic/'+b5n+scr+'.jpg';
  b6=new Image(10,10); b6.src='http://matebence.hu/pic/'+b6n+scr+'.jpg';
  b7=new Image(10,10); b7.src='http://matebence.hu/pic/'+b7n+scr+'.jpg';
  b8=new Image(10,10); b8.src='http://matebence.hu/pic/'+b8n+scr+'.jpg';
  b9=new Image(10,10); b9.src='http://matebence.hu/pic/'+b9n+scr+'.jpg';

  if (document.URL.indexOf('base')>-1) {

  } else {
    if (document.URL.indexOf('home')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('galery')>-1) {
      setcol(1); setcol(2); setcol(3); setcol(4); setcol(5);
      setbw(1); setbw(2); setbw(3); setbw(4); setbw(5);
      loading(0);
    }
    if (document.URL.indexOf('bio')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('book')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('prize')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('press')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('video')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('shop')>-1) {
      loading(0);
      $imgno=document.getElementById('imgno');
      $val=$imgno.options[$imgno.selectedIndex].value;
      if ($val!=0) {
        $imgno.onchange();
      }
    }
    if (document.URL.indexOf('contact')>-1) {
      loading(0);
    }
    if (document.URL.indexOf('spla')>-1) {
      loading(0);
    }
    if (browser()=='IE') {
//      loading(0);
    }
//    alert(document.URL); alert(parent.document.URL);
//    loading(0);
  }
}

function setcol(mn) {
  e_mn=document.getElementById("gmpic"+mn);
  if (mn==1) fn='news';
  if (mn==2) fn='mamm';
  if (mn==3) fn='bird';
  if (mn==4) fn='othe';
  if (mn==5) fn='werk';
  scr=getCookie('SCR');
  e_mn.src='pic/gm_'+fn+'_'+scr+'.jpg';
}

function setbw(mn) {
  e_mn=document.getElementById("gmpic"+mn);
  if (mn==1) fn='news';
  if (mn==2) fn='mamm';
  if (mn==3) fn='bird';
  if (mn==4) fn='othe';
  if (mn==5) fn='werk';
  scr=getCookie('SCR');
  e_mn.src='pic/gm_'+fn+'_'+scr+'_bw.jpg';
}

//----------------------------------------------------------
function drawkeret(mn) {
  br=browser();
  if (br=='NS') body=document.body;
  if (window.top!=window.parent) {
    doc=window.parent.document;
    body=window.parent.document.body;
  } else {
    doc=document;
    if (br=='NS') body=document.body;
  }
  omn=0;
  if (mn==0) { mn=getCookie('MENU'); if (mn==0) mn=1; omn=1;}
  if (mn==1) { img=b1n; col="#222222"; pg='home'; }
  if (mn==2) { img=b2n; col="#837892"; pg='galery';}
  if (mn==4) { img=b3n; col="#333333"; pg='bio';}
  if (mn==5) { img=b4n; col="#697340"; pg='prize'; setCookie('hideshow','free'); }
  if (mn==6) { img=b5n; col="#6d3a00"; pg='press';}
  if (mn==7) { img=b6n; col="#152137"; pg='video';}
  if (mn==8) { img=b7n; col="#48210f"; pg='shop';}
  if (mn==9) { img=b8n; col="#422f31"; pg='contact';}
  if (mn==10) {img=b9n; col="#222222"; pg='book';}
  setCookie('MENU',mn);
  e_bac=doc.getElementById("artback");
  if (e_bac==null) {
    e_bac=doc.createElement('div'); e_bac.setAttribute('id','artback'); e_bac.className='artback'; body.appendChild(e_bac);
  }
  e_keret=doc.getElementById("keret"); if (e_keret!=null) body.removeChild(e_keret);
  if (window.top!=window.parent) window.parent.location.reload();
  if (mn==2) {e_keret=doc.createElement('div');} else {e_keret=doc.createElement('iframe');}
  e_keret.setAttribute('id','keret'); e_keret.className='keret'; body.appendChild(e_keret);
  e_keret=doc.getElementById("keret");
  e_bac=doc.getElementById("artback");
//  e_leftb=document.getElementById("lefttab");
  e_logo=doc.getElementById("logo");
  e_menu=doc.getElementById("menu");
  e_copy=doc.getElementById("copy");
  e_book=doc.getElementById("book");
  e_flag=doc.getElementById("flag");
  e_flli=doc.getElementById("flaglink");
  e_crea=doc.getElementById("created");
  e_load=doc.getElementById('loading');
  e_fb=doc.getElementById('FB');

  page=hs.getPageSize();
  maxx=page.width; maxy=page.height; setCookie('MAXX',maxx); setCookie('MAXY',maxy);
//  scrx=screen.width; scry=screen.height;
  scrx=getCookie('SCRX'); scry=getCookie('SCRY');
  if (scrx-2>maxx) maxx=scrx-2;
  if (scry*0.8>maxy) maxy=scry*0.8;
  if (maxx>2500) {scrx=2560; scry=1600;}
  if (scrx>2560) {maxy=maxy*2560/maxx; maxx=2558; scry=2560*scry/scrx; scrx=2560;}

  mt=110*scrx/1280; mb=60*scrx/1280; ml=50*scrx/1280; mr=50*scrx/1280; yy=maxy-mt-mb;
  e_bac.style.width=maxx;
  e_bac.style.height=maxy;
  e_keret.style.top=mt;
  e_keret.style.left=ml;
  e_keret.style.width=maxx*0.65;
  e_keret.style.height=yy;
//  e_leftb.style.height=yy;
  if (e_copy) {
    e_copy.style.top=mt+yy+20;
    e_copy.style.left=maxx-170-mr+4-34;//ml;
  }
  if (e_flag) {
    e_flag.style.top=mt*0.65;
    e_flag.style.left=maxx-mr-23-4;
  }
  if (e_logo) {
    e_logo.style.top=mt+yy-30;
    e_logo.style.left=maxx-mr-90+4; //e_logo.style.width=150
  }
  if (e_crea) {
    e_crea.style.top=mt+yy+35;//maxy-mt*0.2;
    e_crea.style.left=maxx-150-mr+4-130;//maxx/2-60;
  }
  if (e_menu) {
    e_menu.style.top=maxy/2-180-40;
    e_menu.style.left=maxx-170-mr+4-12; //e_menu.style.width=170
  }
  if (e_fb) {
    e_fb.style.left=ml;
    e_fb.style.top=mt+yy+14;
    if (br=='IE')
      e_fb.style.width=maxx*0.65;
    else
      e_fb.style.width=maxx*0.65-10;
  }
  if (e_book) {
    e_book.style.top=maxy/2-180+344-20;
    e_book.style.left=maxx-mr-12-82;
  }
  if (e_load) {
    e_load.style.top=maxy-mt*0.2-20;
    e_load.style.left=maxx/2-110;
  }
  fn=scrx+'x'+scry;
  if (omn==1)  {
    body.style.background="#000 url(pic/"+img+fn+".jpg) no-repeat scroll top left";
  }
  LN=getCookie('Language');
  if (LN=='HU') LAN='EN'; else LAN='HU';
  if (e_flli) {
    e_flli.href="gp.php?Cmd=chlang&ln="+LAN+"&sp="+pg;
  }
//alert(img+fn);
  e_bac.style.background="#000 url(pic/"+img+fn+".jpg) no-repeat fixed top left";
  if (br=='IE') {
    e_bac.style.filter='alpha(opacity=0)';
    e_keret.style.filter='alpha(opacity=0)';
  } else {
    e_bac.style.opacity=0;
    e_keret.style.opacity=0;
  }

  e_keret.style.borderColor=col;
  e_bac.style.display='block';
//  window.setTimeout('hs.fade(e_keret,0.9,0.0,100)',0);
//  window.setTimeout('e_keret.src=\'gp.php?pg=\'+pg;',600);
//pg='prb';
//alert('00');
  setCookie('Loaded',0);

  if (mn==2) {
    geturl('gp.php?pg=galery&ln='+LN);
  } else {
    e_keret.src='gp.php?pg='+pg+'&ln='+LN;
  }
//  window.setTimeout('hs.fade(e_bac,0,1)',350);
  hs.fade(e_bac, 0.0, 1, 350 );
/*  for (i=1;i<=10;i++) {
    if (br=='IE') window.setTimeout('e_bac.style.filter=\'alpha(opacity='+(i*10)+')\';',i*35);
    else window.setTimeout('e_bac.style.opacity='+(i/10)+';',i*35);
  }*/
  window.setTimeout('body.style.background=e_bac.style.background; e_bac.style.display=\'none\'; loading(1);',600);


//  window.setTimeout('bac.style.display=\'none\'',800);
//  window.setTimeout('hs.fade(bac,1.0,0.0,10)',610);
/*  window.setTimeout('hs.fade( e_keret,0.0, 0.8, 300)',6000);
  window.setTimeout('hs.fade(e_keret,0.8,0.0,300)',8000);
  window.setTimeout('hs.fade(bac,1.0,0.0,300)',9000);
  window.setTimeout('bac.style.display=\'none\'',10000);*/
//  window.setTimeout('e_keret.style.border=\'1px solid \'+col;',800);

//  window.setTimeout('hs.fade(e_keret, 0.0, 0.9, 500 ); ',800);
//  window.setTimeout('e_keret.style.opacity=1; e_keret.style.filter=\'alpha(opacity=100)\'; e_keret.style.background=\'url(pic/transpBlack90.png)\';',2000);
/*
  window.setTimeout('e_keret.style.opacity=1;',1200);
  window.setTimeout('e_keret.style.filter=\'alpha(opacity=100)\';',1200);
  window.setTimeout('e_keret.style.background=\'url(pic/transpBlack90.png)\'',1500);*/
//alert('end');
  return false;
}

function delay(ms) {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < ms);
}

function setCookie(cookieName,cookieValue) {
 document.cookie = cookieName+"="+escape(cookieValue)+";path=/";
}

function getCookie(cookieName) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(cookieName + "=");
    if (c_start!=-1) {
      c_start=c_start + cookieName.length+1 ;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return '';
}

function igazit(pg) {
  page=hs.getPageSize();
  maxx=page.width;
  maxy=page.height;

  if (pg=='home') {
    e_tab=document.getElementsByTagName('table');
    e_tab[0].style.height=maxy-20;
//    e_img=document.getElementById('fokep');
//    e_img.style.width='360px';
  }
  if (pg=='galery') {
    e_tab=document.getElementById('galtab');
    e_tab.style.height=maxy-50;
  }
  if (pg=='press') {
    e_cov=document.getElementById('covers');
//    e_cov.style.height=500;
  }
}

function maxkeret() {
//  alert('maxkeret()');
  e_keret=parent.document.getElementById("keret");
  if (e_keret!=null) {
    e_subpad=document.getElementById("subpad");
    br=browser();
    if (br=='IE') {
//      maxx=parent.document.body.scrollWidth; maxy=parent.document.body.scrollHeight;
      maxx=getCookie('MAXX'); maxy=getCookie('MAXY');
    } else {
      maxx=parent.window.innerWidth;
      maxy=parent.window.innerHeight;
    }
    topp=e_keret.style.top;
    leff=e_keret.style.left;
    wi=e_keret.style.width;
    he=e_keret.style.height;
    to=0+Math.floor(topp.substr(0,topp.indexOf('px')));
    ri= 0+maxx-wi.substr(0,wi.indexOf('px'))-leff.substr(0,leff.indexOf('px')); ri=Math.floor(ri);
    bo= 0+maxy-he.substr(0,he.indexOf('px'))-topp.substr(0,topp.indexOf('px')); bo=Math.floor(bo);
    le=0+Math.floor(leff.substr(0,leff.indexOf('px')));
    pp=to+'px '+ri+'px '+bo+'px '+le+'px';
    if (br=='NS') e_subpad.style.display='none';
    trans(1);
    if (br!='IE') {
      e_subpad.style.padding=pp;
    }
    e_keret.style.top=0;
    e_keret.style.left=0;
    e_keret.style.width=maxx;
    e_keret.style.height=maxy;
  }
}

function setkeret(page) {
//alert('setkeret');
  e_keret=parent.document.getElementById("keret");
  if (e_keret!=null) {
    e_subpad=document.getElementById("subpad");
  //  trans(0);
    maxx=getCookie('MAXX');//page.width;
    maxy=getCookie('MAXY');//page.height;
    scrx=screen.width;
    scry=screen.height;
    if (maxx>1900) {scrx=1920; scry=1200;}
    if (scrx>1920) {maxy=maxy*1920/maxx; maxx=1918; scry=1920*scry/scrx; scrx=1920;}
    mt=110*scrx/1280; mb=60*scrx/1280; ml=50*scrx/1280; mr=50*scrx/1280;
    e_subpad.style.padding='0px';//10px 5px 5px 10px';
    yy=maxy-mt-mb;
    e_keret.style.top=mt;
    e_keret.style.left=ml;
    e_keret.style.width=maxx*0.65;
    e_keret.style.height=yy;
    if (br=='NS') e_subpad.style.display='block';
    return e_keret;
  }
}


function hideshow(id) {
  chs=getCookie('hideshow');
  if (chs=='busy') return false;
  setCookie('hideshow','busy');
  pr=document.getElementById('prize'+id);
  tav=document.getElementById('tav'+id);
  step=20;
  time=100;
  br=browser();
  if (pr.className=='nodisp') {
    tav.style.height='0px';
    tav.className='disp';
    for (i=1;i<=step;i++) {
      window.setTimeout('tav.style.height=\''+i*50/step+'px\';',i*time/step);
    }
    if (br=='NS') window.setTimeout('pr.style.height=\'50px\';',time);
    else window.setTimeout('tav.className=\'nodisp\';',time);
    window.setTimeout('tav.style.height=\'0px\';',time);
    window.setTimeout('pr.className=\'disp\';',time);
    window.setTimeout('hs.fade(pr,0,1,300);',time);
    window.setTimeout('setCookie(\'hideshow\',\'free\');',time+325);
  } else {
    hs.fade(pr,1,0,250);
    tav.style.height='50px';
    pr.style.height='0px';
    window.setTimeout('pr.className=\'nodisp\';',250);
    if (br!='NS') window.setTimeout('tav.className=\'disp\';',250);
    else window.setTimeout('pr.style.height=\'0px\';',250);
    for (i=step;i>0;i--) {
      window.setTimeout('tav.style.height=\''+i*50/step+'px\';',250+(step-i+1)*time/step);
    }
    window.setTimeout('tav.className=\'nodisp\';',300+time+20);
    window.setTimeout('setCookie(\'hideshow\',\'free\');',300+time+25);
  }
  return false;
}

function openglr() {
  gp1=document.getElementById('gmpic1');
  gl1=document.getElementById('gmlink1');
  gp1.style.height=100; gp1.style.height=100;
  return false;
}

function chsrc(el) {
  p=el.src.indexOf('.jpg');
  p2=el.src.indexOf('_v.jpg');
  if (p2>-1) {el.src=el.src.substr(0,p2)+'.jpg'; el.style.zIndex=1; }
  else {el.src=el.src.substr(0,p)+'_v.jpg'; el.style.zIndex=24; }
}

function numonly(el) {
  last=el.value.substr(-1,1);
  valid='0123456789';
  if (valid.indexOf(last)==-1) el.value=el.value.substr(0,el.value.length-1);
}

function loading(onoff) {
//alert('loading('+onoff+')');
  ret=true;
  if (onoff==0) {
    if (parent.document.getElementById('loading'))
      parent.document.getElementById('loading').style.display='none';
    e_keret=parent.document.getElementById('keret');
    if (e_keret) {
      e_keret.style.background='url(pic/transpback.png)';
      hs.fade(e_keret, 0.0, 1, 400 );
      window.setTimeout('e_keret.style.background=\'url(pic/transpback.png)\'',600);
      if (browser()=='IE') window.setTimeout('e_keret.style.filter=\'alpha(opacity=100)\';',800);
      else window.setTimeout('e_keret.style.opacity=1;',800);
    }
  } else {
    if (getCookie('Loaded')==0) {
      if (document.getElementById('loading'))
        document.getElementById('loading').style.display='inline';
    } else {
//      e_keret=document.getElementById('keret');
//      hs.fade(e_keret, 0.0, 1, 500 );
//      window.setTimeout('e_keret.style.background=\'url(pic/transpback.png)\'',700);
    }
  }
  return ret;
}

function browser() {
  br='';
  if (navigator.appName=='Netscape') br='NS';
  if (navigator.appName=='Microsoft Internet Explorer') br='IE';
  if (navigator.appName=='Opera') br='OP';
  if (br=='') if (document.all && !window.opera) br='IE';
  if (br=='') br='IE';
  return br;
}

function trans(tr) {
//alert('trans('+tr+')');
  br=browser();
  if (tr==1) {
    if (br=='IE') parent.document.getElementById("keret").style.filter='alpha(opacity=100)';
    else parent.document.getElementById("keret").style.opacity=1;
  } else {
    if (br=='IE') parent.document.getElementById("keret").style.filter='alpha(opacity=90)';
    else parent.document.getElementById("keret").style.opacity=0.9;
  }
}

function myfade(el,opsta,opend,dur) {
  step=(opend-opsta)/10;
  for (i=1;i<=10;i++) {
  opact=opsta+i*step;
//alert('el.style.opacity='+opact+';');
//    if (br=='IE') window.setTimeout('el.style.filter=\'alpha(opacity='+(opact*100)+')\';',i*dur/10);
//    else window.setTimeout('el.style.opacity='+opact+';',i*dur/10);
  }
//alert(3);
}

function geturl(url) {
//alert('geturl: '+url);
  try
    {// Firefox, Opera 8.0+, Safari, IE7
    xmlHttp=new XMLHttpRequest();
    }
  catch(e)
    {// Old IE
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch(e)
      {
      alert ("Your browser does not support XMLHTTP!");
      return;
      }
    }
  xmlHttp.onreadystatechange=state_Change;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function state_Change() {
//alert('state_Change state: '+xmlHttp.readyState+', status: '+xmlHttp.status);
  if (xmlHttp.readyState==4) {// 4 = "loaded"
    if (xmlHttp.status==200) {// 200 = OK
      txt=xmlHttp.responseText;
      e_keret=document.getElementById("keret");
      if (e_keret==null) e_keret=parent.document.getElementById("keret");
      e_keret.innerHTML=txt;
      hs.fade(e_keret, 0.0, 1, 500 );
      window.setTimeout('e_keret.style.background=\'url(pic/transpback.png)\'',700);
      if (browser()=='IE') window.setTimeout('e_keret.style.filter=\'alpha(opacity=100)\';',800);
      else window.setTimeout('e_keret.style.opacity=1;',800);
      window.setTimeout('document.getElementById(\'loading\').style.display=\'none\';',900);
    } else {
      alert("Problem retrieving XML data");
    }
  }
}

function gotogal(url) {
  e_keret=parent.document.getElementById("keret"); if (e_keret!=null) parent.document.body.removeChild(e_keret);
  e_keret=parent.document.createElement('div'); e_keret.setAttribute('id','keret'); e_keret.className='keret'; parent.document.body.appendChild(e_keret);
  geturl(url);
}

function showbook() {
  pWidth=820; pHeight=650;
  ofsx=(screen.width-pWidth)/2; ofsy=(screen.height-pHeight)/4;
  Win=window.open( "gp.php?pg=book", "_blank", "width="+ pWidth+ ",height="+pHeight+",status=no,scrollbars=yes,menubar=no,resizable=yes,screenX="+ofsx+",screenY="+ofsy+",left="+ofsx+",top="+ofsy);
  Win.document.show;
  Win.document.close();
  if (navigator.appName.substring(0,8) == "Netscape") Win.focus();
}

function updshop(el) {
//alert(el);
//el=document.getElementById('imgno');
  if (el.value!=0) kk=el.value+'.jpg'; else kk='spacer.png';
  document.getElementById('IMG').src='tn/'+kk;
  document.getElementById('LINK').href='pic/'+kk;
  document.getElementById('DescImg').innerHTML='';
  document.getElementById('os0').value='';
  if (el.selectedIndex>0) {
    kk=el.options[el.selectedIndex].text;
    document.getElementById('DescImg').innerHTML=kk;
    document.getElementById('os0').value=kk;
//    document.getElementById('item_name').value='Print '+document.getElementById('SIZE').options[document.getElementById('SIZE').selectedIndex].text;
  };
}
