var recipeArray = $(".recipesbox") ; 
var curRec = false;
var recLength = recipeArray.length;
var recFadeValue = 30;
var limit = Math.floor(recLength / 2 ); 
					
function recFwd(){ 
	nextRec = curRec + 1;
	if(nextRec > limit){
	//	nextRec = 0;
	} else {
		changeRec (nextRec);

	}
}

function recBack(){
	nextRec = curRec - 1;
	if(nextRec < 0){
		//nextRec = recLength - 1;
	} else {
		changeRec (nextRec);
	}
}

function changeRec (nextRec){
	$("#loadingrec").fadeIn("fast");
	$(".recipesbox:visible").fadeOut("slow", function (){ 
		$(".recipesbox:eq("+(nextRec*2)+")").fadeIn("slow", function () { 
			$("#loadingrec").fadeOut("fast");
		});
		$(".recipesbox:eq("+(nextRec*2+1)+")").fadeIn("slow", function () {
		});
	});
	curRec = nextRec;
	if(nextRec == 0){
		$("#r_back").attr("src", "/img/arrow_left_inactive.gif"); 
	} else {
		$("#r_back").attr("src", "/img/arrow_left_active.gif"); 
	}
	if( nextRec >= limit){
		$("#r_fwd").attr("src", "/img/arrow_right_inactive.gif"); 
	} else {
		$("#r_fwd").attr("src", "/img/arrow_right_active.gif"); 
	}
	
}

function showRecipe(num){
	//alert (num);
}

function hideFlashContent() { 
	$("#swfph").hide().css("visibility", "hidden");
	
}

function restoreFlashContent() { 
	$("#swfph").show().css("visibility", "visible");
	
}
 

$(document).ready(function () {
	//$(".recipesbox").bind("click", function () {showRecipe(this.id.substr(10)); });
 
	$(".nyroRecipe").nyroModal();
	$(".nyroExtratext").nyroModal();

	$.fn.nyroModal.settings.processHandler = function ()  { hideFlashContent(); };
	$.fn.nyroModal.settings.endRemove = function ()  { restoreFlashContent(); }; 
		
		 
	if(recLength > 0) {
		$(".recipesbox:eq(0)").show();
	}
	if(recLength > 1){
		$(".recipesbox:eq(1)").show();
	}
	if(recLength > 2 ){
		curRec = 0;
		$("#recipesnav").show();
	//	$("#r_back").css("visibility", "hidden"); 
		$("#r_back").bind("click", function(){ recBack(); });
		$("#r_fwd").bind("click", function(){ recFwd(); });
		$("#r_fwd").attr("src", "/img/arrow_right_active.gif"); 
	} 
});
		