/* ************************************************************
// JavaScript: www.coldwellbankerpremier.com/js/slideshow.js
// ©2009 by Inico.com, LLC
// Last modified: 2009-10-02 11:41:41 UTC
// ************************************************************
*/

document.imageCurrentNumber=0
var mlsNum




function set_onerror(){
	document.imageRef.src =  _maris_image_url(mlsNum, parseInt(document.imageCurrentNumber))
}

function slideshow ( ){

	if(document.imageCurrentNumber == undefined)
	document.imageCurrentNumber = 1

	if( document.imageCurrentNumber >= document.imageCount)
	document.imageCurrentNumber=0

	mlsNum = parseInt(  document.imageSrc.substr( document.imageSrc.lastIndexOf('/')+1) );


	document.imageRef.src = document.imageSrc.replace(/_\d+\.jpg$/, '_' + document.imageCurrentNumber + '.jpg')

	document.imageRef.onerror= set_onerror



	document.imageSrc = document.imageRef.src

	document.imageRef.width= 382;
	document.imageRef.height =283;

	document.imageCurrentNumber =  parseInt(document.imageCurrentNumber)+1
}

function slideshow_init (imageId,imageCount, iconID, startINDEX){



	if (!imageId)return false ;
	document.imageRef = _gebi(imageId)

	if (!document.imageRef )return false ;
	if(document.imageRef && !document.imageSrc)
	document.imageSrc = document.imageRef.src


	if(startINDEX >0 && document.imageCurrentNumber ==0)
	document.imageCurrentNumber = startINDEX

         // show starting slideshow image
	//document.imageRef.src= '/img/startingslideshow.jpg'

	if (!imageCount || imageCount < 2)return false ;

	if(iconID){
		iconRef =  _gebi(iconID)
		iconsrc = iconRef.src
		iconRef.src = iconsrc.replace(/\.gif$/, '_ani.gif')
		iconRef.title = "Click to STOP slideshow!"
		iconRef.alt = "Click to STOP slideshow!"
		}


	startstopsignal =  _gebi('starting_slideshow')
	if(startstopsignal){

		startstopsignalSrc = startstopsignal.src
		if(startstopsignalSrc.lastIndexOf('_start.gif') == -1)
		startstopsignal.src = startstopsignalSrc.replace(/\_1st\.gif$/, '_start.gif').replace(/\_stop\.gif$/, '_start.gif')

			startstopsignal.style.display='block';
	}


	document.imageCount = imageCount;
	document.imageSlideshow =setInterval('slideshow()',3000);

}

function  slideshow_stop(iconID){



	if(document.imageSlideshow){


		clearInterval(document.imageSlideshow)
		document.imageSlideshow = false

		if(iconID){
		iconRef =  _gebi(iconID)
		iconsrc = iconRef.src
		iconRef.src = iconsrc.replace(/_ani\.gif$/, '.gif')
		iconRef.title = "Click to START slideshow!"
		iconRef.alt = "Click to START slideshow!"
		}

		startstopsignal =  _gebi('starting_slideshow')
		if(startstopsignal){

			startstopsignalSrc = startstopsignal.src
			if(startstopsignalSrc.lastIndexOf('_stop.gif') == -1)
			startstopsignal.src = startstopsignalSrc.replace(/_1st\.gif$/, '_stop.gif').replace(/_start\.gif$/, '_stop.gif')

			startstopsignal.style.display='block';
		}


		return true;
	}
	return false;
}


function _maris_image_url(myMLS,myIDX){

//var ms =  "http://72.26.1"  "13.54"
//var ms =  "http://mar" + "is.rap" + "mls.com"
var ms = 	"http://medialaxa.rap" + "mls.com/gstl/maris"


 	if(!myMLS)
 	  return "about:blank"

 	if(!myIDX)
	 	myIDX =0;

	myMLS = String(myMLS);

 	if(myIDX==0)
 		return ms + "/listingpics/bigphoto/0" + myMLS.substr(myMLS.length -2,2) + "/" + myMLS+ ".jpg";
 	else if(myIDX>0 && myIDX <10)
 		return ms + "/listingpics/bigphoto/0" + myMLS.substr(myMLS.length -2,2) + "/" + myMLS+'_0' + String(myIDX)  + ".jpg";
 	else if(myIDX>9 )
 		return ms + "/listingpics/bigphoto/0" + myMLS.substr(myMLS.length -2,2) + "/" + myMLS+'_' +  String(myIDX) + ".jpg";

}


