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

		if($('slidearea_nav') && $('slidearea_slides')){
			
			var currentSlide = 1;
			var totalSlides = 0;
			var i = 0;
			
			var scroll = new Fx.Scroll('slidearea_slides', {
				wait: false,
				duration: 500,
				offset: {'x': 0, 'y': 0},
				transition: Fx.Transitions.Quad.easeInOut
			});
	
			var nextSlide = function(){
				if(currentSlide < totalSlides){
					currentSlide++;
					scroll.toElement('img_slide'+currentSlide);
				}else{
					currentSlide = 1;
					scroll.toElement('img_slide'+currentSlide);
				}
				
				// highlight current slide button
				i = 1;
				while(i <= totalSlides){
				  if(i == currentSlide){
					$('nav_slide'+i).set({'opacity': 0.8});
				  }else{
					$('nav_slide'+i).set({'opacity': 0.5});
				  }
				  i++;
				}
						
			};

			var prevSlide = function(){
				if(currentSlide > 1){
					currentSlide--;
					scroll.toElement('img_slide'+currentSlide);
				}else{
					currentSlide = totalSlides;
					scroll.toElement('img_slide'+totalSlides);
				}
				
				// highlight current slide button
				i = 1;
				while(i <= totalSlides){
				  if(i == currentSlide){
					$('nav_slide'+i).set({'opacity': 0.8});
				  }else{
					$('nav_slide'+i).set({'opacity': 0.5});
				  }
				  i++;
				}
						
			};


			var timer = nextSlide.periodical(5000);

			// listen for left & right arrows
			document.addEvent('keydown', function(e) {
				// left = prev
				if (e.code == '37') prevSlide();
			
				// right = next
				if (e.code == '39') nextSlide();
			});

			$('slidearea').addEvent('mouseover', function(){
				clearInterval(timer);				
			}.bind(this));
			
			$('slidearea').addEvent('mouseout', function(){
				timer = nextSlide.periodical(5000);		
			}.bind(this));
	
			var allSlideNav = $('slidearea_nav').getElements('img');
			$each(allSlideNav, function(imgObject, index){
				
				// initially highlight the first slide button
				if(parseInt(imgObject.get('id').replace('nav_slide','')) == 1){
					$(imgObject.get('id')).set({'opacity': 0.8});
				}else{
					$(imgObject.get('id')).set({'opacity': 0.5});
				}
				
				imgObject.addEvent('click', function(){
					scroll.toElement( imgObject.get('id').replace('nav_','img_') );
					currentSlide = parseInt(imgObject.get('id').replace('nav_slide',''));
					
					// highlight current slide button
					i = 1;
					while(i <= totalSlides){
					  if(i == currentSlide){
						$('nav_slide'+i).set({'opacity': 0.8});
					  }else{
					  	$('nav_slide'+i).set({'opacity': 0.5});
					  }
					  i++;
					}	
					
				}.bind(this));
				
				totalSlides++;
				
			});
			
		}else{
			//alert('slider elements missing');
		}

	});
	
// ----- Thickbox -----
function usethickbox(){
		window.addEvent('domready', function() {
 
	/**
	 * Some options for the large photos.
	 *
	 * The first argument is the argument for $$ (can be an array of elements or a selector)
	 */
 
	ReMooz.assign('#full_listing_thumbhold a', {
		'origin': 'img',
		'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
		'resizeFactor': 0.8, // resize to maximum 80% of screen size
		'cutOut': false, // don't hide the original
		'opacityResize': 0.4, // opaque resize
		'dragging': true, // disable dragging
		'centered': true // resize to center of the screen, not relative to the source element
	});
 
	/**
	 * Note on "shadow": value can be true, onOpenEnd (appear after resize) and false, to disable shadow
	 * WebKit (Safari 3) uses (great looking) CSS shadows, so it ignores this option.
	 */
 
});
	
};
// ----- Main Navigation Menu -----

function insertMainMenu($openmenu){

	window.addEvent('domready', function() {
	//------------------------------------------------------------BEGIN
	//------------------------------------------------------------WELCOME SECTION
	var welcomeSection = new Fx.Slide('navi_welcome',{
		duration: 'short'
		
	});

	if ($openmenu != 7){
		welcomeSection.hide();
	}
	
		$('welcome_toggle').addEvent('click', function(e){
				
			$('navi_welcome').setStyle("display","block");
			e.stop();
			welcomeSection.toggle();
		});
	//------------------------------------------------------------SIGHTSEEING SECTION
	var sightseeingSection = new Fx.Slide('navi_sightseeing',{
		duration: 'short'

	});

	if ($openmenu != 2){
	sightseeingSection.hide();
	}
		$('sightseeing_toggle').addEvent('click', function(e){
				
			$('navi_sightseeing').setStyle("display","block");
			e.stop();
			sightseeingSection.toggle();
		});
	//------------------------------------------------------------SHOPPING SECTION
	var shoppingSection = new Fx.Slide('navi_shopping',{
		duration: 'short'

	});
	if ($openmenu != 3){
	shoppingSection.hide();
	}
		$('shopping_toggle').addEvent('click', function(e){
				
			$('navi_shopping').setStyle("display","block");
			e.stop();
			shoppingSection.toggle();
		});
	
	//------------------------------------------------------------EATING SECTION
	var eatingSection = new Fx.Slide('navi_eating',{
		duration: 'short'
	});
	if ($openmenu != 4){
	eatingSection.hide();
	}
		$('eating_toggle').addEvent('click', function(e){
				
			$('navi_eating').setStyle("display","block");
			e.stop();
			eatingSection.toggle();
		});
	//------------------------------------------------------------ACCOMMODATION SECTION
	var accommodationSection = new Fx.Slide('navi_accommodation',{
		duration: 'short'
	});
	if ($openmenu != 5){
	accommodationSection.hide();
	}
		$('accommodation_toggle').addEvent('click', function(e){
				
			$('navi_accommodation').setStyle("display","block");
			e.stop();
			accommodationSection.toggle();
		});
	//------------------------------------------------------------ACCOMMODATION SECTION
	var livingSection = new Fx.Slide('navi_living',{
		duration: 'short'
	});
	if ($openmenu != 6){
	livingSection.hide();
	}
		$('living_toggle').addEvent('click', function(e){
				
			$('navi_living').setStyle("display","block");
			e.stop();
			livingSection.toggle();
		});
	
	
	//------------------------------------------------------------VERY END
	});
};



//----- Item boxes transitions -----


window.addEvent('domready',function() {   
	
	
    $each($$('.item_summary_full_width'), function(el) {   
        el.addEvents({   
            'mouseenter' : function() { 
			
				this.set('morph', {
					duration: 'long',
					transition: Fx.Transitions.Quint.easeOut 
				}).morph('.item_summary_full_width_hover');
			
			},   
            'mouseleave' : function() { 
			
				this.set('morph', {
					duration: 'long',
					transition: Fx.Transitions.Quint.easeOut 		 
				}).morph('.item_summary_full_width');
			
			}   
        });   
    });   
	
});  


//------------------------------------------------------------enquiry slide
function enquiry_slide($hide){
	
		window.addEvent('domready', function() {
											 
		var addSlide = new Fx.Slide('full_listing_enquiry');
		
		if ($hide==1){
			addSlide.hide();
		}

		
		$('enquiry_slide').addEvent('click', function(e){
			duration:'short'
			e.stop();
			addSlide.slideIn();
		});
		$('enquiry_slide_in').addEvent('click', function(e){
			duration:'short'
			e.stop();
			addSlide.slideOut();
		});
	 
	});
};

//------------------------------------------------------------rooms slide
function room_slide(){
	
		window.addEvent('domready', function() {
											 
		var addSlide = new Fx.Slide('full_listing_rooms');
		addSlide.hide();
		
		$('rooms_slide').addEvent('click', function(e){
			duration:'short'
			e.stop();
			addSlide.slideIn();
		});
		$('rooms_slide_in').addEvent('click', function(e){
			duration:'short'
			e.stop();
			addSlide.slideOut();
		});
	 
	});
};

document.addEvent('domready', function() {
 
	/**
	 * Simple example, backend returns a list of <li> elements,
	 * processed by Autocompleter.Request.HTML.
	 */
	var inputWord = $('demo-word');
 

 
	// Our instance for the element with id "demo-word2"
	new Autocompleter.Request.HTML(inputWord, 'searchfeed.php', {
		'indicatorClass': 'autocompleter-loading',
		'postData': {
			'extended': '1' // send additional POST data, check the PHP code
		},
		'injectChoice': function(choice) {

			if (choice.getFirst() != null){
				var newText = choice.getFirst();

				choice.inputValue = newText.innerHTML.replace(/(<([^>]+)>)/ig,"").replace("&amp;","and").replace("Click here to view",""); 

				this.addChoiceEvents(choice);
			}
		}
	});
 

 
});

//---------------------contact free listing slide

function applySlide(){
		window.addEvent('domready', function() {
											 
		var applySlider = new Fx.Slide('apply_slide');
		applySlider.hide();
		
		$('apply_click').addEvent('click', function(e){
			duration:'short'
			applySlider.slideIn();
		});
	 
	 	$('apply_click2').addEvent('click', function(e){
			duration:'short'
			applySlider.slideIn();
		});
	});
};
