function slideShow(elemId, blog_id, entry_array, field_to_display, title, loaded_callback, onstart_callback, onstop_callback) {
var id = blog_id;
var entries = entry_array;
var loadImage = "/images/loadingAnimation.gif";
var currentslide = 0;
var slides = new Array();
var indicators = new Array();
var slideTimer = null;
var timeout = 5;
var parent;
var field = field_to_display;
var after_loaded = loaded_callback;
var onstop = onstop_callback;
var onstart = onstart_callback;
var d = document;
var container = d.getElementById(elemId);
var isIE = d.all || window.opera;
var slides = d.createElement('DIV');
var showtitle = null;

  container.innerHTML = "";

  slides.id = elemId + '_slideshowcontainer';
  slides.className = 'slideshowcontainer';
  slides.align = "center";
  container.appendChild(slides);
  
  if(title != null && title != '') {
    showtitle = d.createElement('DIV');
    showtitle.className = 'slideshowtitle';
    showtitle.innerHTML = title;
    slides.appendChild(showtitle);
  }

  parent = d.createElement('DIV');
  parent.id = elemId + '_slideshow';
  parent.className = 'slideshow';
  slides.appendChild(parent);

  var control = d.createElement('DIV');
  parent.id = elemId + '_slideshowcontrol';
  control.className = 'slideshowcontrol';

  var buttonsdiv = d.createElement('DIV');
  buttonsdiv.className = 'slideshowcontrolbuttons';
  
  var btnPrev = d.createElement('A');
  btnPrev.href = "";
  btnPrev.rel = "nofollow";
  btnPrev.innerHTML = '<img src="/images/0.png" class="previous" alt="Previous" title="Previous" />';
  btnPrev.onclick = goPrevious;
  buttonsdiv.appendChild(btnPrev);

  var btnPlay = d.createElement('A');
  btnPlay.href = "";
  btnPlay.rel = "nofollow";
  btnPlay.innerHTML = '<img src="/images/0.png" class="play" alt="Play" title="Play" />';
  btnPlay.onclick = startShow;
  buttonsdiv.appendChild(btnPlay);

  var btnStop = d.createElement('A');
  btnStop.href = "";
  btnStop.rel = "nofollow";
  btnStop.innerHTML = '<img src="/images/0.png" class="stop" alt="Stop" title="Stop" />';
  btnStop.onclick = stopShow;
  buttonsdiv.appendChild(btnStop);

  var btnNext = d.createElement('A');
  btnNext.href = "";
  btnNext.rel = "nofollow";
  btnNext.innerHTML = '<img src="/images/0.png" class="next" alt="Next" title="Next" />';
  btnNext.onclick = goNext;
  buttonsdiv.appendChild(btnNext);

  var indicators = d.createElement('DIV');
  indicators.className = 'slideshowpages';
  for(var idx=0; idx < entries.length; idx++) {
    var title = "Page "+(idx+1)+" of "+entries.length;
    var img = d.createElement('IMG');
    img.title = img.alt = title;
    img.src = "/images/0.png";
    img.setAttribute("rel", idx);
    img.onclick = goTo;
    indicators.appendChild(img);
  }
  control.appendChild(buttonsdiv);
  control.appendChild(indicators);
  
  slides.appendChild(control);
  
  loadSlide(0);
  
  $(document).ready(function() {start();});
  
  function disableButton(btn) {
    btn.disabled = true;
    var images = btn.getElementsByTagName("IMG");
    images[0].style.backgroundPosition = "left bottom";
  }
  
  function enableButton(btn) {
    btn.disabled = false;
    var images = btn.getElementsByTagName("IMG");
    images[0].style.backgroundPosition = "left top";
  }
  
  function loadContent() {
    return $.ajax({
      type: "POST",
      url: "/weblog/slide",
      cache: false,
      async: false,
      dataType: "text",
      data: "weblog_id="+id+"&entry_id="+entries[currentslide]+"&field="+field
    }).responseText;
  }
  
  function loadSlide(entry_id) {
    var images = indicators.getElementsByTagName("IMG");
    images[currentslide].style.backgroundPosition = "left top";
    currentslide = entry_id;
    images[currentslide].style.backgroundPosition = "left bottom";
    if(null == slides[currentslide]) {
      parent.innerHTML = '<img src="/images/0.png" style="background: url('+loadImage+') no-repeat center center; width: 100%; height: 100%" />';
      slides[currentslide] = loadContent();
    }
    parent.innerHTML = slides[currentslide];
    if(slideTimer == null) {
      if(currentslide == entries.length-1) disableButton(btnNext); else enableButton(btnNext);
      if(currentslide == 0) disableButton(btnPrev); else enableButton(btnPrev);
    }
    if(after_loaded != null) after_loaded(currentslide);
  }
  
  function nextSlide() {
    var next = currentslide+1;
    if(next >= entries.length) next = 0;
    loadSlide(next);
    return false;
  }
  
  function start() {
    slideTimer = setInterval(nextSlide, timeout*1000);
    disableButton(btnPrev);
    disableButton(btnPlay);
    disableButton(btnNext);
    enableButton(btnStop);
    if(onstart != null) onstart();
    return false;
  }
  
  function startShow(evt) {
    start();
    var e = evt == null? window.event: evt;
    if(e != null) {
      e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
    }
    return false;
  }

  function stopShow(evt) {
    if(slideTimer != null) clearInterval(slideTimer);
    slideTimer = null;
    if(currentslide < entries.length-1) enableButton(btnNext);
    enableButton(btnPlay);
    if(currentslide > 0) enableButton(btnPrev);
    disableButton(btnStop);
    if(onstop != null) onstop();
    var e = evt == null? window.event: evt;
    if(e != null) {
      e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
    }
    return false;
  }

  function goNext(evt) {
    var next = currentslide+1;
    if(slideTimer == null && next < entries.length) loadSlide(next);
    var e = evt == null? window.event: evt;
    if(e != null) {
      e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
    }
    return false;
  }

  function goPrevious(evt) {
    var next = currentslide-1;
    if(slideTimer == null && next >= 0) loadSlide(next);
    var e = evt == null? window.event: evt;
    if(e != null) {
      e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
    }
    return false;
  }

  function getTarget(x){
    x = x || window.event;
    return x.target || x.srcElement;
  }
  
  function goTo(evt) {
    var e = evt == null? window.event: evt;
    if(e != null) {
      var elem = getTarget(evt);
      if(slideTimer == null && elem.getAttribute("rel") != null && elem.getAttribute("rel") != currentslide) {
        loadSlide(parseInt(elem.getAttribute("rel")));
      }
      e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
    }
    return false;
  }
  
  function pause(millis) {
    var date = new Date();
    var curDate = null;
    do { curDate = new Date();
    } while(curDate-date < millis);
  } 
}