// global variables for this file
var width = window.screen.width
var height = window.screen.height
var recwidth  = 650
var recheight = 700
var picwidth  = 700
var picheight = 570

// determine width and height for recipes and pictures and set variables
function widthheight()
{
	if (height <= 600)
	{
		recwidth  = 650
		recheight = 565
		picwidth  = 700
		picheight = 565
	}
	else
	{
		recwidth  = 650
		recheight = 690
		picwidth  = 700
		picheight = 565
	}
}

// show pictures and title
function showpic()
{
	document.images.pic.src = imgs[n] ;
	document.title = title + (n+1) + " of " + (imgs.length)
}

// could preload the images to cache, but that would delay the start
// var preload = new Array();                             
// for( var i = 1; i < imgs.length; i++ )
// {                                            
//   preload[i] = new Image();           
//   preload[i].src = imgs[i];                                     
// }
// specify the onload event-handler
// window.onload = slideshow; 

// store an interval in a variable 3000 miliseconds = 3 seconds
var pause = 3000 ;
var runslideshow = true ;

// a function to display each image for the set interval
function slideshow(start)
{                       
  ( n == (imgs.length - 1 )) ? n = 0 : n++;  
	showpic() ;
	if (start) runslideshow = true ;
	if (runslideshow) setTimeout( "slideshow()", pause ) ;
}

// change subscript for previous image and show picture
function previmg()
{
	if (n > 0) n-- ;
	runslideshow = false ;
	showpic() ;
}

// change subscript for next image and show picture
function nextimg()
{
	if (n < imgs.length-1) n++ ;
	runslideshow = false ;
	showpic() ;
}

// popup for recipe - if popup not passed, open new window
function PopUpRecipe(page,popup)
{
	widthheight() ;
	var same = false ;
	if (popup == null)
	{
	popup = window.name ;
	same = true
	}
	window.open(page,popup,'width='+recwidth+',height='+recheight+',menubar=no,status=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0,replace');
	if (same)
	{
	window.resizeTo(recwidth,recheight) ;
	window.scrollbars = true ;
	window.status = false ;
	}
}

// popup for pictures - if popup not passed, open new window, npic is starting pic
function PopUpPic(page,popup)
{
	widthheight() ;
	var same = false ;
	if (popup == null)
	{
	popup = window.name ;
	same = true ;
	}
	window.open(page,popup,'width='+picwidth+',height='+picheight+',menubar=no,status=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0,replace');
	if (same)
	{
	window.resizeTo(picwidth,picheight) ;
	window.scrollbars = false ;
	window.status = false ;
	}
}

// popup for pictures - if popup not passed, open new window
function PopUpImg(page,popup)
{
	widthheight() ;
	var same = false ;
	if (popup == null)
	{
	popup = window.name ;
	same = true ;
	}
	window.open(page,popup,'width='+picwidth+',height='+picheight+',menubar=no,status=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0,replace');
	if (same)
	{
	window.resizeTo(picwidth,picheight) ;
	window.scrollbars = false ;
	window.status = false ;
	}
}
