$(function() {
	// homepage carousel
	if ($("#imageContainer").length && typeof $.fn.hbcarousel === 'function')
		$("#imageContainer").hbcarousel({rotationInterval:11500});

	if (typeof $.fn.fancybox === 'function')
		$("#gallery-1 a, a.fancybox").fancybox();

	// name that detail answer
	if ($("a.detail_answer").length && typeof $.metadata === 'object') {
		$("a.detail_answer").bind("click", function() {
			var data = $(this).metadata();
			if (data.answer)
				$(this).parent().text(data.answer);
			return false;
		});
	}

	if ($("#contact_map_1").length) {
		map1 = new hbMap('contact_map_1', [21.314904, -157.863482], { zoom:14 });
		map1.addMarker([21.31683518310513, -157.8683665394783], 'HONBLUE Iwilei Headquarters');
		map1.addMarker([21.309456, -157.860253], 'HONBLUE Downtown');
	}

	if ($("#contact_map_2").length) {
		map2 = new hbMap('contact_map_2', [20.891691,-156.461126]);
		map2.addMarker([20.891691,-156.461126], 'HONBLUE Maui');
	}
});

function hbMap(id, center, options) {
	this.map = null,
	this.markersArray = [];

	// initialize map
	this.addMap = function(id, center, options) {
		var $map = $("#"+id);
		if ($map.length && center[0] && center[1]) {
			var myLatlng = new google.maps.LatLng(center[0], center[1]),
				myOptions = $.extend({}, {
					zoom: 15,
					center: myLatlng,
					mapTypeControl: false,
					streetViewControl: false,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				}, options);

			// initialize map
			this.map = new google.maps.Map($map[0], myOptions);
		}
	};

	// add a marker
	this.addMarker = function(coords, title) {
		if (coords[0] && coords[1]) {
			var myLatlng = new google.maps.LatLng(coords[0], coords[1]);
			new google.maps.Marker({
				map: this.map,
				position: myLatlng,
				title: title
			});
		}
	};

	return this.addMap(id, center, options);
};

function readCookie(name) {
	var nameEQ = name + '=',
		ca = document.cookie.split(';');
	for (var i=0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
};
