// initital variables for slideshow
var cookie_slide_show_counter = getCookie("slideshow_image");
var slide_show_counter = (cookie_slide_show_counter ? cookie_slide_show_counter : 1);
var slide_show_running = false;

/**
 * run image slideshow
 *         
 * @return void
 */
function slideShowRun() {
  var img = document.getElementById("slide_img");
  
	if (document.all && slide_show_running){
	  img.style.filter="blendTrans(duration=1)";
    img.filters.blendTrans.Apply();
  }  
  
  img.src = "gfx/observator_logo_" + slide_show_counter + ".jpg";
  
	if (document.all && slide_show_running){
	  img.filters.blendTrans.Play();
	}
  
	setCookie("slideshow_image", slide_show_counter); 
  
  slide_show_counter++;
	if (slide_show_counter > 5) {
	  slide_show_counter = 1;
	}
	
	// preload next image
	var img = new Image();
	img.src = + "gfx/observator_logo_" + slide_show_counter + ".jpg";
	
	if (!slide_show_running) {
	  slide_show_running = true;
	}
	
	var t = setTimeout('slideShowRun()', slide_show_speed);
}

/**
 * get cookie value
 *         
 * @param string name    name of cookie
 * @return mixed         value of cookie if cookie set, undefined otherwise
 */
function getCookie(name) {
  var t;
  var search = name + "=";
  
  if (document.cookie.length) {
    var start = document.cookie.indexOf(search);
    if (start != -1) {
      start += search.length;
      end = document.cookie.indexOf(";", start);
      
      if (end == -1) {
        end = document.cookie.length;
      }
      
      t = unescape(document.cookie.substring(start, end));
    }
  }
  
  return t;
}

/**
 * set cookie value
 *         
 * @param string name            name of cookie
 * @param string value           value of cookie
 * @param integer days_expire    [optional] number of days after which cookie will expire
 * @return void
 */
function setCookie(name, value, days_expire) {
	if (days_expire) {
		var expires = new Date();
		expires.setTime(expires.getTime() + 1000*60*60*24*days_expire);
	}
	
	document.cookie = name + "=" + escape(value) + (days_expire == null ? "" : (";expires=" + expires.toGMTString())) + ";path=/";
}