
vlen=0;

sshow = new Object();								// global state variables
sshow.mode=1; // homepage

//configurations
sshow.initimage						=	-1;
sshow.randomStart					= true;
sshow.currentid						=	-1; 			// no last image on first draw of the page
sshow.init_big_opacity				=	100; 				// starting point of the first opacity of the big image
sshow.slideshowWrapAround			=	1;				// slideshow wrap around mode 1 = yes wrap around 0 = do not wrap
sshow.fadeouttime					=	.8; 			// seconds it takes to fade in or out
sshow.fadeintime					=	.8; 			// seconds it takes to fad in or out
sshow.bigImageQuality				=	'87'; 			// jpeg quality
sshow.thumbScrollSpeed				=	10; 			// how quickly does the thumb get to the right spot
sshow.thumbRefreshFrequency			=	70;			 	// miliseconds between refreshes 100=1/10th second
sshow.bigImageInitialOpacity		=	0;
sshow.showTotalCount				= 	1;				// show the total count of images
sshow.playOnStart					= 	1;				// auto plays the slideshow
sshow.playSlideshowPeriod			=	7;				// number of seconds between images
sshow.bigImagePixels				=	597;			// pixels of maximum width
sshow.delaytime						= 	.1;				// time to delay from fade-in to slideshow
sshow.fadeOutdelaytime				= 	.2;
sshow.safetytime					= 	.1;
sshow.donothing=1;
sshow.totalImages=0;
sshow.baseURL='http://images.prod.ipnservices.com/dyn_images';
// status arrays
sshow.bigImagePreloaded=new Array();
sshow.bigImageDimensions=new Array();
sshow.thumbnailCrop = new Array();
sshow.thumbnailZoom = new Array();
sshow.thumbnailOpacity = new Array();
sshow.ssImage_controls  = new Array();
sshow.layer=900;

function playSS(){
	$('image_div').style.zoom = (100 ) + '%';
	$('image_div').style['MozTransform'] = 'scale(1)';
	$('the_image').style.zoom = (100) + '%';
	$('the_image').style['MozTransform'] = 'scale(1)';
}

function slideShowStart(){
	makeBigImages();
}
	
function makeBigImages(){  		// make big images as empty items in the DOM	
	sshow.totalImages=0;
	var tindex=0; // which image are we building
  qq("function","makeBigImages");
	
	sshow.totalImages=slideShowData.length;
	
  qq("total images",sshow.totalImages);
	for(var i=0;i<sshow.totalImages;i++){
	
		var ssImageID=slideShowData[i]['details']['image_id'];
		qq('ssImageId',ssImageID);
  	if(ssImageID.length==10){
			// make the wrap node
			var nnode = document.createElement('div');
			nnode.setAttribute("id","main_image_" + tindex);
			nnode.setAttribute("class","main_image_display");
			sshow.layer++;
			var browserName=navigator.appName;
			var browserVersion = parseInt(navigator.appVersion);
			if (browserName=="Microsoft Internet Explorer" && browserVersion >= 8){
				nnode.style.position = "absolute";	
				nnode.style.zIndex = sshow.layer;
				nnode.style.filter = 'alpha(opacity=' + sshow.bigImageInitialOpacity + ')'; 
			} else{ 
				nnode.setAttribute("style","display: block; text-align: center;position: absolute;left:0px;top:0px;z-index: " + sshow.layer + ";opacity:" + sshow.bigImageInitialOpacity/100 + ";filter:alpha(opacity=" + sshow.bigImageInitialOpacity + ");");
			}	
			// make the image node
			var nnode2 =  document.createElement('img');
			nnode2.setAttribute("id","the_image" + tindex);
			nnode2.setAttribute("src", sshow.baseURL + "/" + sshow.bigImagePixels + "/" + sshow.bigImageQuality + "/" + ssImageID +  ".JPG" );
			nnode2.setAttribute("class","the_image_image");
			nnode2.setAttribute("style","display: block;");
			nnode2.setAttribute("onload","sshowUpdateSize(this,'" + tindex + "');");
			nnode.appendChild(nnode2);
			slideShowNode.appendChild(nnode);
			sshow.bigImagePreloaded.push('1000|1000');	
			sshow.bigImageDimensions.push('0|0');
			sshow.ssImage_controls.push();	
/* 			new Effect.Scale($('the_image' + tindex), (ssImageStartScale * 100), {duration: .01}); */
  		tindex++;
		};
	}
};

function sshowUpdateSize(obj,tindex){
	var dimensions=$('the_image' + tindex).getDimensions();
	if(dimensions.width > 0){
		sshow.bigImageDimensions[tindex]=dimensions.width + '|' + dimensions.height;
		if(sshow.initimage==-1){
			sshow.initimage=(sshow.randomStart ? Math.floor(Math.random() * sshow.totalImages) : '0' );
 			qq('dimensions',dimensions.width + ',' + dimensions.height + ',' +  tindex);
			goToImageByIndex(sshow.initimage); // first image to load is first of slideshow
		}
	}
};

function goToImageByIndex(gid){
	qq('function goToImageByIndex',gid);
	if(sshow.currentid != gid){  // is the new go to id different than the current id
		sshow.layer++;
		$('main_image_' + gid).style.visibility="hidden";
		$('the_image' + gid).style.visibility="hidden";
//			new Effect.Scale($('the_image' + gid), (parseFloat(kbScaleStart).toFixed(5) * 100), {duration: 0,
//				scaleMode: { originalHeight: sshow.bigImageDimensions[gid].split('|')[1], originalWidth: sshow.bigImageDimensions[gid].split('|')[0] }
//			});
		document.getElementById('main_image_' + gid).style.zIndex=sshow.layer;
		new Effect.Opacity($('main_image_' + gid), {  from: 0, to: 1, duration: sshow.fadeintime, delay: sshow.delaytime});
		$('main_image_' + gid).style.display='block';
		$('main_image_' + gid).style.visibility='visible';
		$('the_image' + gid).style.visibility="visible";
		$('the_image' + gid).style.display='block';
		var tdelay1= parseInt(sshow.fadeintime) + parseInt(sshow.delaytime) + parseInt(sshow.safetytime);;
		// fadeout
	  var tdelay= parseInt(sshow.fadeintime) +  parseInt(sshow.delaytime) + parseInt(sshow.safetytime) + parseInt(sshow.playSlideshowPeriod) + parseInt(sshow.fadeOutdelaytime) + parseInt(sshow.fadeouttime);
	  new Effect.Opacity($('main_image_' + gid), {  from: 1, to: 0, duration: sshow.fadeouttime, delay: tdelay});	         
	  sshow.nextTiming = setTimeout("slideshowNextImage();",tdelay * 1000);
		sshow.donothing=0;
		var tat = sshow.bigImageDimensions[gid];
		sshow.currentid=gid;//done assign the current to the incoming changeto id.
	} else {
		qq('error');
	}
};


function slideshowNextImage(){
	var tnext=parseInt(sshow.currentid) + 1;
  qq('next id',tnext + ',' + slideShowData.length);

	if(tnext >= (parseInt(slideShowData.length)) ){
		if(sshow.slideshowWrapAround==1){
			tnext=0;
			goToImageByIndex(tnext);
		} else {
			slideshowStop();
		}
	} else {
		goToImageByIndex(tnext);
	}
}
function slideshowPreviousImage(){
	var tprev=sshow.currentid-1;
	slideshowStop();

	if(tprev < 0 ){
		if(sshow.slideshowWrapAround==1){
			tprev=slideShowData.length;
			goToImageByIndex(tprev);
		} else {
		}
	} else {
		goToImageByIndex(tprev);
	}
}

function slideshowStart(){
	slideshowNextImage();
	sshow.slideshowIntervalObject = setInterval("slideshowNextImage();",sshow.playSlideshowPeriod * 1000);
}

function slideshowStop(){
	clearInterval(sshow.slideshowIntervalObject);
	clearTimeout(sshow.nextTiming);
}
qqobj = new Object();
qqobj.loopbuster=0;
globaltimerStart=new Date();
globaltimerLastTime = globaltimerStart;
function qq(p,n,m){
        qqobj.loopbuster++;
        var newtime = new Date();
        if (qqobj.loopbuster < 900){
                var echo= ((newtime.getTime() - globaltimerStart)/1000).toFixed(4) + ' :: '  +  ((newtime.getTime() - globaltimerLastTime)/1000).toFixed(4) + ' :: ' + p + '=' + n + '<br\>' + $('debug_data').innerHTML;
                if(self.location.href.indexOf('debugmode')>=0){
                        if(utilParseUrlParam('debugmode')== m ){
                                $('debug_data').innerHTML = echo;
                        }
                } else {
                        $('debug_data').innerHTML = echo;
                }
        }
        globaltimerLastTime=newtime.getTime();
}

        function utilParseUrlParam( name ){                name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");                var regexS = "[\\?&]"+name+"=([^&#]*)";                var regex = new RegExp( regexS );                var results = regex.exec( window.location.href );                if( results == null )                return "";                else                return results[1];        };        function utilTrim(stringToTrim) {                return stringToTrim.replace(/^\s+|\s+$/g,"");        };        function utilAddCommas(nStr){                nStr += '';                x = nStr.split('.');
                x1 = x[0];
                x2 = x.length > 1 ? '.' + x[1] : '';
                var rgx = /(\d+)(\d{3})/;
                while (rgx.test(x1)) {
                        x1 = x1.replace(rgx, '$1' + ',' + '$2');
                }
                return x1 + x2;
        };



