var windowWidth, windowHeight, windowOffset, fullHeight, step, imageNumber, oldImageNumber;

function _doImage () {
	var oBox = document.getElementById('box');
	var oBackground = document.getElementsByTagName("BODY");

	if ( navigator.appName == "Netscape" || navigator.appName == "Opera" ) {
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
		windowOffset = window.pageYOffset;
		fullHeight = oBox.clientHeight;
	} else if ( document.documentElement.clientWidth ) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		windowOffset = document.documentElement.scrollTop;
		fullHeight = oBox.offsetHeight;
	} else {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
		windowOffset = document.body.scrollTop;
		fullHeight = oBox.offsetHeight;
	}

	oBox.style.width = ( windowWidth < 740 ) ? "420px" : ( windowWidth - 340 ) + "px";
	
	step = Math.ceil(( fullHeight - windowHeight ) / 10 );
	imageNumber = Math.floor( windowOffset / step );
	imageNumber = ( imageNumber > 9 ) ? 9 : imageNumber ;
	if ( imageNumber != oldImageNumber ) {
		oBackground[0].style.backgroundImage = "url(img/" + imageNumber + ".jpg)";
		oldImageNumber = imageNumber;
	}
}

var recipeNumber = false;
var oRecipe, iOffset;

function _popMove( box ) {
	oRecipe = document.getElementById( box );
	iOffset = Math.floor (( windowWidth - oRecipe.offsetWidth ) / 2 );
	oRecipe.style.left = ( iOffset < 0 ) ? "15px" : iOffset + "px";
	iOffset = Math.floor (( windowHeight - oRecipe.offsetHeight ) / 2 );
	oRecipe.style.top = ( iOffset < 0 ) ? eval( windowOffset + 10 ) + "px" : eval( windowOffset + iOffset ) + "px";
}

function _popUp ( number ) {
	if ( recipeNumber ) document.getElementById( 'recipe_' +  recipeNumber ).style.visibility = "hidden";
	_popMove( 'recipe_' +  number );
	recipeNumber = number;
	oRecipe.style.visibility = "visible";
}

function _popDown( number ) {
	document.getElementById( 'recipe_' +  number ).style.visibility = "hidden";
	recipeNumber = false;
}

function _popCenter () {
	if ( recipeNumber ) _popMove ( 'recipe_' + recipeNumber );
}

function _msie_replace_png_imgs() {
	var i, elements;

	elements = document.getElementsByTagName( "img" );
	for ( i = 0; i < elements.length; i++ ) {
		var img = elements[i];
		if ( img.src.toLowerCase().search(/\.png$/ ) < 0 ) continue;

		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src	+ "', sizingMethod='image')";
		img.src = "img/spacer.gif";
	}
}

if ( window.attachEvent && navigator.appName == "Microsoft Internet Explorer" ) window.attachEvent ( "onload", _msie_replace_png_imgs );

function _showRecipe ( url ) {
	nWide = 750;
	xPosition = ( screen.width - nWide ) / 2 - 10;
	if ( screen.width <= ( nWide + 20 ) ) {
		nWide = screen.width - 40;
		xPosition = 0;
	}
	nHigh = screen.height - 40;
	yPosition = 0;

	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
	
	recipeWindow = window.open( url, 'recipe', args );
	recipeWindow.focus();
}
