/*
 	Asynchronously loads and displays all the property images.

	property_id. 			 int (propiedades.id). The property ID.
	image_size. 		 	 string. "tiny", "thumb", "normal".
	url_view_property. 		 string. The URL for viewing the property. ie '{$this->m_home}/propiedad/ver/id-176'
	ajax_url_get_all_images. string. The AJAX URL for retrieving all the property images. ie '{$this->m_home}/propiedad/images'.
									 This AJAX method will receive these parameters:
										property_id: property_id,
										image_size: 'thumb',
										max_images: 100
	dom_prefix				 string. The prefix used for the dom element.
*/
function loadSlideShow(property_id, image_size, url_view_property, ajax_url_get_all_images, dom_prefix) {
	var nodom = $("#" + dom_prefix + "_noslide_" + property_id);
	// var dom = $("#" + dom_prefix + "_slide_" + property_id);
	var propertyIDs = new Array();
	
	// if ( dom.html() != "" ) {
	// 	return;
	// }

	$.getJSON(
		ajax_url_get_all_images,
		{
			property_id: property_id,
			image_size: image_size,
			max_images: 100
		},
		function(response) {
			var data = eval(response);
			if ( (data == null) || (data.length == 0) ) {
				return;
			}
			
			var s = "";
			for ( var i = 1; i < data.length; i++ ) {
				s += ("<a href='" + url_view_property + "'><img src='" + data[i]['url'] + "' border='0'></a>");
			}

			// dom.html(s);				
			// nodom.slideUp();
			// dom.slideDown();
			
			// if ( data.length > 1 ) {
			// 	dom.cycle({ fx: 'fade', timeout: 0, pause: 0 }).hover(function() {
			// 		$(this).cycle('toggle').cycle({ fx: 'fade', timeout: 1, delay: -1500 });
			// 	},function(){
			// 		$(this).cycle('pause');
			// 	});
			// }
			
			if ( data.length > 1 ) {				
				nodom.addClass('slideshow').append(s);
				nodom.cycle({ fx: 'fade', timeout: 1, delay: -1500
					}).cycle("pause").hover(function() {
						$(this).cycle('resume');
					},function(){
						$(this).cycle('pause');
					});
			}
	    }
	);
}

/*
 	Starts or stops the slide show.

	property_id. int (propiedades.id). The property ID.
	show. 		 bool. True to start the slideshow, false to stop it.
	dom_prefix	 string. The prefix used for the dom element.
*/
function showSlideShow(property_id, show, dom_prefix) {
	var dom = $("#" + dom_prefix + "_noslide_" + property_id);

	if ( dom.html() != "" ) {
		if ( show == true ) {
			dom.cycle('pause');
			dom.cycle({ fx: 'fade', timeout: 1000, pause: 1 });
		} else {
			dom.cycle('pause');
			dom.cycle({
				fx: 'fade',
				timeout: 700
			}).cycle("pause").hover(function() {
				$(this).cycle('resume');
			},function(){
				$(this).cycle('pause');
			});
		}
	}
}

