/* 
Copyright 2007 Kraig Larson, kraig-at-ciceron-dot-com
Last modified: 2007-02-24
*/
/* For each slideshow frame, insert HTML  and label */
var images = new Array();
images[0] = { htm:'<img src="minneapolis-hotel-images/hotel-0.jpg" alt="" title="Chambers Minneapolis - outside view" width="630" height="300" />', fcaption:'Chambers Minneapolis - a view from the street', flabel:'', fsrc:'minneapolis-hotel-images/hotel-0.jpg' };
images[1] = { htm:'<img src="minneapolis-hotel-images/hotel-1.jpg" alt="" title="Bar and Outdoor Patio Photo by Stuart Lorenz" width="630" height="300" />', fcaption:'Rooftop balcony and lounge Photo by Stuart Lorenz', flabel:'', fsrc:'minneapolis-hotel-images/hotel-1.jpg' };
images[2] = { htm:'<img src="minneapolis-hotel-images/hotel-2.jpg" alt="" title="Chambers Front Desk Photo by Stuart Lorenz" width="630" height="300" />', fcaption:'Chambers lobby and front desk Photo by Stuart Lorenz', flabel:'', fsrc:'minneapolis-hotel-images/hotel-2.jpg' };
images[3] = { htm:'<img src="minneapolis-hotel-images/hotel-3.jpg" alt="" title="Chambers Lobby Photo by Stuart Lorenz" width="630" height="300" />', fcaption:'Chambers lobby Photo by Stuart Lorenz', flabel:'', fsrc:'minneapolis-hotel-images/hotel-3.jpg' };
images[4] = { htm:'<img src="minneapolis-hotel-images/hotel-4.jpg" alt="" title="Chambers lobby bar Photo by Stuart Lorenz" width="630" height="300" />', fcaption:'Chambers lobby bar Photo by Stuart Lorenz', flabel:'', fsrc:'minneapolis-hotel-images/hotel-4.jpg' };
images[5] = { htm:'<img src="minneapolis-hotel-images/hotel-5.jpg" alt="" title="Chambers Courtyard Photo by Jerry Swanson" width="630" height="300" />', fcaption:'Chambers courtyard by Jerry Swanson', flabel:'', fsrc:'minneapolis-hotel-images/hotel-5.jpg' };

/* settings: customize these variables for your page */
var imageID = "cfimage";
var timerTimeout = 3000;


/* do not change anything below this */
var curr = 0;
var photoTimer;
var photoAnim;
var isTiming = 1;

showImg = function(p) {
	hideCaption();
	if (!isTiming) { btn=YAHOO.util.Dom.get('btnpauseplay'); btn.src = 'i/pause.png'; isTiming=1; }
	curr = p;
	clearTimeout(photoTimer);
	imgCon = YAHOO.util.Dom.get(imageID); 
	YAHOO.util.Dom.setStyle([imageID], 'opacity', 0); 
	imgCon.innerHTML = images[p].htm;
	YAHOO.util.Dom.get('cf_caption_content').innerHTML = images[p].fcaption; 
	fadeIn(imageID,imgCon);
}
startTimer = function() {
	if (photoAnim) { photoAnim.onComplete.unsubscribeAll(); }
	curr ++; if (curr >= images.length) { curr=0; }
	photoTimer = setTimeout("showImg(curr)",timerTimeout);
}
goNext = function() {
	if (photoAnim) { photoAnim.onComplete.unsubscribeAll(); }
	curr ++; if (curr >= images.length) { curr=0; }
	showImg(curr);
}

toggleTimeout = function() {
	btn=YAHOO.util.Dom.get('btnpauseplay');
	if (photoAnim) { photoAnim.onComplete.unsubscribeAll(); }
	clearTimeout(photoTimer);
	if (isTiming) { 
		btn.src = 'i/play.png';
		isTiming=0; 
	}
	else if (!isTiming) {
		curr++; if (curr >= images.length) { curr=0; }; showImg(curr);
		btn.src = 'i/pause.png';
		isTiming=1;
	}
}
showCaption = function() {
	//if (images[curr].fcaption != '') {
	if (YAHOO.util.Dom.get('cf_caption_content').innerHTML != '') {
		YAHOO.util.Dom.setStyle('cf_caption','display','block');
	}
}
hideCaption = function() {
	YAHOO.util.Dom.setStyle('cf_caption','display','none');
}
goHome = function() {
	showImg(0); 
}
function fadeIn(e,wp) {
	//alert('e='+ e + '\nwp=' + wp);
	photoAnim = new YAHOO.util.Anim(wp, { opacity: { from: 0, to: 1 } }, 1, YAHOO.util.Easing.easeOut);
	photoAnim.onComplete.subscribe(startTimer);
	photoAnim.animate();
}
function preloadImages(e) {
	//preload = YAHOO.util.Dom.get('cf_preload');
	imglst = YAHOO.util.Dom.get('imagelist');
	imglst.innerHTML += '<img id="btnpauseplay" src="i/pause.png" title="Click to Pause or Resume" onclick="toggleTimeout();" />';
	for (x in images) {
		//preload.innerHTML += images[x].htm;
		imglst.innerHTML += '<a href=\"javascript:showImg(' + x + ');\" onmouseover="hideCaption();" class="imglistthumb" title="' + images[x].flabel + '"><img src=\"' + images[x].fsrc + '" /><\/a> ';
	}
	photoTimer = setTimeout("showImg(1)",timerTimeout*2);
	//imglst.innerHTML += '<img src="i/home.png" onclick="goHome();" />   <img id="btnpauseplay" src="i/pause.png" title="Click to Pause or Resume" onclick="toggleTimeout();" />';
	showImg(0);
}

YAHOO.util.Event.onAvailable('cf_preload', preloadImages, this);