$(document).ready(function(){
	
	// execute function when page loads
	window.onload=function(){
		if(document.getElementsByTagName){
			loadmaps();
     	}
}

//Core Mapping Loader
function loadmaps(){
    // get all <div> elements in the document
    divs=document.getElementsByTagName('div');
    // iterate over all <div> elements in the document
    for(var i=0;i<divs.length;i++){
    // make collection with <div> elements with class attribute 'googlemap'
    var clsname=divs[i].className;
        if (clsname != '') {
        var pos=clsname.indexOf('googlemap');
        //Check to see if the googlemap class is in the class name
            if (pos>=0) {
                if (GBrowserIsCompatible()) {
                    //Collect the current DIV
                    var div = divs[i];
                    //Check to see if this is driving directions
                    if (div.getAttribute("toaddress") != null && div.getAttribute("fromaddress") != null) { 
                        if (document.getElementById(div.getAttribute("directions")) == null) {
                            div.innerHTML = "<span style='color : red;'>Error: </span> Directions container is not specified!"
                         } else {
                            loaddrivingdirections(div, document.getElementById(div.getAttribute("directions")));
                        }
                    } else { 
                        //Load Address or Longitude and Latitude
                        loadaddress(div);
                    }
                }
            }
        }
    }
}

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = "https://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

function createMarker(point, index, title, url, html) {
	// Create a lettered icon for this point using our icon class
	var number = index;
	var numberIcon = new GIcon(baseIcon);

	if (index == 9 || index == 10)
	{
		var locations_html = '<div class="mapItem" style="height:140px;">';
	}
	else
	{
		var locations_html = '<div class="mapItem">';
	}
	locations_html += '<div class="label">'+index+'</div><a href="'+url+'" target="_blank"><h3>'+title+'</h3></a>'+html+'</div>';
	
	numberIcon.image = "https://www.habitburger.com/markers/marker" + number + ".png";

	// Set up our GMarkerOptions object
	markerOptions = { icon:numberIcon };
	var marker = new GMarker(point, markerOptions);

	GEvent.addListener(marker, "click", function() {
		window.open(url)
	});
	
    $("#storeMain").append(locations_html);
	
	return marker;
}

function loaddrivingdirections(div,route) {
  var map = new GMap2(div);
  addmapcontrols(div,map);
  var directionsPanel = route;
  var directions = new GDirections(map, directionsPanel);
  directions.load("from: " + div.getAttribute("fromaddress") + " to: " + div.getAttribute("toaddress"));
}

function loadaddress(div) {
	// Los Angeles

	// Orange County

	// Sacramento

	// Santa Barbara

	// Ventura

	// Central Valley

	// Nor Cal

	// San Bern

	// San Diego

	// Arizona

	var innerHTML = div.innerHTML;
	var map = new GMap2(div);
	addmapcontrols(div,map);
	var habitLocations = new Array();
	var mapidx = 1;
    
    if (div.getAttribute("address") == "los-angeles-county" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(34.149557,-118.245907), 9);
		
		habitLocations[mapidx++] = new Array (new GLatLng(34.14702,-118.761068), '29145 Canwood Street, Suite A-1<br>Agoura Hills, CA 91301', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=29145+Canwood+Street,+Suite+A-1.+Agoura+Hills,+CA+91301&sll=37.0625,-95.677068&sspn=47.033113,71.806641&ie=UTF8&hq=&hnear=29145+Canwood+St,+Agoura+Hills,+Los+Angeles,+California+91301&t=h&z=16&iwloc=A', '<span class="phone">(818) 707-7300</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.1733412, -118.3009755), '103 East Alameda Ave.<br>Burbank, CA 91502', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=103+East+Alameda+Ave.,+Burbank,+CA+91502&sll=37.0625,-95.677068&sspn=54.753001,86.660156&ie=UTF8&hq=&hnear=103+E+Alameda+Ave,+Burbank,+Los+Angeles,+California+91502&z=17&iwloc=A', '<span class="phone">(818) 260-0083</span><br /><span class="hours">Mon-Sat: 10:30am-10pm <br /> Sun: 11am-9pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.238476,-118.571065), '9243 Winnetka Ave.<br>Chatsworth, CA 91311', 'http://maps.google.com/places/us/los-angeles/winnetka-ave/9243/-habit-restaurant-inc', '<span class="phone">(818) 773-0257</span><br /><span class="hours">Mon-Thur: 10:30am-9pm <br>Fri-Sat: 10:30am-10pm <br/>Sun:11am-8pm</span>');



		habitLocations[mapidx++] = new Array (new GLatLng(34.150106 ,-118.072421), '3733 E. Foothill Blvd.<br>East Pasadena, CA 91107', 'http://maps.google.com/maps?rlz=1T4ACGW_en___US427&q=3733+E.+Foothill+Blvd.+East+Pasadena,+CA+91107&um=1&ie=UTF-8&hq=&hnear=0x80c2db7deabe4e99:0x8376fb781f5706c1,3733+E+Foothill+Blvd,+East+Pasadena,+CA+91107&gl=us&ei=c87LTvCwJPCNsAKyz6nxDg&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CCAQ8gEwAA', '<span class="phone">(626) 351-1122</span><br /><span class="hours">Mon-Sat: 10:30am-10pm <br>Sun:11am-9pm</span>');

		habitLocations[mapidx++] = new Array (new GLatLng(33.919988,-118.396497), '311 N. Sepulveda Blvd.<br>El Segundo, CA  90245', 'http://maps.google.com/places/us/el-segundo/n-sepulveda-blvd/311/-habit-restaurant', '<span class="phone">(310) 524-9016</span><br /><span class="hours">Mon-Sat: 10:30am-10pm Sun:11am-9pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.160356,-118.506422), '17132 Ventura Blvd.<br>Encino, CA  91316', 'http://maps.google.com/places/us/los-angeles/ventura-blvd/17132/-habit', '<span class="phone">(818) 783-6162</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.149557,-118.245907), '249  Glendale Ave.<br>Glendale, CA  91206', 'http://maps.google.com/places/us/glendale/n-glendale-ave/249/-habit-burger-grill', '<span class="phone">(818) 246-6095</span><br /><span class="hours">Mon-Sat: 10:30am-10pm Sun:11am-9pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.115859,-117.772917), '1608 Foothill Blvd.<br>La Verne, CA  91750', 'http://maps.google.com/maps/place?cid=9004420963638513375&q=1608%2BFoothill%2BBlvd.%2BLa%2BVerne,%2BCA%2B%2B91750', '<span class="phone">(909) 593-1640</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		
		
		habitLocations[mapidx++] = new Array (new GLatLng(34.157145,-118.369955), '4770 Lankershim Blvd.<br>North Hollywood, CA  91602', 'http://maps.google.com/maps/place?q=4770%2BLankershim%2BBlvd.%2BNorth%2BHollywood,%2BCA%2B%2B91602', '<span class="phone">(818) 762-1995</span><br><span class="hours">Mon-Sat: 10:30am-10pm<br>Sun: 11am-9pm</span>'); 
		
		
		habitLocations[mapidx++] = new Array (new GLatLng(34.2378,-118.53655), '9215 Reseda Blvd.<br>Northridge, CA  91324', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=9215+Reseda+Blvd.+Northridge,+CA++91324&ie=UTF8&hq=&hnear=9215+Reseda+Blvd,+Northridge,+Los+Angeles,+California+91324&ll=34.238326,-118.536547&spn=0.007823,0.010096&z=17&iwloc=A', '<span class="phone">(818) 993-7113</span><br /><span class="hours" >Drive Thru: Mon-Thur:10:30-11pm Fri-Sat:10:30am-12am Sun:11am-10pm </span><span style="font-size:11px;">(Dining room closes one hour prior to drive thru)</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(33.918759,-118.073452), '12401 South Norwalk Blvd. Norwalk, CA  90650', 'http://maps.google.com/places/us/norwalk/norwalk-blvd/12401/-habit-burger-grill', '<span class="phone">(562) 863-3061</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.397348,-118.491256), '19223 Golden Valley Rd.<br>Santa Clarita, CA  91387', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&q=Golden+Valley+Rd,+Newhall,+Los+Angeles,+California&ie=UTF8&cd=2&geocode=FTSTDQIdYxLw-A&split=0&sll=34.395473,-118.479777&sspn=0.006458,0.014728&hq=&hnear=Golden+Valley+Rd,+Santa+Clarita,+Los+Angeles,+California&z=14&iwloc=A', '<span class="phone">(661) 252-1487</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.151289,-118.452272), '14622 Ventura Blvd.<br>Sherman Oaks, CA  91403', 'http://maps.google.com/places/us/sherman-oaks/ventura-blvd/14622/-habit-burger-grill', '<span class="phone">(818) 386-0995</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');  
		habitLocations[mapidx++] = new Array (new GLatLng(33.837594,-118.35414), '3829 Torrance Blvd.<br>Torrance, CA  90503', 'http://maps.google.com/places/us/torrance/w-torrance-blvd/3829/-habit-restaurant-casual-dining', '<span class="phone">(310) 406-3063</span><br /><span class="hours">Mon-Thur: 10:30am-9:30pm <br /> Fri-Sat:10:30am-10pm<br>Sun: 11am-9pm </span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.407811,-118.55572), '25948 McBean Pkwy.<br>Valencia, CA  91355', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=25948+McBean+Pkwy.+Valencia,+CA++91355&ie=UTF8&hq=&hnear=McBean+Pkwy,+Santa+Clarita,+Los+Angeles,+California+91355&ll=34.40588,-118.555394&spn=0.031229,0.040383&z=15&iwloc=A', '<span class="phone">(661) 291-1575</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.443124,-118.606075), '28251 Newhall Ranch Rd.<br>Valencia, CA  91355', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=28251+Newhall+Ranch+Rd.++Valencia,+CA++91355&sll=34.40588,-118.555394&sspn=0.031229,0.040383&ie=UTF8&hq=&hnear=Newhall+Ranch+Rd,+Santa+Clarita,+Los+Angeles,+California+91355&z=13&iwloc=A', '<span class="phone">(661) 294-1071</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.068621,-117.938953), '2851 Eastland Center Drive<br>West Covina, CA  91791', 'http://maps.google.com/maps?q=2851%2BEastland%2BCenter%2BDrive%2BWest+Covina,+CA&z=13', '<span class="phone">(626) 859-6666</span><br /><span class="hours">Mon-Sat: 10:30am-10pm <br /> Sun: 11am-9pm</span>');

		habitLocations[mapidx++] = new Array (new GLatLng(34.167043,-118.620154), '22651 Ventura Blvd.<br>Woodland Hills, CA  91364', 'http://maps.google.com/places/us/los-angeles/ventura-blvd/22651/-habit-restaurant', '<span class="phone">(818) 225-2231</span><br /><span class="hours">Mon-Sat: 10:30am-10pm <br /> Sun: 11am-9pm</span>');
		
        
    } 
    
    if (div.getAttribute("address") == "orange-county" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(33.774282,-117.867212), 10);

		habitLocations[mapidx++] = new Array (new GLatLng(33.570889,-117.722599), '26921 Aliso Creek Rd. #A<br>Aliso Viejo, CA 92656', 'http://maps.google.com/maps?hl=en&rlz=1T4ACGW_enUS460US427&q=26921+Aliso+Creek+Road.+%23A,+Aliso+Viejo,+CA+92656&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1270&bih=537&wrapid=tlif132327695100910&um=1&ie=UTF-8&hq=&hnear=0x80dcef4e39ad040b:0x2a2905e85d5037ad,26921+Aliso+Creek+Rd,+Aliso+Viejo,+CA+92656&gl=us&ei=oprfTqyiLIX9iQLeguXIDw&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CBwQ8gEwAA', '<span class="phone">(949) 831-3116</span><br /><span class="hours">Mon-Thur: 10:30am-9:30pm <br />Fri-Sat: 10:30am-10pm <br />Sun:11am-9pm</span>');

		habitLocations[mapidx++] = new Array (new GLatLng(33.867794 ,-117.743063), '8182 E. Santa Ana Canyon Rd. #199<br>Anaheim Hills, CA 92808', 'http://maps.google.com/maps?rlz=1T4ACGW_en___US427&q=8182+E.+Santa+Ana+Canyon+Rd.+%23199,+Anaheim+Hills,+CA+92808&um=1&ie=UTF-8&hq=&hnear=0x80dcd1d1dca17e53:0xe5d62d9a5d38a81b,8182+E+Santa+Ana+Canyon+Rd,+Anaheim,+CA+92808&gl=us&ei=rAqGTpHTKIHiiAKIvKCgDA&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CBoQ8gEwAA', '<span class="phone">(714) 998-8000</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');

		
		habitLocations[mapidx++] = new Array (new GLatLng(33.8780479, -117.8809417), '2720 Nutwood Ave, #A<br>Fullerton, CA 92831', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=2720+Nutwood+Ave,+%23A,+Fullerton,+CA+92831&sll=34.173341,-118.300976&sspn=0.007066,0.010579&ie=UTF8&hq=&hnear=2720+Nutwood+Ave,+Fullerton,+Orange,+California+92831&z=17&iwloc=A', '<span class="phone">(714) 871-9116</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(33.619255,-117.701989), '23632 El Toro Rd., #A<br>Lake Forest, 92630', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=23632+El+Toro+Rd.+Lake+Forest,+92630&sll=37.0625,-95.677068&sspn=49.357162,85.429688&ie=UTF8&hq=&hnear=23632+El+Toro+Rd,+Lake+Forest,+Orange,+California+92630&z=17&iwloc=A', '<span class="phone">(949) 206-9110</span><br /><span class="hours">Mon-Thur: 10:30am-9pm <br />Fri-Sat: 10:30am-10pm <br />Sun:11am-9pm</span>');


		habitLocations[mapidx++] = new Array (new GLatLng(33.774282,-117.867212), '2777 N. Main St.<br>Santa Ana, CA  92705', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=2777+N.+Main+St.+Santa+Ana,+CA++92705&ie=UTF8&hq=&hnear=2777+N+Main+St,+Santa+Ana,+Orange,+California+92705&ll=33.774804,-117.867208&spn=0.007866,0.010096&z=17&iwloc=A', '<span class="phone">(714) 550-1201</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');

 
        
    } 
    


    if (div.getAttribute("address") == "san-diego" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(33.17,-117.156649), 9);

		habitLocations[mapidx++] = new Array (new GLatLng(32.983123 ,-117.076126 ), '12002 Carmel Mountain Rd.<br>Carmel Mountain, CA 92128', 'http://maps.google.com/maps?hl=en&qscrl=1&nord=1&rlz=1T4ACGW_en___US427&q=12002+Carmel+Mountain+Rd.+92128&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1366&bih=613&ion=1&wrapid=tlif132197971314010&um=1&ie=UTF-8&hq=&hnear=0x80dbfa00f5d5c589:0xd2ce0926b39ac9c3,12002+Carmel+Mountain+Rd,+San+Diego,+CA+92128&gl=us&ei=Rc_LTpPBAYv4sQL_0bHXDg&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CBwQ8gEwAA', '<span class="phone">(858) 485-9991</span><br /><span class="hours">Mon-Thur: 10:30am-9:00pm <br />Fri-Sat: 10:30am-10pm <br />Sun:11am-9pm</span>');
		
		habitLocations[mapidx++] = new Array (new GLatLng(33.55541512646698 ,-117.14618682861328), 'Murrieta (Murrieta Plaza)', 'http://maps.google.com/maps?pq=%09%09,+murrieta+ca&hl=en&cp=14&gs_id=49&xhr=t&q=murrieta+plaza&rlz=1T4ACGW_enUS460US427&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1366&bih=613&wrapid=tljp1326243932268222&um=1&ie=UTF-8&hq=&hnear=0x80db7dde93c82377:0x176e508f2b89e4f7,Plaza,+Murrieta,+CA+92563&gl=us&ei=ceAMT9qOCIfZiAKI1JDrAw&sa=X&oi=geocode_result&ct=title&resnum=1&sqi=2&ved=0CCYQ8gEwAA', '<span class="phone">Coming soon</span><br /><span class="hours">Coming soon </span>');

		habitLocations[mapidx++] = new Array (new GLatLng(32.767376 ,-117.156649 ), '845 Camino De La Reina<br>San Diego, CA 92108', 'http://maps.google.com/maps?rlz=1T4ACGW_en___US427&q=845+Camino+de+la+Reina+San+Diego+CA+92108&um=1&ie=UTF-8&hq=&hnear=0x80d95524af8c6c01:0x3cfcd045c8bc0d6c,845+Camino+De+La+Reina,+San+Diego,+CA+92108&gl=us&ei=BM6dTrOSBIbRiALQ3rmMCg&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CBsQ8gEwAA', '<span class="phone">(619) 299-9913</span><br /><span class="hours">Mon-Thur: 10:30am-9:00pm <br />Fri-Sat: 10:30am-10pm <br />Sun:11am-9pm</span>');
	}
    
    if (div.getAttribute("address") == "sacramento" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(38.59278, -121.41546), 9);
		
		habitLocations[mapidx++] = new Array (new GLatLng(38.666098,-121.272262), '5437 Sunrise Blvd.<br>Citrus Heights, CA  95610', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=5437+Sunrise+Blvd.+Citrus+Heights,+CA++95610&ie=UTF8&hq=&hnear=5437+Sunrise+Blvd,+Citrus+Heights,+Sacramento,+California+95610&ll=38.666589,-121.272261&spn=0.007389,0.010096&z=17&iwloc=A', '<span class="phone">(916) 536-9175</span><br /><span class="hours">Mon-Thur: 10:30am-9pm<br>Fri-Sat: 10:30am-10pm<br>Sun:11am-9pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(38.541063,-121.740924), '500 1st Street<br>Davis, CA  95616', 'http://maps.google.com/places/us/davis/1st-st/500/-habit-burger-grill', '<span class="phone">(530) 757-7485</span><br /><span class="hours">Mon-Thur: 10:30am-9pm <br />Fri-Sat: 10:30am-9:30pm <br/>Sun: 11am-9:30pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(38.422344,-121.410666), '7400 Laguna Blvd.<br>Elk Grove, CA  95758', 'http://maps.google.com/places/us/elk-grove/laguna-blvd/7400/-habit-burger-grill', '<span class="phone">(916) 683-3551</span><br /><span class="hours">Mon-Thur: 10:30am-9pm <br />Fri-Sat: 10:30am-9:30pm<br>Sun:11am-9pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(38.742517,-121.225661), '4060 Douglas Blvd.<br>Granite Bay, CA  95746', 'http://maps.google.com/maps/place?cid=69927108015539497&q=4060%2BDouglas%2BBlvd.%2BGranite%2BBay,%2BCA%2B%2B95746', '<span class="phone">(916) 791-6790</span><br /><span class="hours">Mon-Sat: 10:30am-9pm Sun:11am-9pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(38.768713,-121.328232), '933 Pleasant Grove Blvd.<br>Roseville, CA  95678', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=933+Pleasant+Grove+Blvd.+Roseville,+CA++95678&ie=UTF8&hq=&hnear=Pleasant+Grove+Blvd,+Roseville,+Placer,+California+95678&ll=38.777607,-121.295671&spn=0.029508,0.040383&z=15&iwloc=A', '<span class="phone">(916) 791-5292</span><br /><span class="hours">Mon-Sat: 10:30am-9pm Sun:11am-9pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(38.59278,-121.41546), '1431 Howe Ave.<br>Sacramento, CA  95825', 'http://maps.google.com/maps/place?cid=6014813086890687660&q=Habit+Burger+1431+Howe+Ave.+Sacramento,+CA+95825&hl=en&cd=1&ei=ntSzS_m1Gp-CyQSYhtWjDQ&sig2=GD8Ehm-WyYIydl4UKL_83w&sll=38.60312,-121.506592&sspn=0.433843,0.562396&ie=UTF8&ll=38.9861,-122.173462&spn=0,0&z=10&iwloc=A', '<span class="phone">(916) 927-2604</span><br /><span class="hours">Mon-Thur: 10:30am-9pm<br>Fri-Sat: 10:30am-10pm<br>Sun:11am-9pm</span>');

    }  
    
    if (div.getAttribute("address") == "santa-barbara" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(34.419154, -119.676037), 10);
		
		habitLocations[mapidx++] = new Array (new GLatLng(34.435445,-119.824668), '5735 Hollister Ave.<br>Goleta, CA  93117', 'http://maps.google.com/maps/place?cid=10602435749234936419&q=5735%2BHollister%2BAve.%2BGoleta,%2BCA%2B93117', '<span class="phone">(805) 964-0366</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.419154,-119.676037), '216 S. Milpas<br>Santa Barbara, CA  93103', 'http://maps.google.com/places/us/santa-barbara/s-milpas-st/216/-habit', '<span class="phone">(805) 962-7472</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.418598,-119.697405), '628 State St.<br>Santa Barbara, CA  93101', 'http://maps.google.com/places/us/santa-barbara/state-st/628/-habit', '<span class="phone">(805) 892-5400</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); 
		habitLocations[mapidx++] = new Array (new GLatLng(34.438473,-119.749827), '3890 La Cumbre Plaza Ln.<br>Santa Barbara, CA  93105', 'http://maps.google.com/places/us/santa-barbara/la-cumbre-plaza-ln/3890/-habit', '<span class="phone">(805) 687-5200</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>'); //3890 La Cumbre
      	
        
    } 
    
    if (div.getAttribute("address") == "ventura-county" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(34.218453, -119.045163), 10);
		
		habitLocations[mapidx++] = new Array (new GLatLng(34.218453,-119.045163), '1855 Daily Dr.<br>Camarillo, CA  93010', 'http://maps.google.com/places/us/camarillo/e-daily-dr/1855/-habit-burger-grill', '<span class="phone">(805) 484-2950</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.192158,-118.937082), '1025 Broadbeck Ln.<br>Newbury Park, CA  91320', 'http://maps.google.com/places/us/thousand-oaks/broadbeck-dr/1025/-habit-restaurant-inc', '<span class="phone">(805) 375-9227</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.227654,-119.176222), '2350 Vineyard Dr.<br>Oxnard, CA  93030', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=2350+Vineyard+Dr.+Oxnard,+CA++93030&ie=UTF8&hq=&hnear=2350+E+Vineyard+Ave,+Oxnard,+Ventura,+California+93036&z=17&iwloc=A', '<span class="phone">(805) 981-9919</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.286912,-118.716771), '2906 Tapo Cyn. Blvd.<br>Simi Valley, CA  93065', 'http://maps.google.com/maps/place?cid=16801176467226815257&q=2906%2BTapo%2BCyn.%2BBlvd.%2BSimi%2BValley,%2BCA%2B%2B93065', '<span class="phone">(805) 527-4500</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.18112,-118.874739), '11 East Hillcrest Dr.<br>Thousand Oaks, CA  91360', 'http://maps.google.com/places/us/thousand-oaks/e-hillcrest-dr/11/-habit', '<span class="phone">(805) 494-1124</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.278494,-119.293426), '487 E. Thompson Blvd.<br>Ventura, CA  93001', 'http://maps.google.com/places/us/ventura/e-thompson-blvd/487/-habit', '<span class="phone">(805) 667-2065</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');
		habitLocations[mapidx++] = new Array (new GLatLng(34.263196,-119.227249), '4732 Telephone Rd.<br>Ventura, CA  93003', 'http://maps.google.com/places/us/ventura/w-telephone-rd/4732/-habit', '<span class="phone">(805) 676-1717</span><br /><span class="hours">Mon-Sat: 10:30am-9pm <br>Sun:11am-8pm</span>');

        
    } 
    
    if (div.getAttribute("address") == "central-california" || div.getAttribute("address") == "central-valley" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(36.01384,-119.554017), 8);
		
		habitLocations[mapidx++] = new Array (new GLatLng(36.8085092, -119.8045365), '702 West Shaw Ave.<br>Fresno, CA 93704', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=702+West+Shaw+Ave.,+Fresno,+CA+93704&sll=37.0625,-95.677068&sspn=54.753001,86.660156&ie=UTF8&hq=&hnear=702+W+Shaw+Ave,+Fresno,+California+93704&z=17&iwloc=A', '<span class="phone">(559) 226-2128</span><br /><span class="hours">Mon-Thur: 10:30am-9pm<br>Fri-Sat: 10:30am-9pm<br>Sun:11am-8pm</span>');
		
		habitLocations[mapidx++] = new Array (new GLatLng(36.365318,-119.314472), '604 S. Mooney Blvd.<br>Visalia, CA 93277', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Mooney+Boulevard,+Visalia,+CA&sll=36.365318,-119.314472&sspn=0.01175,0.017531&g=Visalia+Mooney+Blvd.&ie=UTF8&hq=&hnear=604+S+Mooney+Blvd,+Visalia,+Tulare,+California+93291&ll=36.365319,-119.314442&spn=0.093997,0.140247&t=h&z=13&iwloc=A', '<span class="phone">(559) 625-5700</span><br /><span class="hours">Drive Thru: Mon-Thur:10:30-11pm Fri-Sat:10:30am-12am Sun:11am-10pm </span><span style="font-size:11px;">(Dining room closes one hour prior to drive thru)</span>');
		
		habitLocations[mapidx++] = new Array (new GLatLng(35.280037,-120.662592), '839 Higuera Street<br>San Luis Obispo, CA 93401', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=839+Higuera+Street+San+Luis+Obispo,+CA+93401&aq=&sll=34.569906,-119.119263&sspn=1.922286,4.515381&ie=UTF8&hq=&hnear=839+Higuera+St,+San+Luis+Obispo,+California+93401&t=h&z=16&iwloc=A', '<span class="phone">(805) 542-0105</span><br /><span class="hours">Mon-Sat: 10:30am-10pm<br>Sun: 11am-9pm</span>');
   } 
   
   if (div.getAttribute("address") == "bay-area" || div.getAttribute("address") == "northern-cali" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(37.896043,-122.062929), 9);
		
		
		habitLocations[mapidx++] = new Array (new GLatLng(38.32078423408987,-122.30632781982422), 'Napa (Napa Crossing)', 'http://maps.google.com/maps?rlz=1T4ACGW_enUS460US427&q=1739+Trancas+St,+Napa,+CA&gs_upl=0l0l0l4090366lllllllllll0&um=1&ie=UTF-8&hq=&hnear=0x808506de4178707f:0x8c960716e39a8e50,1739+Trancas+St,+Napa,+CA+94558&gl=us&ei=CeAMT-GSE-HXiQL-1cTiAw&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CB4Q8gEwAA', '<span class="phone">Coming soon</span><br /><span class="hours">Coming soon </span>');

		habitLocations[mapidx++] = new Array (new GLatLng(37.656237212046236,-121.89794540405273), '6770 Bernal Avenue, Suite 410, S. Pleasanton, CA 94588', 'http://maps.google.com/maps/place?hl=en&georestrict=input_srcid:1d3eef0bedc344bc', '<span class="phone">(925) 485-3260</span><br /><span class="hours">Mon-Sat: 10:30am-10pm <br />Sun: 11am-9pm </span>');
		
		habitLocations[mapidx++] = new Array (new GLatLng(37.53460683245632,-122.30199337005615), 'San Mateo (Park Place)', 'http://maps.google.com/maps?hl=en&qscrl=1&nord=1&rlz=1T4ACGW_enUS460US427&q=san+mateo,+ca+94403&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1366&bih=613&ion=1&wrapid=tlif132624368487010&um=1&ie=UTF-8&hq=&hnear=0x808f9efd97202f51:0x7d145724bf74a0e0,San+Mateo,+CA+94403&gl=us&ei=bt8MT_C-M6LWiAKukI31Aw&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CCYQ8gEwAA', '<span class="phone">Coming soon</span><br /><span class="hours">Coming soon </span>');

		habitLocations[mapidx++] = new Array (new GLatLng(37.885453,-122.032602), '1255 S. California Blvd.<br>Walnut Creek, CA 94596', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=1255+S.+California+Blvd.+Walnut+Creek,+CA+94596', '<span class="phone">(925) 279-2286</span><br /><span class="hours">Mon-Sat: 10:30am-10pm <br />Sun: 11am-9pm </span>');
		

		
	} 
	
	if (div.getAttribute("address") == "san-bernardino" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(33.97528,-117.72306), 11);
		
		habitLocations[mapidx++] = new Array (new GLatLng(33.984204,-117.714428), '4200 Chino Hills Parkway #200<br>Chino Hills, CA 91709', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Chino+Hills,+CA&sll=37.0625,-95.677068&sspn=54.357317,66.357422&ie=UTF8&hq=&hnear=Chino+Hills,+San+Bernardino,+California&z=12&iwloc=A', '<span class="phone">(909) 597-3344</span><br /><span class="hours">Mon-Thur: 10:30am-9:30pm <br />Fri-Sat: 10:30am-10pm <br /> Sun:11am-8:30pm</span>');
		

    } 
    
    if (div.getAttribute("address") == "arizona" || div.getAttribute("address") == "locations") {
        map.setCenter(new GLatLng(33.325000, -111.936556), 9);
		
		
		habitLocations[mapidx++] = new Array (new GLatLng(33.318913,-111.969608), '960 N. 54th Street<br>Chandler, AZ 85226', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=960+N.+54th+Street+Chandler,+AZ+85226&aq=&sll=33.363749,-111.910394&sspn=0.007617,0.017638&ie=UTF8&hq=&hnear=960+N+54th+St,+Chandler,+Maricopa,+Arizona+85226&t=h&z=16&iwloc=A', '<span class="phone">480-705-0306</span><br /><span class="hours">Mon-Sat: 10:30am-9pm<br>Sun: 11am-8pm</span>');

		habitLocations[mapidx++] = new Array (new GLatLng(33.538348,-112.064315 ), '745 E. Glendale Ave.<br>Phoenix, AZ 85014', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=745+E.+Glendale+Ave+Phoenix,+AZ+85014', '<span class="phone">(602) 265-1815</span><br /><span class="hours">Mon-Thur: 10:30am-9pm<br>Fri-Sat: 10:30am-10pm<br>Sun: 11am-9pm</span>');

		habitLocations[mapidx++] = new Array (new GLatLng(33.363749,-111.910394), '1817 E. Guadalupe Road #102<br>South Tempe, AZ 85283', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=1817+E.+Guadalupe+Road+South+Tempe,+AZ+85283', '<span class="phone">(480) 456-8912</span><br /><span class="hours">Mon-Thur: 10:30am-9pm<br>Sun: 11am-8pm</span>');
		
		
    } 

	if (div.getAttribute("address") == "locations") {
		map.setCenter(new GLatLng(36.61512514748051,-118.141113281), 5);
    } 

        
    if (div.getAttribute("address") == "") {
    
        //Add the address with geocoding, passing in the target DIV
        geocodeaddress(div);
    }
	else
	{
		var len = habitLocations.length;
		
		for (var i = 1; i < len; i++) {
			var value = habitLocations[i][0];
			var title = habitLocations[i][1];
			var url = habitLocations[i][2];
			var html = habitLocations[i][3];
			map.addOverlay(createMarker(value, i, title, url, html));
		}
		
        // Add address information to marker
        if (innerHTML != "") {
            marker.openInfoWindowHtml(innerHTML);
        }
	
	}
}

function geocodeaddress(div) {
    // Create new geocoding object
    geocoder = new GClientGeocoder();

    // Retrieve location information, pass it to addToMap()
    geocoder.getLocations(div.getAttribute("address"), addToMap);
}

// This function adds the point to the map
function addToMap(response) {
    var div = findmapdiv(response.name);
    try
    {
        // Retrieve the object
        place = response.Placemark[0];
        //Capture the current HTML of the DIV
        var innerHTML = div.innerHTML;
        // Create new map object
        map = new GMap2(div);
        //Add map controls if applicable
        addmapcontrols(div,map);
        // Retrieve the latitude and longitude
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        // Center the map on this point
        map.setCenter(point, getzooomlevel(div));
		// Double click zoom
		map.enableDoubleClickZoom();
        // Create a marker
        marker = new GMarker(point);
        // Add the marker to map
        map.addOverlay(marker);
        //If we have HTML fill it in the window.
        if (innerHTML != "") {
            marker.openInfoWindowHtml(innerHTML);
        } 
    }
    catch(err)
    {
        //Handle errors here
        div.innerHTML = "<span style='color : red;'>Error: </span><b>" + response.name + "</b> was not found, please adjust address."
    }  
}

//Helper Functions
function findmapdiv(address) {
// get all <div> elements in the document
divs=document.getElementsByTagName('div');
// iterate over all <div> elements in the document
    for(var i=0;i<divs.length;i++){
    // make collection with <div> elements with class attribute 'googlemap'
        var clsname=divs[i].className;
        if (clsname != '') {
        var pos=clsname.indexOf('googlemap');
        //Check to see if the googlemap class is in the class name
            if (pos>=0) {
                if (GBrowserIsCompatible()) {
                    if (divs[i].getAttribute("address") == address) {
                        return divs[i];
                    }
                }
            }
        }
    }
}

function addmapcontrols(div, map) {

    if (div.getAttribute("scale") == "yes") {
        map.addControl(new GScaleControl());
    }
    if (div.getAttribute("type") == "yes") {
        map.addControl(new GMapTypeControl());
    }
    if (div.getAttribute("pan") == "yes") {
        map.addControl(new GSmallMapControl());
    }
}

function getzooomlevel(div) {
    var zoom = parseInt(div.getAttribute("zoom"));
        if(isNaN(zoom)) { zoom = 13; } 
    return zoom;
}
    
});

