function _centerBox () {
	var w, h;
	// all except Explorer
	if ( self.innerHeight ) {
		w = self.innerWidth;
		h = self.innerHeight;
	// Internet Explorer 6 Strict Mode
	} else if ( document.documentElement && document.documentElement.clientHeight ) {
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	// other Internet Explorers
	} else if ( document.body ) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}

	var viewWidth = w;
	var viewHeight = h;

	var boxWidth = 730;
	var boxHeight = 430

	var leftOffset = Math.floor (( viewWidth - boxWidth ) / 2 );
	leftOffset = ( leftOffset > 10 ) ? leftOffset : 10 ;
	document.getElementById( "box" ).style.left = leftOffset + "px";

	var topOffset = Math.floor (( viewHeight - ( boxHeight + 40 )) / 2 );
	topOffset  = ( topOffset > 10 ) ? topOffset: 10 ;
	document.getElementById( "box" ).style.top = topOffset + "px";

	leftOffset = ( leftOffset % 240 );
	topOffset = ( topOffset % 200 );
	document.getElementById( "box" ).style.background = "url( images/pattern_light.png  ) -" + leftOffset + "px -" + topOffset + "px";

	var offset = Math.floor (( viewWidth - 400 ) / 2 );
	document.getElementById( "copy" ).style.left = ( offset > 10 ) ? offset + "px" : "10px" ;
	offset = viewHeight - 20;
	document.getElementById( "copy" ).style.top = ( offset > 402 ) ? offset + "px" : "402px" ;

	if ( timer !== undefined ) clearInterval ( timer );
	_startTimer();
}

var timer = null;
var offset = 0;
var recipe = null;
var flashInterval = 100;
var scrollInterval = 400;
var offsetArray = new Array( 0, 60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 960, 1020, 1080, 1140, 1200, 1260, 1320, 1380 );

function _marquee () {
	_dynamic ( offset );
	offset = ( offset < 23 ) ? ( offset + 1 ) : 0 ;
}

function _startTimer () {
	if ( recipe !== null ) _hideCaption ( recipe );
	timer = setInterval ( "_marquee()", scrollInterval );
}

function _stopTimer ( thumb ) {
	clearInterval ( timer );
	stopOffset = ( offset > 0 ) ? ( offset - 1 ) : 23 ;
	recipe = (( stopOffset - thumb ) <= 0 ) ? ( stopOffset - thumb + 23 ) : ( stopOffset - thumb - 1 ) ;
	setTimeout ( "_blank ()", 1 * flashInterval );
	setTimeout ( "_static ( recipe )", 2 * flashInterval );
	setTimeout ( "_blank ()", 3 * flashInterval );
	setTimeout ( "_static ( recipe )", 4 * flashInterval );
	setTimeout ( "_blank ()", 5 * flashInterval );
	setTimeout ( "_dynamic ( stopOffset )", 6 * flashInterval );
	_showCaption ( recipe );
}

function _dynamic ( offset ) {
	var i, j, k;
	for ( i = 0; i < 24; i++ ) {
		j = 23 - i;
		k = (( i + offset ) < 24 ) ? ( i + offset ) : ( i + offset ) - 24 ;
		document.getElementById( "thumb_" + j ).style.background = "url( images/poissons.jpg ) no-repeat 0px -" + offsetArray[k] + "px";
	}
}

function _static ( recipe ) {
	var i, j;
	for ( i = 0; i < 24; i++ ) {
		j = 23 - i;
		document.getElementById( "thumb_" + j ).style.background = "url( images/poissons.jpg ) no-repeat 0px -" + offsetArray[recipe] + "px";
	}
}

function _blank () {
	var i, j;
	for ( i = 0; i < 24; i++ ) {
		j = 23 - i;
		document.getElementById( "thumb_" + j ).style.background = "url( images/poissons.jpg ) no-repeat -100px 0px";
	}
}

function _showList () {
	document.getElementById( "listOuter" ).style.visibility = "visible";
}

function _hideList () {
	document.getElementById( "listOuter" ).style.visibility = "hidden";
}

function _showCaption ( recipe ) {
	document.getElementById( "caption_" + recipe ).style.visibility = "visible";
	document.getElementById( "listOuter" ).style.visibility = "hidden";
}

function _hideCaption ( recipe ) {
	document.getElementById( "caption_" + recipe ).style.visibility = "hidden";
}

function _showRecipe () {
	var nWide = 750;
	var xPosition = ( screen.width - nWide ) / 2 - 10;
	if ( screen.width <= ( nWide + 20 ) ) {
		nWide = screen.width - 40;
		xPosition = 0;
	}
	var nHigh = screen.height - 40;
	var yPosition = 0;

	var args = "width=" + nWide + "," 
	+ "height=" + nHigh + "," 
	+ "location=no," 
	+ "menubar=no,"
	+ "resizable=yes,"
	+ "scrollbars=yes,"
	+ "status=yes," 
	+ "titlebar=no,"
	+ "toolbar=no,"
	+ "hotkeys=no,"
	+ "screenx=" + xPosition + ","  //NN Only
	+ "screeny=" + yPosition + ","  //NN Only
	+ "left=" + xPosition + ","     //IE Only
	+ "top=" + yPosition;           //IE Only
	
	_hideCaption ( recipe );
	var recipeString = ( recipe < 10 ) ? "0" + recipe : recipe ;
	var url = 'recipes/index.php?' + recipeString;
	var recipeWindow = window.open( url, 'recipe', args );
	recipeWindow.focus();
}
