  
  
 /* 
  
function init()
  {
    //pantryAnimate();
    $(".action_button_text").bind("click", pantryAnimate);
    getArrayIngredients();
    var servAr = createServArray();
    var system = "<?=UnitConverter::getUsedWeightSystem()=='US'?'US':'SI'?>";
    var liquid = <?=(int)$p['food']['liquid']?>;
    if(liquid==1)
    {
    if (system=='SI') var unit = 'ml'; else unit = 'fluid oz';  
    }else
    {
    if (system=='SI') var unit = 'g'; else unit = 'oz';
    }
    
     c = new Calorie('calculator1',servAr,unit,<?=$p['food']['weightIn200CInMainUnit'];?>);
     c.setLiquid(1,<?=$p['food']['weightIn200CInGr']?>);
     //refreshIngredients();
     c.attachHandlerToCalorie('onchange',refreshIngredients);
     c.attachHandlerToAmount('onchange',refreshIngredients);
     c.attachHandlerToSelect('onchange',refreshIngredients);
     
  }
   
  $(init);

  
  
  var clonePantryButton;
  
  var arrayIngredients = new Array();
  var offsetCloneNode = new Array();

  
  var weightIn200C=<?=$p['food']['weightIn200CInGr'];?>;

  function test()
  {
     
   YellowFade("pantry_button_id",1000);
  }
  
  
  
  function createServArray()
  {
    var ms = new Array();
    <?
    $servSizes = $p['food']['servingSizes'];
    if ($servSizes!==false)
       {
         $i = 0;
            foreach ($servSizes as $value)
                 if((int) $value['servingSizeQuantity']!==0){?>
                  ms[<?=$i?>] = new Array();
                  ms[<?=$i?>]['title']='<?=$value['servingSizeName']?>';
                  ms[<?=$i?>]['ratio']=<?=$value['ratio']?>;<?
             $i++;}
        }?>
    return ms;
  }
  */
  /*function getTop(obj)
{
  if (!obj.offsetParent)
    return obj.offsetTop;
  else
    return getTop(obj.offsetParent) + obj.offsetTop;
}

function getLeft(obj)
{
  if (!obj.offsetParent)
    return obj.offsetLeft;
  else
    return getLeft(obj.offsetParent) + obj.offsetLeft;
}
  
  */
  
  
  
  function omMouseOverAdditionalPhoto(path,newText)
  {
  	var j = document.getElementById('id_main_food_image');
  	document.getElementById('id_main_food_image').src = path;
  	document.getElementById('food_title').innerHTML = newText;
  }
  
  
  function omMouseOutAdditionalPhoto(pathMainPhoto,defaultText)
  {
  	document.getElementById('id_main_food_image').src = pathMainPhoto;
  	document.getElementById('food_title').innerHTML = defaultText;
  }
  
  
  function refreshIngredients()
  {
    var valueAmount = c.getAmountInGr();
    if(weightIn200C!==0)
    var koef = roundN(valueAmount/weightIn200C,2);
    else koef = roundN(valueAmount/100,2); //if food has no calories 
    ///
    iterator = 0;
    
    var ingrValues = $("#containerIngredients .nutrition_info_param_value");
    var vv = ingrArray['basicIngredients'].length;
    for(var i in ingrArray['basicIngredients'])
    {   
    
    	if(ingrArray['basicIngredients'][i]['weight'] == null) {
          cellValue = ' N/A ';
        } else {

          var cellValue = roundN(ingrArray['basicIngredients'][i]['weight']*koef,2);
          
          if(cellValue > 0)
            cellValue = cellValue.toFixed(2);

        }
        
        if(i == 'procnt') {
          $('#diagramm_protein_weight').text(cellValue);
        }
        
        if(i == 'fat') {
          $('#diagramm_fat_weight').text(cellValue);
        }

        if(i == 'chocdf') {
          $('#diagramm_carb_weight').text(cellValue);
        }
        
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      ingrValues[iterator].innerHTML = cellValue;
	      ingrValues[iterator].innerHTML = ingrValues[iterator].innerHTML +ingrArray['basicIngredients'][i]['units'];
	      
      iterator++;
    	if(ingrArray['basicIngredients'][i]['dependentIngredients']!==undefined)
    	for(var n in ingrArray['basicIngredients'][i]['dependentIngredients'])
    	{

          if(ingrArray['basicIngredients'][i]['dependentIngredients'][n]['weight'] == null) {
            cellValue = ' N/A ';
          } else {

            var cellValue = roundN(ingrArray['basicIngredients'][i]['dependentIngredients'][n]['weight']*koef,2);
            
            if(cellValue > 0)
              cellValue = cellValue.toFixed(2);

          }

	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      ingrValues[iterator].innerHTML = cellValue;
	      ingrValues[iterator].innerHTML = ingrValues[iterator].innerHTML +ingrArray['basicIngredients'][i]['dependentIngredients'][n]['units'];
	      iterator++;
    	}
    }
    
    //var ingrOtherValues = $("#containerIngredients .nutrition_info_param_value");

    for(var i in ingrArray['otherIngredients'])
    {
    	var cellValue = roundN(ingrArray['otherIngredients'][i]['weight']*koef,2);
        
        if(cellValue > 0)
	      cellValue = cellValue.toFixed(2);
          
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      ingrValues[iterator].innerHTML = cellValue;
	      ingrValues[iterator].innerHTML = ingrValues[iterator].innerHTML +ingrArray['otherIngredients'][i]['units'];
      iterator++;
    	if(ingrArray['otherIngredients'][i]['dependentIngredients']!==undefined)
    	for(var n in ingrArray['otherIngredients'][i]['dependentIngredients'])
    	{
	    	var cellValue = roundN(ingrArray['otherIngredients'][i]['dependentIngredients'][n]['weight']*koef,2);
            
          if(cellValue > 0)  
	        cellValue = cellValue.toFixed(2);
            
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      ingrValues[iterator].innerHTML = cellValue;
	      ingrValues[iterator].innerHTML = ingrValues[iterator].innerHTML +ingrArray['otherIngredients'][i]['dependentIngredients'][n]['units'];
	      iterator++;
    	}
    }
    
    
    
    iterator=0;
    var ingrPercents = $("#containerIngredients .nutrition_info_percent_value");
    
    
    for(var i in ingrArray['basicIngredients'])
    {
          if(ingrArray['basicIngredients'][i]['weight'] == null) {
            cellValue = ' N/A ';
          } else {

            var cellValue = roundN(ingrArray['basicIngredients'][i]['percent']*koef,1);
            
            if(cellValue > 0)
              cellValue = cellValue.toFixed(1);

          }
        
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      
          if((ingrPercents[iterator]) && (ingrPercents[iterator].innerHTML!==''))
	      {
		      ingrPercents[iterator].innerHTML = cellValue;
              
              if(cellValue != ' N/A ')
		        ingrPercents[iterator].innerHTML = ingrPercents[iterator].innerHTML +'%';
	      }
	      
      iterator++;
    	if(ingrArray['basicIngredients'][i]['dependentIngredients']!==undefined)
    	for(var n in ingrArray['basicIngredients'][i]['dependentIngredients'])
    	{
          
          if(ingrArray['basicIngredients'][i]['dependentIngredients'][n]['percent'] == null) {
          
            cellValue = ' N/A ';
            
          } else {

            var cellValue = roundN(ingrArray['basicIngredients'][i]['dependentIngredients'][n]['percent']*koef,1);
            
            if(cellValue > 0)
              cellValue = cellValue.toFixed(1);

          }
        
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      if(ingrPercents[iterator].innerHTML!=='')
	      {
		      ingrPercents[iterator].innerHTML = cellValue;
		      
              if(cellValue != ' N/A ')
                ingrPercents[iterator].innerHTML = ingrPercents[iterator].innerHTML +'%';
	      }
	      iterator++;
    	}
    }
    
    
    
    for(var i in ingrArray['otherIngredients'])
    {
    	var cellValue = roundN(ingrArray['otherIngredients'][i]['percent'],1);
        
        if(cellValue > 0)
	      cellValue = cellValue.toFixed(1);
          
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      if((ingrPercents[iterator]) && ingrPercents[iterator].innerHTML!=='')
	      {
		      ingrPercents[iterator].innerHTML = cellValue;
		      ingrPercents[iterator].innerHTML = ingrPercents[iterator].innerHTML +'%';
	      }
      iterator++;
    	if(ingrArray['otherIngredients'][i]['dependentIngredients']!==undefined)
    	for(var n in ingrArray['otherIngredients'][i]['dependentIngredients'])
    	{
	    	var cellValue = roundN(ingrArray['otherIngredients'][i]['dependentIngredients'][n]['percent'],1);
            
          if(cellValue > 0)  
	        cellValue = cellValue.toFixed(1);
            
	      //this.innerHTML = roundN(arrayIngredients[iteratorRefresh]['weight']*koef,2);
	      if(ingrPercents[iterator].innerHTML!=='')
	      {
		      ingrPercents[iterator].innerHTML = cellValue;
		      ingrPercents[iterator].innerHTML = ingrPercents[iterator].innerHTML +'%';
	      }
	      iterator++;
    	}
    }
  }
  
  
  function _getArrayIngredients(str)
  {
    var tmp = eval(str);
    ingrArray = new Array();
    ingrArray = tmp[0];
  	
  }
  
  function getArrayIngredients()
  {
    var arrayIngredientsName = new Array();
    var arrayIngredientsWeight = new Array();
    var arrayIngredientsUnit = new Array();
    var arrayIngredientsPercent = new Array();
    var ty = $(".nutrition_info_param_name");
    
    $("#containerIngredients .nutrition_info_param_name").each(
    function()
    {
      arrayIngredientsName.push(this.innerHTML);
    }
    );
    $("#containerIngredients .nutrition_info_param_value").each(
    function()
    {
      var str = this.innerHTML;
      var num = str.match(/\d+(\.\d+)?/);
      arrayIngredientsWeight.push(num['0']);
      var num = str.match(/[a-z A-Z]+/);
      arrayIngredientsUnit.push(num['0']);
    }
    );
    $("#containerIngredients .nutrition_info_percent_value").each(
    function()
    {
      var num = this.innerHTML.match(/\d+(\.\d+)?/);
      if (num!==null)
      arrayIngredientsPercent.push(num['0']);
    }
    );
    for(key in arrayIngredientsName)
    {
      arrayIngredients[key] = new Array();
      arrayIngredients[key]['foodComponent'] = arrayIngredientsName[key];
      arrayIngredients[key]['weight'] = arrayIngredientsWeight[key];
      arrayIngredients[key]['percent'] = arrayIngredientsPercent[key];
      arrayIngredients[key]['unit'] = arrayIngredientsUnit[key];
    }
    return arrayIngredients;
  }
  
  
  
  function pantryAnimate()
  {

    if (clonePantryButton!==undefined)
      clonePantryButton.
      
    remove();
       
     var originButtonPantry = $("#pantry_menu_link_id");
     var offsetCloneNode = new Array();
     offsetCloneNode.left = getLeft(originButtonPantry['0']);
     offsetCloneNode.top = getTop(originButtonPantry['0']);

      clonePantryButton = 
      $(".mainmenu_item:eq(3)")
        .clone();
      
      clonePantryButton.appendTo("body:first")
      
      .css( {top:offsetCloneNode.top,left:offsetCloneNode.left,backgroundColor:"#f1f4f8",position:"absolute",zIndex:200})
      
      //.css( {top:offsetCloneNode.top,left:offsetCloneNode.left,backgroundColor:"yellow",position:"absolute",zIndex:200})
      
      .animate( {opacity:"hide"}, 1500 );
      
      var offsetCloneNode = $(".mainmenu_item:eq(4)").offset();
  }
  
  function roundN(number,digit)
  {
      k = Math.pow(10,digit);
      number = number * k;
      number = Math.round(number);
      number = number/k;
      return number;
  }
  
	function fadeValueAndPercents()
	{
	var r = 241;
   var g = 244;
   var b = 248;
   var i=0;
   var currentColor = r.toString(16)+''+g.toString(16)+''+b.toString(16);
   
   
   //$(".nutrition_info_param_value").css( {backgroundColor:currentColor.toString(16)});
   //$(".nutrition_info_percent_value").css( {backgroundColor:currentColor.toString(16)});
   
   $(".nutrition_info_param_value").each(
   
     function(iIndex) {
       
       if($(this).text() != '') {
       
         $(this).css( {backgroundColor:currentColor.toString(16)});  
       
       }
       
     }
   )
   

   $(".nutrition_info_percent_value").each(
   
     function(iIndex) {
       
       if($(this).text() != '') {
       
         $(this).css( {backgroundColor:currentColor.toString(16)});  
       
       }
       
     }
   )
   
   $('#diagramm_protein_weight').css( {backgroundColor:currentColor.toString(16)});  
   $('#diagramm_fat_weight').css( {backgroundColor:currentColor.toString(16)});  
   $('#diagramm_carb_weight').css( {backgroundColor:currentColor.toString(16)});  

   	
   	var stAr = new Array(241,244,248);
   	var edAr = new Array(255,255,255);
   	 var t = setInterval(
   	   function()
   	   {
   	   	 var curColor = getCurrentColor(stAr,edAr,i++,15);
   	   	 
	   	   //$(".nutrition_info_param_value").css( {backgroundColor:curColor});
   			 
   	   	   //$(".nutrition_info_percent_value").css( {backgroundColor:curColor});
           
           $(".nutrition_info_param_value").each(
           
             function(iIndex) {
               
               if($(this).text() != '') {
               
                 $(this).css( {backgroundColor:curColor});  
               
               }
               
             }
           )
           

           $(".nutrition_info_percent_value").each(
           
             function(iIndex) {
               
               if($(this).text() != '') {
               
                 $(this).css( {backgroundColor:curColor});  
               
               }
               
             }
           )
           
           $('#diagramm_protein_weight').css( {backgroundColor:curColor});  
           $('#diagramm_fat_weight').css( {backgroundColor:curColor});  
           $('#diagramm_carb_weight').css( {backgroundColor:curColor});  
           
           
           
   	   	 if(i==14) 
   	   	 {
   	   	 
			   //$(".nutrition_info_param_value").css( {backgroundColor:'fff'});
			   
			   //$(".nutrition_info_percent_value").css( {backgroundColor:'fff'});
               
           $(".nutrition_info_param_value").each(
           
             function(iIndex) {
               
               if($(this).text() != '') {
               
                 $(this).css( {backgroundColor:'fff'});  
               
               }
               
             }
           )
           

           $(".nutrition_info_percent_value").each(
           
             function(iIndex) {
               
               if($(this).text() != '') {
               
                 $(this).css( {backgroundColor:'fff'});  
               
               }
               
             }
           )
           
           $('#diagramm_protein_weight').css( {backgroundColor:'fff'});  
           $('#diagramm_fat_weight').css( {backgroundColor:'fff'});  
           $('#diagramm_carb_weight').css( {backgroundColor:'fff'});  
               
               
               
               
   	   	 	clearInterval(t);
   	   	 }
   	   }
   	   ,50);  
	}
	
	
	function getCurrentColor(rgbStart,rgdEnd,stepNumber,stepAmount)
	{

	   var r = rgbStart[0];
	   var g = rgbStart[1];
	   var b = rgbStart[2];
	   var newr=0;
	   var newg=0;
	   var newb=0;
	   
	   var currentColor = r.toString(16)+''+g.toString(16)+''+b.toString(16);
	   var rStep = Math.round((255-r)/stepAmount);
	   var gStep = Math.round((255-g)/stepAmount);
	   var bStep = Math.round((255-b)/stepAmount);
	   newr=r+rStep*(stepNumber+1);
	   if(newr<=255)
	   		 r=newr;else r=255;
	   newg=g+gStep*(stepNumber+1);
	   if(newg<=255)
	   		 g=newg; else g=255;
	   newb=b+bStep*(stepNumber+1);
	   if(newb<=255)
	   		 b=newb; else b=255;
	   		var currentColor = r.toString(16)+''+g.toString(16)+''+b.toString(16);
	   		return currentColor;
	   //document.write(currentColor+'<br>');
	}