// JavaScript Document
function CSTslideshow(instance, imagecountIn, intervalIn, memory) {
	imagecount = +imagecountIn;			// PHP sends strings - convert to numbers
	interval = +intervalIn;				// PHP sends strings - convert to numbers
	firstSlide = getStart(instance)			// get first slide of sequence
	MM_effectAppearFade('slideshow'+firstSlide+instance, 1000, 0, 100, false);
	MM_changeProp('slideshow'+firstSlide+instance,'','zIndex','10','DIV');
	setCookie('CSTss'+instance,firstSlide,'','','','/','','');
	if (imagecount > 1) {
		rotate(instance, imagecount, interval, firstSlide);
		rotateInterval = interval * imagecount;
		setInterval('rotate("'+instance+'", "'+imagecount+'", "'+interval+'", "'+firstSlide+'")',rotateInterval);
	}
}

function getStart (instance){
	cval = getCookie('CSTss'+instance)
	if (cval) {
		return +cval;
	}
	else {
		return 0;
	}
}

function rotate(instance, imagecount, interval, firstSlide) {
	
	next = +firstSlide;
	currentSlide = +firstSlide;
	for (i=0; i<=imagecount-1; i++) {
		intrvl = (i+1) * interval;
		next++;
		if (next > (imagecount - 1)) {next = 0;}
		setTimeout(	'MM_effectAppearFade(\'slideshow'+currentSlide+instance+'\', 1000, 100, 0, false);MM_effectAppearFade(\'slideshow'+next+instance+'\', 1000, 0, 100, false);MM_changeProp(\'slideshow'+currentSlide+instance+'\',\'\',\'zIndex\',\'1\',\'DIV\');MM_changeProp(\'slideshow'+next+instance+'\',\'\',\'zIndex\',\'10\',\'DIV\');setCookie(\'CSTss'+instance+'\',\''+next+'\',\'\',\'\',\'\',\'/\',\'\',\'\')',intrvl);
		currentSlide++;
		if (currentSlide > +imagecount-1) {currentSlide = 0};
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y ) {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}
