function ajaxvideolibrary(videogalleryid, uniqueid)
{
	var galleryEntries = new Array();

	$.ajax({
		url: "internalajax/videogallery",
		type: "POST",
		data:
			{
				videogalleryid: videogalleryid
			},
		dataType: "xml",
		success: function(xml, textStatus)
			{
				$("videogalleryoutput>videogallery>videos>video", xml).each(
					function(indexInArray, valueOfElement)
					{
						var entry = new GalleryEntry();
						entry.video = $("video", valueOfElement).text();
						entry.thumbnail = $("thumbnail", valueOfElement).text();
						galleryEntries[indexInArray] = entry;
					});
				var gallerydate = $("videogalleryoutput>videogallery>formatteddate", xml).text();
				var gallerytitle = $("videogalleryoutput>videogallery>title", xml).text();
				
        initCaption(gallerydate, gallerytitle, uniqueid);
				initVideoGallery(galleryEntries, uniqueid);
			},
		error: function (XMLHttpRequest, textStatus, errorThrown) 
			{
				alert("Fehler beim Laden der Videogalerie.");
			},
		cache: false
	});
}

function GalleryEntry()
{
	var video;
	var thumbnail;
}

function initCaption(gallerydate, gallerytitle, uniqueid)
{
	var title = $("#" + uniqueid + "title");
	title.html(gallerydate + "&nbsp;" + gallerytitle);
}

function initVideoGallery(galleryEntries, uniqueid)
{
  var playerContainer = $("#" + uniqueid + "flowplayer");
  
  for(var i=0; i<galleryEntries.length; i++)
	{
    //Nur 1 Eintrag anzeigen
    if(i == 0)
    {
      //Thumbnail - ausgeblendet
      $("#" + uniqueid + "thumbnail").attr("src", galleryEntries[i].thumbnail);
      var clickContainer = $("#" + uniqueid + "thumbnailContainer");
      clickContainer.hide();
      
      var entryVideo = galleryEntries[i].video;
      var player = flowplayer(uniqueid + "flowplayer", "media/flowplayer-3.1.0.swf", {
          clip: {
            autoPlay: false,
            autoBuffering: true,
            baseUrl: $('base').attr('href'),
      			// track start event for this clip
      			onStart: function(clip) {
      				_gaq.push(['_trackEvent', 'Videogalerie', 'Play', clip.url]);
      			},
      
      			// track pause event for this clip. time (in seconds) is also tracked
      			onPause: function(clip) {
      				_gaq.push(['_trackEvent', 'Videogalerie', 'Pause', clip.url, parseInt(this.getTime())]);
       			},
      
      			// track stop event for this clip. time is also tracked
      			onStop: function(clip) {
      				_gaq.push(['_trackEvent', 'Videogalerie', 'Stop', clip.url, parseInt(this.getTime())]);
      			},
      
      			// track finish event for this clip
      			onFinish: function(clip) {
      				_gaq.push(['_trackEvent', 'Videogalerie', 'Finish', clip.url]);
      			}
          },
          playlist: [
            entryVideo
          ]
        });
    }
  }
}






























