        var image_curr = -1;        

        var image_num = 0;

        var image_loaded = [];

        

        function image_loader(){

            image_num = image_urls.length;

            image_loaded = Array(image_num);

            for(i=0;i<image_num;i++){

                image_loaded[i]=0;

                var newdiv = document.createElement('div');

                newdiv.id = 'image_'+i;

                newdiv.className='ss_image';                

                if(i==0){

                    newdiv.style.zIndex = 999; 

                    newdiv.style.backgroundImage="url("+ image_urls[i]+")";

                    $('photosByBox').innerHTML = image_titles[i];

                }else if(i==1){

                    newdiv.style.zIndex = 888; 

                    newdiv.style.backgroundImage="url("+ image_urls[i]+")";                   

                }else{

                     newdiv.style.zIndex = 0;

                }

                $('slideShow').appendChild(newdiv);



            }

            setTimeout("image_changer()",5000);

        }


        /**
         * image changer
         *
         * Changes the header images periodically. If an image doesn't have an
         * author, the placeholder for author name will be hidden and blank.
         */
        function image_changer(){
            if(image_loaded[(image_curr+2) % image_num ]==0){
                $('image_'+(((image_curr+2) % image_num))).style.backgroundImage="url("+ image_urls[(image_curr+2) % image_num]+")";
                image_loaded[(image_curr+2) % image_num]==1;
            }
            image_curr = (image_curr + 1) % image_num;
            $("image_"+image_curr).set('tween', {duration: 1500});
            $("image_"+image_curr).tween('opacity',0.0);
	    for(i=0;i<image_num;i++){
                $("image_"+i).style.zIndex=0;
            }
	    $("image_"+image_curr).style.zIndex=999;
            $("image_"+((image_curr+1)%image_num)).style.zIndex=888;
            $("image_"+((image_curr+1)%image_num)).set('opacity','1.0');
            if(!(image_titles[(image_curr+1)%image_num]) || (image_titles[(image_curr+1)%image_num] == "")) {
                $('photosByBox').style.display = 'none';
                $('photosByBox').innerHTML = '';
            }else {
                $('photosByBox').style.display = 'block';
                $('photosByBox').innerHTML = image_titles[(image_curr+1)%image_num];
            }
            setTimeout("image_changer()",5000);
        }



function zio(){

    window.parent.document.body.style.zoom =1.01;

    window.parent.document.body.style.zoom =1;

}



function send_nl(){

    $('newsletter-message').style.display='none';

            req = new Request.JSON({url:"/index/newsletter",method:"POST",

                onSuccess: function(resp){

                    if(resp.ok){

                        $('newsletter-message').innerHTML = resp.message;                        

                        $('newsletter-message').className="success";

                        $('newsletter-message').style.display='block';

                    }else{

                        $('newsletter-message').innerHTML = resp.email;

                        $('newsletter-message').className="error";                        

                        $('newsletter-message').style.display='block';

                    }

                }                

            });            

            req.send("email="+$('nl-email').value);

}



function toggle_ajanlat(){

    $('reservation-form').style.display='none';

    if($('offer-form').style.display=='none'){

        $('offer-form').style.display='block';

        window.location.hash="ajanlatkeres";        

    }else{

        $('offer-form').style.display='none';

    }

    zio();

}



function toggle_foglalas(){

    $('offer-form').style.display='none';

    if($('reservation-form').style.display=='none'){

        $('reservation-form').style.display='block';

        window.location.hash="foglalas";        

    }else{

        $('reservation-form').style.display='none';

    }

    zio();

}



function ajax_getoptions(value,child,a){

    if(!a)a="";

    if(!child)return;

    opt = $(a+'regio');

    if(child=='ski_ground')opt=$(a+'siterep');

    for(i=(opt.options.length-1);i>=0;i--){

        opt.options[i]=null;

    }

    if(value!=""){

        var req = new Request.JSON({

    		url: "index.php",

    		onSuccess: function(resp){

                if(resp.length==0){

                    if(child!='ski_ground'){

                        opt.options[opt.options.length] = new Option("Régió","",false,false);

                    }else{

                        opt.options[opt.options.length] = new Option("Üdülőhely","",false,false);

                    }

                }else{              

                    for(i=0;i<resp.length;i++){                        

                        opt.options[opt.options.length] = new Option(resp[i]['name'],resp[i]['id'],false,false);

                    }         

                    opt.options[opt.options.length] = new Option("Minden","0",true,true);

                    if(child!='ski_ground' && a!='g'){  

                        ajax_getoptions(opt.value,'ski_ground',a);

                    }

                   

                }

                

                

    		}

    	}).get({'getOptionValue':value,'getOptionChild':child});

    }else{        

        if(child!='ski_ground'){

            opt.options[opt.options.length] = new Option("Régió","",false,false);

        }else{

            opt.options[opt.options.length] = new Option("Üdülőhely","",false,false);

        }

    }

}



function ajax_fancy_box(url_){    

    $('fancy').set('text','');

    req = new Request.HTML({

        evalScripts: true,

        url: url_,

        onSuccess: function(html){   

            $('fancy').set('text','');

            $('fancy').adopt(html);    

            $('fancy_close').addEvent('click',function(){

                $('fancy_bckg').style.display = 'none';

                $('fancy').style.display = 'none';

                document.body.style.overflow='auto';                                    

                $('fancy').innerHTML="";                                 

            });     

            $$('#fancy td img').addEvent('click',function(){

                $('big-image').src=this.src.replace('85x68exact','630x474');

                $('big-image').alt = this.alt;

            });

        },

        onFailrure: function(){

            $('fancy').set('text','A kért oldal nem található');            

        }

        

    });

    req.send();

    window.scrollTo(0, 500);    

    $('fancy_bckg').style.display='block';

    $('fancy').style.display='block';

    document.body.style.overflow='hidden';

}



function fancy_alert(text){

  // $('')

}



function fstToUpper(text){

    return text.substr(0, 1).toUpperCase() + text.substr(1)

}



function submit_felso_kereso(){

    $('fenti_kereso_form').submit();

}



window.addEvent('domready',function(){  

     image_loader();

     $$('ul.navigation li').addEvent('mouseenter',function(){

        if(this.getElement('ul'))this.getElement('ul').setStyle("display","block");

     });

     $$('ul.navigation li').addEvent('mouseleave',function(){

        if(this.getElement('ul'))this.getElement('ul').setStyle("display","none");

     });                               

     

     $$('ul.navigation li ul ul ul li').addEvent('mouseover',function(){

        sps = this.getElements('span');

        this.getElement('img').src=sps[0].innerHTML;

     });

     

     $('fancy_bckg').style.height ='3000px';

     $('fancy_bckg').set('opacity','0.5');

     $('fancy_bckg').addEvent('click',function(){

          $('fancy_bckg').style.display = 'none';

          $('fancy').style.display = 'none';          

          document.body.style.overflow='auto';

          //$('fancy_alert').style.display = 'none';

     });

     if($('map_button')){

        $('map_button').addEvent('click',function(e){

            e.stop();

            ajax_fancy_box(this.href);

        });

     }

     if($('images_button')){

        $('images_button').addEvent('click',function(e){

            e.stop();

            ajax_fancy_box(this.href);

        });

     }

      if($('video_button')){

        $('video_button').addEvent('click',function(e){

            e.stop();

            ajax_fancy_box(this.href);

        });

     }

     

     $('orszag').addEvent('change',function(){

            ajax_getoptions(this.value,'region');

     });

     $('regio').addEvent('change',function(){

            ajax_getoptions(this.value,'ski_ground');

     });

     //ajax_getoptions('','ski_ground');        

       

     if($('acountry')){

         $('acountry').addEvent('change',function(){

                ajax_getoptions(this.value,'region','a');

         });

         $('aregio').addEvent('change',function(){

                ajax_getoptions(this.value,'ski_ground','a');

         });

     }

     if($('gcountry')){

        $('gcountry').addEvent('change',function(){

                ajax_getoptions(this.value,'region','g');

         });

     }

          

     if($('checkout')){        

        $('checkout').setAttribute('readonly','readonly');

        $('checkout').style.cursor='pointer';

        dp1 = new dhtmlxCalendarObject('checkout', true, {

            isYearEditable: false,

            isMonthEditable: true,

            headerButtons: 'M'

        });

        dhtmlxCalendarLangModules['hu'] = {

            langname: 'hu',

            dateformat: '%Y-%m-%d',

            monthesFNames: ["Január", "Február", "Március", "Április", "Május", "Június", "Július", "Augusztus", "Szeptember", "Október", "November", "December"],

            monthesSNames: ["Jan", "Feb", "Már", "Ápr", "Máj", "Jún", "Júl", "Aug", "Sep", "Okt", "Nov", "Dec"],

            daysFNames: ["Vasárnap", "Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek", "Szombat"],

            daysSNames: ["Va", "Hé", "Ke", "Sze", "Cs", "P", "Szo"],

            weekend: [0, 6],

            weekstart: 1,

            msgClose: "Bezárás",

            msgMinimize: "Minimalizálás",

            msgToday: "Ma"

        };           

        dp1.loadUserLanguage('hu');                      

        dp1.draw();

        

     }

     

     if($('checkin')){

        $('checkin').value=format_date(new Date());

        $('checkin').setAttribute('readonly','readonly');

        $('checkin').style.cursor='pointer';

        dp2 = new dhtmlxCalendarObject('checkin', true, {

            isYearEditable: false,

            isMonthEditable: true,

            headerButtons: 'M'

        });   

        dhtmlxCalendarLangModules['hu'] = {

            langname: 'hu',

            dateformat: '%Y-%m-%d',

            monthesFNames: ["Január", "Február", "Március", "Április", "Május", "Június", "Július", "Augusztus", "Szeptember", "Október", "November", "December"],

            monthesSNames: ["Jan", "Feb", "Már", "Ápr", "Máj", "Jún", "Júl", "Aug", "Sep", "Okt", "Nov", "Dec"],

            daysFNames: ["Vasárnap", "Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek", "Szombat"],

            daysSNames: ["Va", "Hé", "Ke", "Sze", "Cs", "P", "Szo"],

            weekend: [0, 6],

            weekstart: 1,

            msgClose: "Bezárás",

            msgMinimize: "Minimalizálás",

            msgToday: "Ma"

        };

        dp2.loadUserLanguage('hu');                      

        dp2.draw();

     }

     

     if($('reserve_room')){

        $('reserve_room').addEvent('click',function(){

            if($('checkin').value=="" || $('checkout').value=="" ){

                alert("Kérem adja meg az érkezés és távozás dátumát is!");

                return;

            }

            $('online-reservation').src="https://secure.booking.com/book.html?aid=331537;hotel_id="+booking_id+";stage=0;checkin="+$('checkin').value+";checkout="+$('checkout').value+";hostname=www.booking.com";

            $('online-reservation').style.display = 'block';

            zio();

        })

     }

     

     $('newsletter').addEvent('submit',function(e){

            e.stop();

            send_nl();

            

     });

     

     if($('calculator_close')){

        $('calculator_close').addEvent('click',function(){

           $('calculator').style.display='none'; 

           $('calculator_dragger').style.display='none';

        });        

        

        var myWidth = 0, myHeight = 0;

        if( typeof( window.innerWidth ) == 'number' ) {            

            myWidth = window.innerWidth;

        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {        

            myWidth = document.documentElement.clientWidth;

  

        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {   

             myWidth = document.body.clientWidth;

  

        }

        $('calculator_dragger').style.left = (myWidth/2-75)+'px';

        $('calculator').style.left = (myWidth/2-75)+'px';

        var myDragInstance = new Drag($('calculator_dragger'),{

            onStart: function(){                

                $('calculator').set('opacity','0.75');

            },

            onComplete: function(){

                $('calculator').set('opacity','1.0');

            },onDrag: function(){  

                $('calculator').style.left = $('calculator_dragger').style.left;

                $('calculator').style.top = $('calculator_dragger').style.top;

            }

         });  

         /*$('calculator').addEvent('click',function(x,y){

                alert(y);

         });

         */

        

        $('calculate').addEvent('click',function(){

            $('calculator_result').innerHTML="="+(Math.round(euro_forint*$('euro').value.replace(",","."))).toString();

        });

        

        $('euro').addEvent('click',function(){

            this.focus(); 

        });        

     }

     

     if($('kategoria')){

        for(i=(($('kategoria').options.length)-1);i>=0;i--){

            if($('kategoria').options[i].value>=8)$('kategoria').options[i]=null;

        };

     }

     if($('akategoria')){

        for(i=(($('akategoria').options.length)-1);i>=0;i--){

            if($('akategoria').options[i].value>=8)$('akategoria').options[i]=null;

        };

     }



      if($('ellatas')){

       for(i=(($('ellatas').options.length)-1);i>=0;i--){
            $('ellatas').options[i] = new Option(fstToUpper($('ellatas').options[i].text),$('ellatas').options[i].value,$('ellatas').options[i].selected,$('ellatas').options[i].selected);

        };

     }

     if($('asupply')){

        for(i=(($('asupply').options.length)-1);i>=0;i--){
            if(i>0)$('asupply').options[i] = new Option(fstToUpper($('asupply').options[i].text),$('asupply').options[i].value,$('asupply').options[i].selected,$('asupply').options[i].selected);

        };

     }

   

     zio();    

});       
