// JavaScript Document
var descriptionTextsFetched = new Array();
var descriptionImagesFetched = new Array();
descriptionImagesAlreadyFetched = false;
descriptionTextAlreadyFetched = false;

function getFullPropertyDescription(propertyId){
	//new Effect.BlindUp('brief_description', {duration:1});ellipsis, {duration:1}
	$('hide_full_description_button_'+propertyId).disabled = true;
	$('read_full_description_button_'+propertyId).disabled = true;
	$('hide_full_description_button_'+propertyId).value = 'please wait...';
	$('read_full_description_button_'+propertyId).value = 'please wait...';
	$('read_full_description_cell_'+propertyId).style.display = 'none'; 
	$('hide_full_description_cell_'+propertyId).style.display = ''; 
	new Effect.BlindUp('brief_description_'+propertyId);
	$('extra_description_'+propertyId).style.display = 'none';
//	getDescriptionText(propertyId);
	//check description text hasn't already been fetched//
	for(var x=0; x<descriptionTextsFetched.length; x++){
		if(descriptionTextsFetched[x] == propertyId){
			descriptionTextAlreadyFetched = true;
		}
	}
	if(descriptionTextAlreadyFetched){
		setTimeout(function(){showText(propertyId)}, 1000);
	}else{
		setTimeout(function(){getDescriptionText(propertyId)}, 500);
	}
	
	for(var x=0; x<descriptionImagesFetched.length; x++){
		if(descriptionImagesFetched[x] == propertyId){
			descriptionImagesAlreadyFetched = true;
		}
	}
	if(descriptionImagesAlreadyFetched){
		setTimeout(function(){showImages(propertyId)}, 1000);
	}else{
		$('extra_description_images_'+propertyId).style.display = 'none';
		setTimeout(function(){getDescriptionImages(propertyId)}, 3000);
	}
		
	descriptionImagesAlreadyFetched = false;
	descriptionTextAlreadyFetched = false;
	//$('hide_full_description_button_'+propertyId).disabled = false;
	//$('read_full_description_button_'+propertyId).disabled = false;
}	

function getDescriptionText(propertyId){
	new Ajax.Updater('extra_description_'+propertyId, '/search_and_book/inline_full_property_description.php?property_id='+propertyId+'&request_type=description', {	method:'POST', 
									onComplete:
												function(){showText(propertyId);},
									onSuccess:
												function(){	descriptionTextsFetched.push(propertyId)}
												
											});
	
	
}

function showText(propertyId){
	new Effect.BlindDown('extra_description_'+propertyId, {duration:2});
}

function getDescriptionImages(propertyId){
	new Ajax.Updater('extra_description_images_'+propertyId, '/search_and_book/inline_full_property_description.php?property_id='+propertyId+'&request_type=images', {	method:'POST', 
									onComplete:	function(){
															showImages(propertyId);							
															},
									onSuccess:
												function(){	
															descriptionImagesFetched.push(propertyId);
															},
									evalScripts: true
											});
}

function showImages(propertyId){
	new Effect.BlindDown('extra_description_images_'+propertyId, {duration:3, afterFinish:
						 									function(){
																$('hide_full_description_button_'+propertyId).disabled = false; 
																$('read_full_description_button_'+propertyId).disabled = false;
																$('hide_full_description_button_'+propertyId).value = 'hide full description';
																$('read_full_description_button_'+propertyId).value = 'read full description';
																}
															}
						);
}

function hideFullPropertyDescription(propertyId){
	$('read_full_description_cell_'+propertyId).style.display = ''; 
	$('hide_full_description_cell_'+propertyId).style.display = 'none';	
	$('read_full_description_button_'+propertyId).value = 'please wait...';
	$('read_full_description_button_'+propertyId).disabled = true;
	
	new Effect.BlindUp('extra_description_'+propertyId, {duration:1});
	new Effect.BlindUp('extra_description_images_'+propertyId, {duration:1});
	setTimeout(function(){new Effect.BlindDown('brief_description_'+propertyId, {afterFinish:
											   						function(){
																	$('read_full_description_button_'+propertyId).value = 'read full description';
																	$('read_full_description_button_'+propertyId).disabled = false;		
																	}
											   }
											   )}, 1000);
	
	 
}

//** LARGE IMAGES SLIDESHOW **//

/*
var slideshow = new Slideshow({	imageRoot:'', 
						imageSrcs:new Array(), 
						delay:5000, 
						targetImg:'image_scroll_area_img',
						imageWidth:500,
						imageHeight:375
						});



function startLargeImageSlideshow(imageSrcs, imagePath){
	slideshow.imageRoot = imagePath;
}

*/

var largeImageSlideshow;
var slideshow;

function startLargeImageSlideshow(imageSrcs, imagePath) {
	//alert(imageSrcs[0]);
	var loadingImage = $('image_scroll_area_img');
	//var targetContainer = targetImage.parentNode;
	var targetContainer = $('image_scroll_area');
	targetContainer.innerHTML = '';
	targetContainer.appendChild(loadingImage);
	
	var imageCount = imageSrcs.length;
	var imageElements = [];
	for (var i = 0; i < imageCount; i++) {
		var image = document.createElement('img');
		image.src = imagePath + imageSrcs[i];
		image.style.width = '500px';
		image.style.height = '375px';
		image.style.overflow = 'hidden';
		image.style.display = 'none';
		// image.style.position = 'absolute';
		
		targetContainer.insertBefore(image, loadingImage);
	}
	
	Element.hide(loadingImage);
	targetContainer.parentNode.appendChild(loadingImage); // move it out of the way
	if (!largeImageSlideshow) {
		slideshow = largeImageSlideshow = new Slideshow2(targetContainer);
		slideshow.holdDuration = 1;
		slideshow.fadeDuration = 0.7;
		slideshow.onStop = function () { Element.hide('pause-button'); Element.show('play-button'); };
		slideshow.onPlay = function () { Element.hide('play-button'); Element.show('pause-button'); };
	}else{
		largeImageSlideshow.stop();
	}
	
	if (window.startScrollingWindows) {
		startScrollingWindows();
	}
	show_image_box();
	
	largeImageSlideshow.start();
	largeImageSlideshow.onPlay();
}	

function show_image_box(){ //image box must be a div with id large-image-slideshow-box
	$('image_scroll_area_img').src = '../images/loading-500_375.gif';
	new Effect.BlindDown('large_image_slideshow_container');
}

function hide_image_box(){ //image box must be a div with id large-image-slideshow-box
	slideshow.pause();
	new Effect.BlindUp('large_image_slideshow_container');
}

function startSlideshow(){
	
	window.slideshow.start();
}

