/*!
 * JavaScript Autoslider
 *
 * Copyright 2011, Bern hard Bezdek
 * Licensed under the GPL Version 2 license.
 * @requires Jquery min. 1.5.x
 *
 * Date: Thu Jul 03 14:16:56 2011 -0400
 *
 * Note This is a modified Version of the auto0lisde function by Bernhard Bezdek
 * The origin you can find on googlecode
 * http://code.google.com/p/appstackio-public-sources/
 */
function autoslide(oSlider, sElement, iUnit, iDelay, iDuration) {
	var iCurMargin = parseInt($(oSlider).css('margin-left').replace(/px/, ''));
	iCurMargin = (iCurMargin<0)?iCurMargin*-1:iCurMargin;

	var iMaxSlide = $(oSlider).children(sElement).length*iUnit;

	$(oSlider).width(iMaxSlide);

	// Additional Animation ()
	$('#hotel-offer').delay(iDelay).fadeOut(250, function() {
		$(this).css('top', '20px');
	});
	//
	$(this).css('top', '20px');
	if((iCurMargin+iUnit)<iMaxSlide) {
		$(oSlider).delay(iDelay).animate({
			'margin-left':'-'+(iCurMargin+iUnit)+'px'
		}, iDuration, function() {
			$('.pricelist').css('display', 'none');
			$('#hotel-offer').fadeIn(250, function() {

				$('#hotel-offer').animate({
					'top':'180'
				}, function() {
					var iCurPriceList = iCurMargin/$(oSlider).children(sElement+':eq(0)').width() +1;
					$('.pricelist:eq('+iCurPriceList+')').fadeIn(150);
					autoslide(oSlider, sElement, iUnit, iDelay, iDuration);
				});
			});
		});
	} else {
		$(oSlider).delay(iDelay).animate({
			'opacity':'0'
		}, 250, function() {
			$(oSlider).css('margin-left','0px');
			$(oSlider).animate({
				'opacity':'1'
			}, 250, function() {
				$('.pricelist').css('display', 'none');
				$('#hotel-offer').fadeIn(250, function() {
					$('#hotel-offer').animate({
						'top':'180'
					}, function() {
						$('.pricelist:visible').css('display', 'none');
						$('.pricelist:eq(0)').fadeIn(150);
						autoslide(oSlider, sElement, iUnit, iDelay, iDuration);
					});
				});
			});
		});
	}
}

function findValueCallback(event, data, formatted) {
	$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	//
}

function formatItem(row) {
	return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}

function formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
}
