/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 */
var showButtonsAll = function(type, args) {
	YAHOO.util.Dom.setStyle("next-arrow-all", "visibility", "visible");
	YAHOO.util.Dom.setStyle("prev-arrow-all", "visibility", "visible");
};

/**
 * Called via the YUI Connection manager (see makeRequest).
 */
var handleSuccessAll = function(callbackResponse)
{
	var start = callbackResponse.argument[0];
	var numResults = callbackResponse.argument[1];
	var carousel = callbackResponse.argument[2];
	
  	if(callbackResponse.responseText !== undefined) {
		var theTrip = eval( '(' + callbackResponse.responseText + ')' );
		for(var i=0; i< theTrip.ResultSet.totalResultsReturned; i++) {
			var result = theTrip.ResultSet.Result[i];
			carousel.addItem(start+i, fmtTripInnerHTMLAll(result));
		}
		showButtons();
		activateads();
     }
};

/**
 * Since carousel.addItem uses an HTML string to create the interface
 * for each carousel item, this method takes an individual trip plan
 * result and cobbles together HTML for the innerHTML argument.
 */
var fmtTripInnerHTMLAll = function(result) {


	/* mr-M / 20008-06-11 */
	// pk und fk fuer link klassische ansicht extrahieren
  	var list = result.Url.split("&");
  	var pk = list[0].slice(3, list[1].length);
    var fk = list[1].slice(3, list[1].length);

  	var tripInnerHTML = 
  		result.Summary +
  		'<div style="border:1px solid #999999;">' +
		'<a href="/_misc/galleries/detail_ajax_further.cfm?pid=6&pk=' + pk + '" target="_blank"><img src="' + result.Image.Url + '" style="width:' + result.Image.Width + ';height:' + result.Image.Height + ';" title="Zum Vergr&ouml;&szlig;ern in klassischer Galerieansicht bitte klicken" /></a>' +  		
  		'</div>' +
		'<div style="color:#666666;font-family:verdana;font-size:10px;height:25px;">' + 
  		result.Title;

	return tripInnerHTML;
	
};

var handleFailureAll = function(o)
{
     var result = o.status + " " + o.statusText;
     //alert("Transaction failed.  The error is: " + result);
};
  
/**
 * A utility function for invoking the YUI connection manager (Ajax)
 * with a URL that matches the Yahoo! developer network Trip Planner
 * APIs (see: http://developer.yahoo.com/travel/tripservice/V1/tripSearch.html)
 *
 * The callback object is the configuration object for the YUI Connection
 * manager. If this is successful, the 'handleSuccess' function is called.
 */
var makeRequestAll = function(carousel, url, pkgallery, start, numResults)
{
	var params = 'galleriepart_' + pkgallery + 
	                        '_' + start + 
	                        '_' + numResults;
	
	var callback =
	{
  		success: handleSuccessAll,
  		failure: handleFailureAll,
  		argument: [start, numResults, carousel]
	};
	
	var sUrl = url + params;
	YAHOO.util.Connect.asyncRequest("GET", sUrl, callback, null);
};
