$(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 = "http://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);
	var locations_html = '<div class="mapItem"><div class="label">'+index+'</div><a href="'+url+'" target="_blank"><h3>'+title+'</h3></a>'+html+'</div>';
	
	numberIcon.image = "http://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) {
	if (div.getAttribute("address") == "locations") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(36.31512514748051,-119.641113281), 6);
		
		var habitLocations = new Array();
		// Los Angeles
		habitLocations[1] = new Array (new GLatLng(34.238476,-118.571065), '9243 Winnetka Ave. 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 &amp; Sat: 10:30am-10pm <br/>Sun:11am-9pm</span>');
		habitLocations[2] = new Array (new GLatLng(33.919988,-118.396497), '311 N. Sepulveda Blvd. 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-9pm Sun:11am-8pm</span>'); 
		habitLocations[3] = new Array (new GLatLng(34.160356,-118.506422), '17132 Ventura Blvd. 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 Sun:11am-8pm</span>');
		habitLocations[4] = new Array (new GLatLng(34.149557,-118.245907), '249  Glendale Ave. 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[5] = new Array (new GLatLng(34.115859,-117.772917), '1608 Foothill Blvd. 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 Sun:11am-8pm</span>'); 
		habitLocations[6] = new Array (new GLatLng(34.2378,-118.53655), '9215 Reseda Blvd. 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 &amp; Sat:10:30am-12am Sun:11am-10pm.<br />(Dining room closes one hour prior to drive thru)</span>');
		habitLocations[7] = 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 Sun:11am-8pm</span>');
		habitLocations[8] = new Array (new GLatLng(34.397348,-118.491256), '19223 Golden Valley Rd. 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 Sun:11am-8pm</span>'); 
		habitLocations[9] = new Array (new GLatLng(34.151289,-118.452272), '14622 Ventura Blvd. 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 Sun:11am-8pm</span>');  
		habitLocations[10] = new Array (new GLatLng(33.837594,-118.35414), '3829 Torrance Blvd. 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 &amp; Sun: 10:30am-9pm <br /> Fri &amp; Sat:10:30am-10pm</span>');
		habitLocations[11] = new Array (new GLatLng(34.407811,-118.55572), '25948 McBean Pkwy. 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 Sun:11am-8pm</span>'); 
		habitLocations[12] = new Array (new GLatLng(34.443124,-118.606075), '28251 Newhall Ranch Rd.  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 Sun:11am-8pm</span>');
		habitLocations[13] = new Array (new GLatLng(34.167043,-118.620154), '22651 Ventura Blvd. 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>');
		habitLocations[14] = new Array (new GLatLng(34.1733412, -118.3009755), '103 East Alameda Ave., 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-9pm <br /> Sun:11am-8pm</span>');
		habitLocations[15] = new Array (new GLatLng(34.136395,-118.774535), 'Agoura Hills in Oak Creek shopping center at 101 fwy and Kanan', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Agoura+Hills&sll=37.0625,-95.677068&sspn=51.089971,73.564453&ie=UTF8&hq=&hnear=Agoura+Hills,+Los+Angeles,+California&z=13&iwloc=A', '<span class="phone">N/A</span><br /><span class="hours">Coming Soon</span>');
		
		// Orange County
		habitLocations[16] = new Array (new GLatLng(33.8780479, -117.8809417), '2720 Nutwood Ave, #A, 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 Sun:11am-8pm</span>'); 
		habitLocations[17] = new Array (new GLatLng(33.774282,-117.867212), '2777 N. Main St. 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 Sun:11am-8pm</span>');
		habitLocations[18] = new Array (new GLatLng(33.619255,-117.701989), '23632 El Toro Rd., #A, 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-Sat: 10:30am-9pm Sun:11am-8pm</span>');
				
		// Sacramento
		habitLocations[19] = new Array (new GLatLng(38.666098,-121.272262), '5437 Sunrise Blvd. 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-Sat: 10:30am-10pm Sun:11am-9pm</span>');
		habitLocations[20] = new Array (new GLatLng(38.541063,-121.740924), '500 1st Street  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-9:30pm <br />Fri-Sat: 10:30am-10pm <br/>Sun: 10:30am-9pm</span>');
		habitLocations[21] = new Array (new GLatLng(38.422344,-121.410666), '7400 Laguna Blvd. 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-Sat: 10:30am-9pm Sun:11am-8pm</span>');
		habitLocations[22] = new Array (new GLatLng(38.742517,-121.225661), '4060 Douglas Blvd. 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-8pm</span>');
		habitLocations[23] = new Array (new GLatLng(38.768713,-121.328232), '933 Pleasant Grove Blvd. 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-8pm</span>');
		habitLocations[24] = new Array (new GLatLng(38.59278,-121.41546), '1431 Howe Ave. 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-Sat: 10:30am-9pm Sun:11am-8pm</span>');
		
		// Santa Barbara
		habitLocations[25] = new Array (new GLatLng(34.435445,-119.824668), '5735 Hollister Ave. 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 Sun:11am-8pm</span>'); 
		habitLocations[26] = new Array (new GLatLng(34.419154,-119.676037), '216 S. Milpas 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 Sun:11am-8pm</span>'); 
		habitLocations[27] = new Array (new GLatLng(34.418598,-119.697405), '628 State St. 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 Sun:11am-8pm</span>'); 
		habitLocations[28] = new Array (new GLatLng(34.438473,-119.749827), '3890 La Cumbre Plaza Ln. 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 Sun:11am-8pm</span>');
		
		// Ventura
		habitLocations[29] = new Array (new GLatLng(34.218453,-119.045163), '1855 Daily Dr. 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 Sun:11am-8pm</span>');
		habitLocations[30] = new Array (new GLatLng(34.192158,-118.937082), '1025 Broadbeck Ln. 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 Sun:11am-8pm</span>');
		habitLocations[31] = new Array (new GLatLng(34.227654,-119.176222), '2350 Vineyard Dr. 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 Sun:11am-8pm</span>');
		habitLocations[32] = new Array (new GLatLng(34.286912,-118.716771), '2906 Tapo Cyn. Blvd. 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 Sun:11am-8pm</span>');
		habitLocations[33] = new Array (new GLatLng(34.18112,-118.874739), '11 East Hillcrest Dr. 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 Sun:11am-8pm</span>');
		habitLocations[34] = new Array (new GLatLng(34.278494,-119.293426), '487 E. Thompson Blvd.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 Sun:11am-8pm</span>');
		habitLocations[35] = new Array (new GLatLng(34.263196,-119.227249), '4732 Telephone Rd. 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 Sun:11am-8pm</span>');

		
		// Central Valley
		habitLocations[36] = new Array (new GLatLng(36.8085092, -119.8045365), '702 West Shaw Ave., 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-Sat: 10:30am-10pm Sun:10:30am-9pm</span>');
		
		// Nor Cal
		habitLocations[37] = new Array (new GLatLng(37.896043,-122.062929), 'Walnut Creek at Olympic and South California', '', '<span class="phone">N/A</span><br /><span class="hours">Coming Soon</span>');
      	
		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));
		}
		
        
    } else if (div.getAttribute("address") == "santa-barbara") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(34.419154, -119.676037), 10);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(34.435445,-119.824668), '5735 Hollister Ave. 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 Sun:11am-8pm</span>'); 
		habitLocations[2] = new Array (new GLatLng(34.419154,-119.676037), '216 S. Milpas 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 Sun:11am-8pm</span>'); 
		habitLocations[3] = new Array (new GLatLng(34.418598,-119.697405), '628 State St. 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 Sun:11am-8pm</span>'); 
		habitLocations[4] = new Array (new GLatLng(34.438473,-119.749827), '3890 La Cumbre Plaza Ln. 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 Sun:11am-8pm</span>'); //3890 La Cumbre
      	
		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);
        }
        
    } else if (div.getAttribute("address") == "ventura-county") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(34.218453, -119.045163), 10);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(34.218453,-119.045163), '1855 Daily Dr. 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 Sun:11am-8pm</span>');
		habitLocations[2] = new Array (new GLatLng(34.192158,-118.937082), '1025 Broadbeck Ln. 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 Sun:11am-8pm</span>');
		habitLocations[3] = new Array (new GLatLng(34.227654,-119.176222), '2350 Vineyard Dr. 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 Sun:11am-8pm</span>');
		habitLocations[4] = new Array (new GLatLng(34.286912,-118.716771), '2906 Tapo Cyn. Blvd. 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 Sun:11am-8pm</span>');
		habitLocations[5] = new Array (new GLatLng(34.18112,-118.874739), '11 East Hillcrest Dr. 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 Sun:11am-8pm</span>');
		habitLocations[6] = new Array (new GLatLng(34.278494,-119.293426), '487 E. Thompson Blvd.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 Sun:11am-8pm</span>');
		habitLocations[7] = new Array (new GLatLng(34.263196,-119.227249), '4732 Telephone Rd. 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 Sun:11am-8pm</span>');

		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);
        }
        
    } else if (div.getAttribute("address") == "los-angeles-county") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(34.149557,-118.245907), 9);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(34.1733412, -118.3009755), '103 East Alameda Ave., 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-9pm <br /> Sun: 11am-8pm</span>');
		habitLocations[2] = new Array (new GLatLng(34.238476,-118.571065), '9243 Winnetka Ave. 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 &amp; Sat: 10:30am-10pm <br/>Sun:11am-9pm</span>');
		habitLocations[3] = new Array (new GLatLng(33.919988,-118.396497), '311 N. Sepulveda Blvd. 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-9pm Sun:11am-8pm</span>'); 
		habitLocations[4] = new Array (new GLatLng(34.160356,-118.506422), '17132 Ventura Blvd. 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 Sun:11am-8pm</span>');
		habitLocations[5] = new Array (new GLatLng(34.149557,-118.245907), '249  Glendale Ave. 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[6] = new Array (new GLatLng(34.115859,-117.772917), '1608 Foothill Blvd. 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 Sun:11am-8pm</span>'); 
		habitLocations[7] = new Array (new GLatLng(34.2378,-118.53655), '9215 Reseda Blvd. 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 &amp; Sat:10:30am-12am Sun:11am-10pm.<br />(Dining room closes one hour prior to drive thru)</span>');
		habitLocations[8] = 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 Sun:11am-8pm</span>');
		habitLocations[9] = new Array (new GLatLng(34.397348,-118.491256), '19223 Golden Valley Rd. 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 Sun:11am-8pm</span>'); 
		habitLocations[10] = new Array (new GLatLng(34.151289,-118.452272), '14622 Ventura Blvd. 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 Sun:11am-8pm</span>');  
		habitLocations[11] = new Array (new GLatLng(33.837594,-118.35414), '3829 Torrance Blvd. 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 &amp; Sun: 10:30am-9pm <br /> Fri &amp; Sat:10:30am-10pm</span>');
		habitLocations[12] = new Array (new GLatLng(34.407811,-118.55572), '25948 McBean Pkwy. 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 Sun:11am-8pm</span>'); 
		habitLocations[13] = new Array (new GLatLng(34.443124,-118.606075), '28251 Newhall Ranch Rd.  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 Sun:11am-8pm</span>');
		habitLocations[14] = new Array (new GLatLng(34.167043,-118.620154), '22651 Ventura Blvd. 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>');
		habitLocations[15] = new Array (new GLatLng(34.136395,-118.774535), 'Agoura Hills in Oak Creek shopping center at 101 fwy and Kanan', 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Agoura+Hills&sll=37.0625,-95.677068&sspn=51.089971,73.564453&ie=UTF8&hq=&hnear=Agoura+Hills,+Los+Angeles,+California&z=13&iwloc=A', '<span class="phone">N/A</span><br /><span class="hours">Coming Soon</span>');
		
		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);
        }
        
    } else if (div.getAttribute("address") == "sacramento") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(38.59278, -121.41546), 9);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(38.666098,-121.272262), '5437 Sunrise Blvd. 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-Sat: 10:30am-10pm Sun:11am-9pm</span>');
		habitLocations[2] = new Array (new GLatLng(38.541063,-121.740924), '500 1st Street  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-9:30pm <br />Fri-Sat: 10:30am-10pm <br/>Sun: 10:30am-9pm</span>');
		habitLocations[3] = new Array (new GLatLng(38.422344,-121.410666), '7400 Laguna Blvd. 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-Sat: 10:30am-9pm Sun:11am-8pm</span>');
		habitLocations[4] = new Array (new GLatLng(38.742517,-121.225661), '4060 Douglas Blvd. 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-8pm</span>');
		habitLocations[5] = new Array (new GLatLng(38.768713,-121.328232), '933 Pleasant Grove Blvd. 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-8pm</span>');
		habitLocations[6] = new Array (new GLatLng(38.59278,-121.41546), '1431 Howe Ave. 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-Sat: 10:30am-9pm Sun:11am-8pm</span>');

		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);
        }
        
    } else if (div.getAttribute("address") == "orange-county") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(33.774282,-117.867212), 10);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(33.8780479, -117.8809417), '2720 Nutwood Ave, #A, 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 Sun:11am-8pm</span>'); 
		habitLocations[2] = new Array (new GLatLng(33.774282,-117.867212), '2777 N. Main St. 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 Sun:11am-8pm</span>');
		habitLocations[3] = new Array (new GLatLng(33.619255,-117.701989), '23632 El Toro Rd., #A, 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-Sat: 10:30am-9pm Sun:11am-8pm</span>');

		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);
        }
        
    } else if (div.getAttribute("address") == "central-valley") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(36.8085092, -119.8045365), 11);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(36.8085092, -119.8045365), '702 West Shaw Ave., 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-Sat: 10:30am-10pm Sun:10:30am-9pm</span>');

		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);
        }
   
   } else if (div.getAttribute("address") == "northern-cali") {
        var innerHTML = div.innerHTML;
        var map = new GMap2(div);
        addmapcontrols(div,map);
        map.setCenter(new GLatLng(37.896043,-122.062929), 11);
		
		var habitLocations = new Array();
		habitLocations[1] = new Array (new GLatLng(37.896043,-122.062929), 'Walnut Creek at Olympic and South California', '', '<span class="phone">N/A</span><br /><span class="hours">Coming Soon</span>');

		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);
        }
         
    } else {
        //Add the address with geocoding, passing in the target DIV
        geocodeaddress(div);
    }
}

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;
}
    
});
