function initVIP() {
  
  $('#vipsubmit').click(function() {
    var vipemail = $('#vipemail').val();
    var dataString = 'newsletter=' + vipemail;
    $.ajax({
      type:"POST",
      url:"vip.php",
      data:dataString,
      success:function() {
              $.fancybox({
          'content' : '<div style="width:400px;height:100px;overflow:auto; color:#000;">Thank you for joining the sweetgreen VIP group! We really hate annoying spam emails as much as you do, which is why we promise to only occasionally (think once a month here) send you some sweetgreen love, email style. This means invites to VIP only events, special deals and offers, and other pretty top secret info. Take care and talk to you soon!</div>'
        });

        $('#vipemailform').html("Thank You");
      }
    });
    return false; 
  });
}

function initializeMap() {
  if (GBrowserIsCompatible()) {
    locations = new Array();
    markers = new Array();
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng( 38.902222, -77.025061), 12);
    map.addControl(new GMapTypeControl());
    geocoder = new GClientGeocoder();
    map.setUIToDefault();
    
    geocoder.getLocations("3333 M St. NW, Washington, DC 20007", addAddress);
    geocoder.getLocations("1512 Connecticut Ave., Washington, DC 20036", addAddress);
    geocoder.getLocations("4831 Bethesda Ave., Bethesda, MD 20814", addAddress);
    geocoder.getLocations("1471 P St NW, Washington, DC 20005", addAddress);
    geocoder.getLocations("221 Pennsylvania Ave SE, Washington, DC 20003", addAddress);
    geocoder.getLocations("11935 Democracy Drive, Reston, VA 20190", addAddress);
	geocoder.getLocations("4075 Wilson Blvd., Arlington, VA 22203", addAddress);
	geocoder.getLocations("68 Coulter Ave., Ardmore, PA 19003", addAddress);
	geocoder.getLocations("3925 Walnut St., Philadelphia, PA 19104", addAddress);
	geocoder.getLocations("2221 Eye Street NW, Washington, DC 20052", addAddress);
	geocoder.getLocations("8300 Baltimore Ave., College Park, MD 20740", addAddress);
	
  }
  
  $('#georgetown').click(function(event) {
    map.panTo(locations[0]);
    markers[0].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Georgetown</strong><br />" + "3333 M St. NW,<br /> Washington, DC 20007" + "<br />202-337-9338</div>");
  });
  $('#dupont').click(function(event) {
    map.panTo(locations[1]);
    markers[1].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Dupont</strong><br />" + "1512 Connecticut Ave. NW,<br /> Washington, DC 20036" + "<br />202-387-9338</div>");
  });
  
  $('#bethesda').click(function(event) {
    map.panTo(locations[2]);
    markers[2].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Bethesda</strong><br />" + "4831 Bethesda Ave.,<br /> Bethesda, MD 20814" + "<br />301-654-7336</div>");
  });
  
  $('#College_Park').click(function(event) {
    map.panTo(locations[11]);
    markers[11].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - College Park</strong><br />" + "8300 Baltimore Ave.,<br /> College Park, MD 20740" + "<br />240-770-4443</div>");
  });
  
  $('#logan').click(function(event) {
    map.panTo(locations[4]);
    markers[4].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Logan Circle</strong><br />" + "1471 P St. NW,<br /> Washington, DC 20005" + "<br />202-234-7336</div>");
  }); 
    
      $('#caphill').click(function(event) {
    map.panTo(locations[5]);
    markers[5].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Capitol Hill</strong><br />" + "221 Pennsylvania Ave. SE,<br /> Washington, DC 20003" + "<br />202-547-9338</div>");
  });


$('#reston').click(function(event) {
    map.panTo(locations[6]);
    markers[6].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Reston</strong><br />" + "11935 Democracy Drive,<br /> Reston, VA 20190" + "<br />571-203-0082</div>");
  });

$('#ballston').click(function(event) {
    map.panTo(locations[7]);
    markers[7].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Ballston</strong><br />" + "4075 Wilson Blvd.,<br /> Arlington, VA 22203" + "<br />703-522-2016</div>");
  });

$('#ardmore').click(function(event) {
    map.panTo(locations[8]);
    markers[8].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Ardmore</strong><br />" + "68 Coulter Ave.,<br /> Ardmore, PA 19003" + "<br />610-642-9400</div>");
  });

$('#upenn').click(function(event) {
    map.panTo(locations[9]);
    markers[9].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - UPenn</strong><br />" + "3925 Walnut St.,<br /> Philadelphia, PA 19104" + "<br />215-386-1365</div>");
  });

  $('#foggybottom').click(function(event) {
    map.panTo(locations[10]);
    markers[10].openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Foggy Bottom</strong><br />" + "2221 Eye Street NW,<br /> Washington, DC 20052" + "<br />202-507-8357</div>");
  });

}

 

function addAddress(response) {
  if (!response || response.Status.code != 200) {
  }
  else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
    var marker = new GMarker(point, {title:response.name});
    var idx = 0;
    switch(response.name){
      case '3333 M St. NW, Washington, DC 20007':
        idx = 0;
      break;
      case '1512 Connecticut Ave., Washington, DC 20036':
        idx = 1;
      break;
      case '4831 Bethesda Ave., Bethesda, MD 20814':
        idx = 2;
      break;
	  
	  case '8300 Baltimore Ave., College Park, MD 20740':
        idx = 11;
		
		 
      break;
	  
	 
      case '1471 P St NW, Washington, DC 20005':
        idx = 4;
      break;
      case '221 Pennsylvania Ave SE, Washington, DC 20003':
        idx = 5;
      break;
	  case '11935 Democracy Drive, Reston, VA 20190':
        idx = 6;
		break;
	  case '4075 Wilson Blvd., Arlington, VA 22203':
        idx = 7;
      break;
	  case '68 Coulter Ave., Ardmore, PA 19003':
        idx = 8;
      break;
	  case '3925 Walnut St., Philadelphia, PA 19104':
        idx = 9;
      break;
	  
	    case '2221 Eye Street NW, Washington, DC 20052':
        idx = 10;
		
		 
      break;
    }
    marker.mid = markers.length;
    locations[idx] = point;
/*    locations.push(point);*/
    markers[idx] = marker;
/*    markers.push(marker);*/
    map.addOverlay(marker);
    if (response.name == "3333 M St. NW, Washington, DC 20007") {
      marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Georgetown</strong><br />" + "3333 M St. NW,<br /> Washington, DC 20007" + "<br />202-337-9338</div>");   
    }
    GEvent.addListener(marker, "click", function() {
      //marker.showMapBlowup();
      if (marker.getTitle() == "3333 M St. NW, Washington, DC 20007") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Georgetown</strong><br />" + "3333 M St. NW,<br /> Washington, DC 20007" + "<br />202-337-9338</div>");
      }
      else if (marker.getTitle() == "1512 Connecticut Ave., Washington, DC 20036") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Dupont</strong><br />" + "1512 Connecticut Ave. NW,<br /> Washington, DC 20036" + "<br />202-387-9338</div>");
        
      }
      else if (marker.getTitle() == "4831 Bethesda Ave., Bethesda, MD 20814") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Bethesda</strong><br />" + "4831 Bethesda Ave.,<br /> Bethesda, MD 20814" + "<br />301-654-7336</div>");        
      }
	  
	  else if (marker.getTitle() == "8300 Baltimore Ave., College Park, MD 20740") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - College Park</strong><br />" + "8300 Baltimore Ave.,<br /> College Park, MD 20740" + "<br />240-770-4443</div>");        
      }
	  
	
	  
      else if (marker.getTitle() == "1471 P St NW, Washington, DC 20005") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Logan Circle</strong><br />" + "1471 P St. NW,<br /> Washington, DC 20005" + "<br />202-234-7336</div>");
                
      } 
            else if (marker.getTitle() == "221 Pennsylvania Ave SE, Washington, DC 20003") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Capitol Hill</strong><br />" + "221 Pennsylvania Ave. SE,<br /> Washington, DC 20003" + "<br />202-547-9338</div>");
      }  
	  
	  else if (marker.getTitle() == "11935 Democracy Drive, Reston, VA 20190") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Reston</strong><br />" + "11935 Democracy Drive,<br /> Reston, VA 20190" + "<br />202-547-9338</div>");
      }   
	  
	  	  else if (marker.getTitle() == "4075 Wilson Blvd., Arlington, VA 22203") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Ballston</strong><br />" + "4075 Wilson Blvd.,<br /> Arlington, VA 22203" + "<br />202-547-9338</div>");
      }  
	  
	  	  else if (marker.getTitle() == "68 Coulter Ave., Ardmore, PA 19003") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Ardmore</strong><br />" + "68 Coulter Ave.,<br /> Ardmore, PA 19003" + "<br />610-642-9400</div>");
      }  
	  
	   else if (marker.getTitle() == "3925 Walnut St., Philadelphia, PA 19104") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - UPenn</strong><br />" + "3925 Walnut St.,<br /> Philadelphia, PA 19104" + "<br />215-386-1365</div>");
      }  
	  
	  
	   else if (marker.getTitle() == "2221 Eye Street NW, Washington, DC 20052") {
        marker.openInfoWindowHtml("<div style=\"width:200px; color:#000000; font-size:11px; font-family:Arial, sans-serif;\"><strong>Sweetgreen - Foggy Bottom</strong><br />" + "2221 Eye Street NW,<br /> Washington, DC 20052" + "<br />202-507-8357</div>");
      }  
	  
    });   
  }
}






function getHomeFeature() {
  $.getJSON('home.json', function(data) {
    var homepics = data.images;
    //var randnum = Math.floor(Math.random() * homepics.length);
/*    var injection = "";
    for (i=0; i < homepics.length; i++) {
      injection += "<a href=\""+ homepics[i].link + "\"><img border=\"0\" alt=\"" + homepics[i].alt + "\" src=\"images/home/features/" + homepics[i].image + "\" /></a>"
    }*/
    //$('#home_feature').html("<a href=\""+ homepics[randnum].link + "\"><img border=\"0\" alt=\"" + homepics[randnum].alt + "\" src=\"images/home/features/" + homepics[randnum].image + "\" /></a>");
    
  });
}

      
function populateMix() {
  green = "";
  veggies = new Array();
  crunchy = "";
  protein = "";
  cheese = "";
  dressing = "";
  $.getJSON('salad.json', parseMix);
}

function parseMix(data) {
  groups = data.saladGroups;
  for (i = 0; i < groups.length; i++) {
    
    var groupId = "#s" + groups[i].id;
    var items = groups[i].items;
    
    for (j=0;j<items.length;j++) {
      var itemId = i + "-" + j;
      var newMenuItem = "<div class=\"mixItem\" ><a id=\"" + itemId + "\" class=\"mixItemLink\" href=\"#\" >" + items[j].title + "</a></div>";
      $(groupId).append(newMenuItem);
    }
    
  }
//  $(".mixItemLink").mouseover(showBubble); 
//  $(".mixItemLink").mouseout(function(event) { $(".mixBubble").hide(); });
//  $(".mixItemLink").click(addToOrder);
}

function getItem(qid) {
  var ids = qid.split("-");
  return(groups[ids[0]].items[ids[1]]);
}




function showBubble(event) {
  var item = getItem($(this).attr("id"));
  if (item.image != "") {
    var imagePath = "../images/menu/mixyourown/" + item.image;
    var xpos = $(this).offset().left + 100;
    var ypos = $(this).offset().top - 50;
    $(".mixBubble").css({'left':xpos, 'top':ypos});
    //$(".mixBubble").offset({left:$(this).offset().left + 100, top:$(this).offset().top- 50} );
    $("#bubblePic").html('<img src="' + imagePath + '" border="0" />');
    $(".mixBubble").show();
  }
}



function addToOrder(event) {
  var item = getItem($(this).attr("id"));
  var ids = ($(this).attr("id")).split("-");
    
  $(this).addClass('mixItemSelect');
  
  switch(ids[0]) {
    case '0':
      if (green != "") {
        $("#" + green).removeClass('mixItemSelect');
      }
      green = $(this).attr("id");
      break;
    case '1':
      if (veggies.length == 3) {
        var pop = veggies.shift();
        $("#" + pop).removeClass('mixItemSelect');
      }
      veggies.push($(this).attr("id"));
      break;      
    case '2':
      if (crunchy != "") {
        $("#" + crunchy).removeClass('mixItemSelect');
      }
      crunchy = $(this).attr("id");
      break;
    case '3':
      if (cheese != "") {
        $("#" + cheese).removeClass('mixItemSelect');
      }
      cheese = $(this).attr("id");
      break;
    case '4':
      if (protein != "") {
        $("#" + protein).removeClass('mixItemSelect');
      }
      protein = $(this).attr("id");
      break;
    case '5':
      if (dressing != "") {
        $("#" + dressing).removeClass('mixItemSelect');
      }
      dressing = $(this).attr("id");
      break;
  }
  updateOrder();
}

function updateOrder() {
/*  var total = 6; // base price
  if (green != "") {
    var greenItem = getItem(green);
    $('#d1list').html(greenItem.title);
    total += greenItem.price;
  }
  if (crunchy != "") {
    var crunchyItem = getItem(crunchy);
    $('#d3list').html(crunchyItem.title);
    total += crunchyItem.price;
  }
  if (cheese != "") {
    var cheeseItem = getItem(cheese);
    $('#d4list').html(cheeseItem.title);
    total += cheeseItem.price;
  }
  if (protein != "") {
    var proteinItem = getItem(protein);
    $('#d5list').html(proteinItem.title);
    total += proteinItem.price;
  }
  if (dressing != "") { 
    var dressingItem = getItem(dressing);
    $('#d6list').html(dressingItem.title);
    total += dressingItem.price;
  }
  if (veggies.length > 0) {
    var veggieList = "";
    for (a=0; a < veggies.length; a++) {
      var veggieItem = getItem(veggies[a]);
      veggieList = veggieList + veggieItem.title + "<br />";
      total+= veggieItem.price;
    }
    $('#d2list').html(veggieList);
    
  }
  $('#dtotal').html("$" + total.toFixed(2));*/
}
