// JavaScript Document

//ENTER IMAGE TOTAL
var iT=20;
var itCap=iT+1;

var n=Math.floor(Math.random()*itCap);
while(n==0){np=Math.floor(Math.random()*itCap);};
var np=Math.floor(Math.random()*itCap);
while(np==n||n==0){np=Math.floor(Math.random()*itCap);};
var npp=n;
var nppp=np;
//var d=1;

var c=0;
var imgTimer;
var timer_is_on=0;

var resShow=1;
var tS=0;
// variable holding active description field
var desOld=0;
var tog=1;
var p1="slideshow/";
var p2="slideshow/office/";
var oldPath=p1;
var path=p1;
var sw="<span style=\"color:white\">";
var swc="</span>";


function start()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  pauseSlide();
  }
}
//POPULATES IMAGES AND STARTS SLIDESHOW
function getGoing(){
	document.getElementById('slide2').src=path+np+".jpg";
	document.getElementById('slide3').src=path+n+".jpg";
	//document.getElementById('slide1').src="slideshow/"+npp+".jpg";
	pauseSlide();
	}
	

//checks for rollovers over image to pause when mouse not over image
function resumeShow(){
	if(resShow==0){
	resumeSlide();;resShow=1;
	}
}
function pauseShow(){
	if(resShow==1){
	clearTimeout(imgTimer);resShow=0;
	};
}

// TIMER
function pauseSlide()
{
	//alert('paused slide');
imgTimer=setTimeout("fadeEffect.init('slide2',"+tog+")",3000);
}



// FADER
var fadeEffect=function(){
	return{
		init:function(id, flag, target){
			this.elem = document.getElementById(id);
			clearInterval(this.elem.si);
			this.target = target ? target : flag ? 100 : 0;
			this.flag = flag || -1;
			this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
			this.si = setInterval(function(){fadeEffect.tween()}, 20);
		},
		tween:function(){
			if(this.alpha == this.target){
				clearInterval(this.si);shuffleImages();
			}else{
				var value = Math.round(this.alpha + ((this.target - this.alpha) * .05)) + (1 * this.flag);
				this.elem.style.opacity = value / 100;
				this.elem.style.filter = 'alpha(opacity=' + value + ')';
				this.alpha = value
			}
		}
	}
}();

//SWITCH IMAGE SOURCE FILES
function shuffleImages(){
	clearTimeout(imgTimer);
//REGENERATE RANDOM NUMBER	
			nppp=npp;	
			npp=np;	
			np=n;
			n=Math.floor(Math.random()*itCap);
			while(n==np||n==npp||n==nppp||n==0){n=Math.floor(Math.random()*itCap);};
// SWAP IMAGE FILE SOURCE
	if(tog==1){document.getElementById('slide3').src=path+n+".jpg";tog=0;}
		else{document.getElementById('slide2').src=path+n+".jpg";tog=1
	};
	pauseSlide();
};

// SHIFTS BETWEEN OFFICE AND OTHER IMAGES
function checkPath(){
	if (oldPath!==path){
	nppp=npp;	
	npp=np;	
	np=n;
	n=Math.floor(Math.random()*itCap);
	while(n==np||n==npp||n==nppp||n==0){n=Math.floor(Math.random()*itCap);};
	if(tog==1){document.getElementById('slide3').src=path+n+".jpg";document.getElementById('slide2').src=path+n+".jpg";}
		else{
	document.getElementById('slide2').src=path+n+".jpg";document.getElementById('slide3').src=path+n+".jpg";
		};
	};
};

// ROLLOVER GENERIC
function btnOver(id,file){
	document.getElementById(id).src=file;
	}
	
function btnOut(id,file){
	document.getElementById(id).src=file;
	}

// ROLLOVER NAV
function swapOver(cat){
	if(cat!=desOld){
	document.getElementById(cat).src="img/nav/"+cat+"-over.png";
	}
	}
	
function swapOut(cat){
	if(cat!=desOld){
	document.getElementById(cat).src="img/nav/"+cat+".png";
	}
	}
	

// POPULATE COPY
function showDescr(des){
	if(desOld!=0){
		document.getElementById(desOld).src="img/nav/"+desOld+".png";
		}
	document.getElementById(des).src="img/nav/"+des+"-active.png";
	if(des==desOld){
		document.getElementById("description").style.visibility="hidden";
		document.getElementById(des).src="img/nav/"+des+".png";
		des=0;
		//resumeShow();
		}
	else if(des=="nav-about"){
		document.getElementById("descrBody").innerHTML="The Aviary is where cocktails and service are given the same attention to detail as a four-star restaurant;  where bartenders are trained as chefs;  where the produce and herbs are carefully sourced and procured fresh daily;  where the name and branding of the spirit mixed is less important than its actual flavor;  where drinks are made quickly and consistently in a state-of-the-art drink kitchen;  where innovation and tradition are both honored.<br /><br />Chef Craig Schoettler presides over our kitchen.<br /><br />The Aviary is owned and operated by chef Grant Achatz and Nick Kokonas.";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p1;iT=20;checkPath();
		//pauseShow();
		}
	else if(des=="nav-reso"){
		document.getElementById("descrBody").innerHTML="The Aviary accepts a limited number of reservations daily at 6:00, 8:00, and 10:00 PM.  You may email your request to <a href=\"mailto:reservations@theaviary.com\">reservations@theaviary.com</a>.<br />Please indicate your desired time, party size, and contact details including your cell phone number. If randomly selected, we will contact you by 4:00 PM on the day of the reservation.<br />We also reserve the chef’s Kitchen Table for a 10-course cocktail tasting menu, paired carefully crafted bites of food for $165.  Parties of 2 or 4 may be requested.";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p1;iT=20;checkPath();
		//pauseShow();
		}
	else if(des=="nav-loc"){
		document.getElementById("descrBody").innerHTML="The Aviary is located at the corner of Fulton Market and Morgan streets.<br /><a href=\"http://maps.google.com/maps?q=fulton+market+%26+morgan,+chicago&hl=en&ll=41.886742,-87.652163&spn=0.001528,0.003039&sll=41.886741,-87.65203&sspn=0.000768,0.001519&z=19&iwloc=A\" target=\"_blank\">Click here for a map</a>.";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p1;iT=20;checkPath();
		//pauseShow();
		}
	else if(des=="nav-events"){
		document.getElementById("descrBody").innerHTML="The Aviary is available for private bookings from 20 to 80 people.  For more information please contact us at: <a href=\"mailto:reservations@theaviary.com\">reservations@theaviary.com</a> and indicate Private Event in the subject line.";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p1;iT=20;checkPath();
		//pauseShow();
		}
	else if(des=="nav-office"){
		document.getElementById("descrBody").innerHTML="We have a basement speakeasy – The Office.  It is available by invitation or by booking a private party for up to sixteen people.";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p2;iT=9;itCap=iT+1;checkPath();
		//pauseShow();
		}
	else if (des=="nav-menu"){
		document.getElementById("descrBody").innerHTML="PDF links go here";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p1;iT=20;checkPath();
		//pauseShow();
		}
	else if (des=="nav-links"){
		document.getElementById("descrBody").innerHTML="<h1>Video:</h1><a href=\"http://www.youtube.com/watch?v=fT_8BwdJtqA\" target=\"_blank\">"+sw+"Aviary Opening"+swc+"</a><br /><h1>Press:</h1><a href=\"http://online.wsj.com/article/SB10001424052748703730104576260740019813846.html\" target=\"_blank\">"+sw+"The Wall Street Journal"+swc+" - Raising the Bar</a><br /><a href=\"http://timeoutchicago.com/restaurants-bars/14860511/the-office-grant-achatzs-invitation-only-bar\" target=\"_blank\">"+sw+"Time Out Chicago"+swc+" - The Office | Grant Achatz\'s invitation-only bar</a><br /><a href=\"http://www.chicagomag.com/Chicago-Magazine/June-2011/Will-The-Aviary-Redefine-Cocktailing-in-Chicago/\" target=\"_blank\">"+sw+"Chicago Magazine"+swc+" - Will The Aviary Redefine Cocktailing in Chicago?</a><br /><a href=\"http://articles.chicagotribune.com/2011-03-09/entertainment/chi-aviary-cocktails-20110309_1_alinea-aviary-cocktail-program\" target=\"_blank\">"+sw+"Chicago Tribune"+swc+" - Aviary\'s cocktails aiming high</a><br /><a href=\"http://bites.today.com/_news/2011/07/18/7105301-the-high-tech-cocktail-future-happy-hour-is-now\" target=\"_blank\">"+sw+"MSNBC"+swc+" - The high-tech cocktail: Future happy hour is now!</a><br /><a href=\"http://www.chicagomag.com/Chicago-Magazine/August-2011/Best-of-Chicago-2011-Bars-and-Nightlife/\" target=\"_blank\">"+sw+"Chicago Magzine"+swc+" - Best Cocktail Lounge in Chicago</a><br /><a href=\"http://www.chicagoreader.com/chicago/aviary-grant-achatz-nick-kokonas/Content?oid=3907690\" target=\"_blank\">"+sw+"Chicago Reader"+swc+" - The Aviary: Grant Achatz and Nick Kokonas\'s latest project takes cocktails to the next level</a><br /><a href=\"http://www.foodandwine.com/articles/americas-best-new-bars\" target=\"_blank\">"+sw+"Food and Wine"+swc+" - America\'s Best New Bars</a><br /><h1>Blogs:</h1><a href=\"http://www.chicagonow.com/he-sippedshe-sipped/2011/05/a-peak-into-chicagos-new-hot-spot-the-aviary/\" target=\"_blank\">"+sw+"Chicago Now"+swc+" - A Peak into Chicago\'s New Hot Spot: The Aviary</a><br /><a href=\"http://gourmetpigs.blogspot.com/2011/07/aviary-kitchen-table-experience-chicago.html\" target=\"_blank\">"+sw+"Gourmet Pigs"+swc+" - The Aviary Kitchen Table Experience (Chicago)</a><br />";
		document.getElementById("description").style.visibility="visible";//oldPath=path;path=p1;iT=20;checkPath();
		//pauseShow();
		}
	else {
		document.getElementById("description").style.visibility="hidden";//oldPath=path;path=p1;iT=20;checkPath();
		//resumeShow();
		des=0;
		};
	
	desOld=des;
	
};

	
//IMAGE PRELOADER	
function preloader() 
{
     // counter
     var iPL = 1;
     // create object
     imageObj = new Image();
     // start preloading
     for(iPL=1; iPL<=iT; iPL++) 
     {
          imageObj.src="slideshow/"+iPL+".jpg";
     };
	 for(iPL=1; iPL<=9; iPL++) 
     {
          imageObj.src="slideshow/office/"+iPL+".jpg";
     };
};
