//    SCROLL begin
function getparentheight(node,n) {

  y=n+node.offsetTop;

  if (node.offsetParent){

    par=node.offsetParent;

    getparentheight(par,y);

  }

  return y;

}



function scroll(){

  var cnt=document.getElementById("content");

  var sb=document.getElementById("scrollbar");

  var sc=sb.firstChild.nextSibling?sb.firstChild.nextSibling:sb.firstChild;

  var th=parseInt(cnt.offsetHeight);

  var h=parseInt(sc.offsetHeight);

  var hh=Math.round(h/2);

  var max=parseInt(sb.offsetHeight);

  var min=0;

  var move=false;

  var lept=(th-max)/(max-h);

  var m=0;

  y=getparentheight(sb,0);

  

  window.onmousewheel=document.onmousewheel=function(e){

    if (th>max){

      if (e==undefined) e=event;

      var delta = 0;

      if (e.wheelDelta) {

        delta = e.wheelDelta/120;

        //if (window.opera) delta = -delta;

      } else if (e.detail) {

        delta = -e.detail/3;

      }

      if (delta){

          if (delta < 0) {

            m+=20;

            if (m>=max-h) m=max-h;

          }      

          else {

            m-=20;

            if (min+h>=m) m=0;

          }

        sc.style.top=m+"px";

        cnt.style.top=-Math.round((m)*lept)+"px";

      }

      if (e.preventDefault)

      e.preventDefault();

    	e.returnValue = false;

    }

  }

  

  if (window.addEventListener) window.addEventListener('DOMMouseScroll', window.onmousewheel, false);

  

  sc.onmousedown=function(){

    move=true;

    return false;

  }

  

  document.onmousemove=function(e){

    if (move && th>max){

      if (e==undefined) e=event;

      m=parseInt(e.clientY)-y;

      if (min+hh<=m && m<=max-hh){

        sc.style.top=m-hh+"px";

        cnt.style.top=-Math.round((m-hh)*lept)+"px";

        //if (document.selection) document.selection.empty();

        //else 

        if (window.getSelection) window.getSelection().removeAllRanges();

      }

    }

    return false;

  }

  

  document.body.onselectstart=function(){

    return false;

  };



  

  sb.onclick=function(e){

    if (th>max){

      if (e==undefined) e=event;

      m=parseInt(e.clientY)-y;

      if (min+h>=m) m=0+hh;

      else if (m>=max-h) m=max-h+hh;

      sc.style.top=m-hh+"px";

      cnt.style.top=-Math.round((m-hh)*lept)+"px";

    }

    return false;

  }

  

  document.onmouseup=function(){

    move=false;

    return false;  

  }

}
//    SCROLL end
//    PICTURES begin
var op=0;

var obj=null;



function pshow(id){

  if (document.all) document.getElementById('fbd').style.visibility='hidden';

  op=0;

  obj=document.getElementById(id);

  obj.style.zIndex=2000;

  changeop(1);

}



function phide(id){

  op=100;

  obj=document.getElementById(id);

  changeop(-1);

  document.getElementById('fbd').style.visibility='visible';

}



function changeop(a){

  if (op<=100 && op>=0){

    op+=6*a;

    if (op>100) opp=100;

    else if (op<0) opp=0;

    else opp=op;

    obj.style.filter='alpha(opacity='+opp+')';

    obj.style.opacity=String(opp/100);

    setTimeout("changeop("+a+");",10);

  }

  if (op<0) {

    obj.style.zIndex='-1';

  }

}

//    PICTURES end
//    ADDGOAL begin
function addgoal(tip){

  if (tip=="fastbook" || tip=="email" || tip=="groupmail" || tip=="fastbutton" || tip=="transfer" || tip=="rendezveny"){

    agi=document.createElement('iframe');

    agi.id="goalframe";

    agi.style.display='none';

    document.body.appendChild(agi);

    atmp=location.href.split("/");

    agi.width="600px";

    agi.height="300px";

    agi.src="http://"+atmp[2]+"/plugins/"+tip+"_goal.php";

  }

}

//    ADDGOAL end
//    SENDMAIL begin
function mmail(obj){

  obj.href=obj.href.replace(/nsp./g,'');

  return true;

}

//    SENDMAIL end
//    MENU begin
function c_opacity(o,p){

  o.style.filter='alpha(opacity='+p+')';

  o.style.opacity=p/100;

}



function hide(x,p){

  if (document.getElementById(x)) {

    ho=document.getElementById(x);

    opp=p;

    ho.parentNode.style.zIndex='9999';

    if (opp>0) {

      c_opacity(ho,opp);

      opp-=8;

      setTimeout('hide("'+x+'",'+opp+');',25);

    }

    else {

      ho.style.display='none';

      if (ho.parentNode.parentNode.id=='menu') ho.parentNode.style.background='transparent';

    }

  }

}



function init_menu(){

  mul=document.getElementById('menu');

  lis=mul.getElementsByTagName('li');

  for (var j=0; j<lis.length; j++){

    if (lis[j].parentNode.id=='menu') fstr="o.parentNode.style.background='#6E471D'; o.style.top=this.offsetHeight+'px'; o.style.left='0px';";

    else fstr="o.style.left=this.offsetWidth+'px'; o.style.top='0px'";

    lis[j].onmouseover=new Function("if (this.childNodes.length>1) { this.style.zIndex='10000'; o=this.getElementsByTagName('ul')[0]; if (o) {o.id='mnu_'+Math.floor(Math.random()*50000); o.style.filter='none'; o.style.opacity='1'; o.style.display='block'; "+fstr+"}}");

    lis[j].onmouseout=new Function("if (this.childNodes.length>1) { o=this.getElementsByTagName('ul')[0]; if (o) {hide(o.id,100);}}");

  }

}
//    MENU end
//    AJAX begin
function ajaxRequest(obj,url,parameters,method,mime,oload) {

  this.req=false;

  this.url=url;

  this.parameters=parameters;

  this.method=method;

  this.obj=obj;

  if (this.obj!=null){ 

    this.kep=document.createElement('IMG');

    this.kep.src='./images/loading.gif';

    this.kep.style.marginTop='7px';

    this.kep.style.width='16px';

    this.kep.style.height='16px';

    this.obj.parentNode.appendChild(this.kep);

  }

   

  this.sendRequest=function(){

    this.req=false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...

       this.req=new XMLHttpRequest();

       if (this.req.overrideMimeType) {

          this.req.overrideMimeType(mime);

       }

    } else if (window.ActiveXObject) { // IE

       try {

          this.req=new ActiveXObject("Msxml2.XMLHTTP");

       } catch (e) {

          try {

             this.req=new ActiveXObject("Microsoft.XMLHTTP");

          } catch (e) {}

       }

    }

    if (!this.req) {

      alert('Cannot create XMLHTTP instance');

      return false;

    }

    

    var self=this;

    

    if (this.method=='post'){

      this.req.open(this.method,this.url,true);

      this.req.onreadystatechange=function(){self.handleResponse(self);}

      this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

      this.req.setRequestHeader("Content-length", this.parameters.length);

      this.req.setRequestHeader("Connection", "close");

      this.req.send(this.parameters);

    }

    else{

      this.parameters="?"+this.parameters;

      if (this.parameters.length>1) this.parameters+='&';

      this.parameters+='r='+Math.floor(Math.random()*10000);

      this.req.open(this.method,this.url+this.parameters,true);

	    this.req.onreadystatechange=function(){self.handleResponse(self);}

      this.req.send(null);

    }

  }

  

  this.handleResponse = function(t){  

    if (t.req.readyState == 4) {

        if (t.req.status == 200) {

          if (t.obj!=null) t.obj.innerHTML="";

          ctype=t.req.getResponseHeader("Content-Type").split(";")[0];

          if (ctype=='application/xml') {

            //parseXML

            eval(oload);

          }

          else if (ctype=='text/plain' || ctype=='text/html') {

            if (t.obj!=null) t.obj.innerHTML=t.req.responseText;

            eval(oload);

          }

          else if (ctype=='text/javascript') {

            //t.obj.innerHTML=t.req.responseText;

            eval(t.req.responseText);

            eval(oload);

          } else {

            if (t.obj!=null) t.obj.innerHTML="Unknown content type!";

            else alert("Unknown content type!");

          }

        } else {

            if (t.obj!=null) t.obj.innerHTML="There was a problem retrieving data:\n" + t.req.statusText;

            else alert("There was a problem retrieving data:\n" + t.req.statusText);

        }

        if (t.obj!=null) t.obj.parentNode.removeChild(t.kep);

      }

  }

  this.sendRequest();

}
//    AJAX end
//    REQUEST begin
function sndReq(action) {

  new ajaxRequest(null,"http://www.promenadehotelbudapest.com/plugins/getlang.php",'lang='+action,"get","text/html","fastbooklangs(t.req.responseText);");

}



function fastbooklangs(response) {

  labels=response.split('|');

  labelids=["FBCi","_jan","_feb","_mar","_apr","_may","_jun","_jul","_aug","_sept","_oct","_nov","_dec","FBNi","FBAd","FBAc","FBCu","FBCa","FBCc","FBMo","FBHh","FBTt"];

  for (i=0; i<labels.length-1; i++){

    txt=document.createTextNode(labels[i]);

    lids=document.getElementById(labelids[i]);

    if (lids) lids.appendChild(txt);

  }

  document.getElementById('load').style.display='none';  

  document.getElementById('fbd').style.display='block';

}

//    REQUEST end
//    PICANIM begin
var si=0;

var pop;

var psobj=null;

var cont=null;

var simages=null;

var ssi=0;



function pic_switch(){

  cont=document.getElementById('galhome');

  simages=cont.getElementsByTagName('LI');

  swap();

}



function swap(){

  psobj=simages[simages.length-1];

  pop=500;

  ssi=setInterval("swapanim()",10);

}



function swapanim(){

  pop--;

  if (pop<100){

    if (pop==0){

      pop=100;

      clearInterval(ssi);

      first=simages[0];

      psobj.removeNode;

      cont.insertBefore(psobj,first);

    }

    psobj.style.filter='alpha(opacity='+pop+')';

    psobj.style.opacity=String(pop/100);

    if (pop==100) swap();

  }

}



window.onunload=function(){

  clearInterval(ssi);

}

//    PICANIM end
//    GMAP begin
var g_cont=null;

var gm=null;



function show_Gmap(oid,id,gw,gh,dist,zoom,type,add,rem,lang){

  

  //new ajaxRequest(null,"./js/gm.php","","get","text/html","");

  

  data='';

  data+='gm_id='+id+'&';

  data+='gm_dist='+dist+'&';

  data+='gm_zoom='+zoom+'&';

  for (i=0; i<type.length; i++){

    data+='gm_type[]='+type[i]+'&';

  }

  for (i=0; i<add.length; i++){

    data+='gm_add[]='+add[i]+'&';

  }

  for (i=0; i<rem.length; i++){

    data+='gm_rem[]='+rem[i]+'&';

  }

  data+='gm_lang='+lang;

  

  if (oid=='') {

    if (g_cont!=null) document.body.removeChild(g_cont);

    g_cont=document.createElement('div');

    g_cont.style.zIndex=1000;

    g_cont.id="gcontid";

    g_cont.style.opacity=0;

    g_cont.style.filter="alpha(opacity=0)";

    g_cont.style.background="#eee";

    g_cont.style.position="absolute";

    g_cont.style.left="50%";

    g_cont.style.top="50%";

    g_cont.style.width=gw+"px";

    g_cont.style.height=gh+"px";

    g_cont.style.margin="-"+Math.floor(gh/2)+"px 0px 0px -"+Math.floor(gw/2)+"px";

    document.body.appendChild(g_cont);

    gm=document.createElement('div');

    gm.style.position="relative";

    gm.style.left="0px";

    gm.style.top="0px";

    gm.style.width=(gw-226)+"px";

    gm.style.height=gh+"px";

    gm.style.background="white";

    gm.id="gmap";

    g_cont.appendChild(gm);

    quit=document.createElement('img');

    quit.src="./images/mapexit.png";

    g_cont.appendChild(quit);

    quit.style.position="absolute";

    quit.style.right="0px";

    quit.style.top="0px";

    quit.onclick=function(){

      phide('gcontid');

    }

    new ajaxRequest(gm,"./js/googlemap.php",data,"post","text/html","load(); pshow('gcontid');");

  }

  else {

    gm=document.getElementById(oid);

    gm.style.width=gw+"px";

    gm.style.height=gh+"px";

    new ajaxRequest(gm,"./js/googlemap.php",data,"post","text/html","load();");

  }

}
//    GMAP end
//    ONLOAD begin
window.onload=function(){

  scroll();

  //if (document.getElementById('gmap')) load();

  init_menu();

  start();

  sndReq(document.idForm.langue.value);

  pic_switch();

}
//    ONLOAD end
