<?php include_once($_SERVER['DOCUMENT_ROOT'] . '/admin/inc/lunchSpecialsConfig.php'); ?>

<?php
	$lunchID = isset($lunchID) ? $lunchID : false;
?>

<div id="dailyLunch">
	<h4 class="header"><?php echo $lunchConfig['branded']; ?></h4>
    <div id="lunchOffset">
	</div>
</div>
<script src="/admin/js/includeJS.js"></script>
<script>
    var deliItems = new Array();
    var deliDropdown = "";
    
	lunchID = <?php echo $lunchID === false ? "false" : $lunchID; ?>;
	
	var config = <?php echo json_encode($lunchConfig); ?>;
	delete config['branded'];
	
    function getDailyLunch(){
	  var today = new moment();
      var theDate = today.format("YYYY-MM-DD");
	  var idCode = "";
	  if (lunchID !== "false") {
		idCode = "&deliType=" + lunchID;
	  }
      
      $.ajax({
	    type: "POST",
	    url: "/admin/lookUp.php",
	    data: "action=getLunchDay&date=" + theDate + idCode,
	    dataType: "json",
	    success: function(theResponse){
		  var theHTML = "";
		  var localConfig = jQuery.extend(true, {}, config);
		  
		  if(theResponse != false){
			
			$.each(theResponse, function(){
				localConfig[this['deli_type']]["has-special"] = true;
				localConfig[this['deli_type']]['item'] = this;
			
				var type = localConfig[this['deli_type']];
			  
				deliID = this.deli_id;
				theHTML += "<div class='aLunch clearfix'>";
				theHTML += "<h4 class='typeHeading'>" + type['common-uc'] + " Special</h4>";
				theHTML += "<img src='/" + deliItems[deliID]['photo'] + "' width='50%' class='specialItemPic' alt='" + type['common-uc'] + "'>";
				theHTML += "<h5>" + deliItems[deliID]['name'] + "</h5>";
				if(this.item_price != "$."){
					theHTML += "<h5 class='clearfix'>" + this.item_price + "</h5>";
				}
				theHTML += "</div>";
			});
		  }else{
			theHTML += getCommonSpecial('aLunch', "50%", localConfig[1]['common-name']);
		  }
		  
		  if(theResponse.length > 1){
			theHTML += "<p><a class='btn' href='lunchSpecials#weeklyLunch'>See this week's lunch specials</a></p>";
		  }else{
			theHTML += "<p><a class='btn' href='lunchSpecials#weeklyLunch'>See this week's specials</a></p>";
		  }
          
          
		  $("#lunchOffset").append(theHTML);
		  
		  //$("#viewLunch").attr("rel", theDate);
	    }
      });
    }
	
    getLunchOptions();
	
    
    
	$(document).ready(function() {
      // JavaScript placed here will run only once Kickstrap has loaded successfully.
      getDailyLunch();
      
   });
	
</script>

