utils = {
	// adding onclick behavior on LI refering to it's first Child's	HREF value
	add_click_main_nav : function() {
		$("#nav li").each(function() {
			$(this).bind('click', function(){
					window.location = $(this).children()[0].href;
				});
		});
	},
	
	// make sure narrow sidebar are always the same height as the #main area
	fix_sidebar_height : function() {
    // $('#main').css('height', '1000');
    height = $('#content').css('height');
		$(".middle-col, .right-col").each(function() {
			$(this).css('height', height);
		});		
	}
			
};

buffet = {
	
	init : function() {
		$('.buffet-select li.choice').each(function() {
			var el = (this);
			var label = $(this).children()[0];
			var radio = $(label).children()[0];
			
			$(radio).bind('click', function() {
				$(el).addClass('active');
				buffet.animate_menu(el, $(el).children('.content').height() + 45);
				buffet.uncollapse(el, radio);
			});
		});
	},

	uncollapse : function(current, radio) {
		$('.buffet-select li.choice').each(function() {
			if(this != current) {
				$(this).removeClass('active');
				buffet.animate_menu(this, 18);
			}
		});
	},

	animate_menu : function(el, height) {
		$(el).animate({
			height: height
		}, 500);
	} 
};

orders = {	
		
	settings : {
		'container' : '#order-items'
	},
		
	add_to_order : function(item) {
		e = $(item);
		if(e && !e.hasClass('loading')) {
			e.addClass('loading');			
			$.ajax({
				type: "GET",
				cache: false,
				dataType: "html",
				url: "/orders/ajax_return_item/" + e.val(),
				success: function(data){
					orders.add_item_to_order(data);
				}		
			});
		}
	},
		
	add_item_to_order : function(data) {
		e.removeClass('loading');		
		$('ul#order-items').append(data);		
		this.calculate_total();
		// this.enable_button();
	},
	
	calculate_total : function() {
		var total = 0.00;
		$('input.item-price').each(function() { total += parseFloat($(this).val()); });
		total = (Math.round(total * 100) / 100).toString();		
		
		if(total.length <= 2) {
			total += '.00';
		}	
			
		$('#total').text(total);
	},
	
	enable_button : function() {
		$('button.submit-button').removeAttr('disabled');
	}			

};

map = {
	
	loadMap : function() {		
		if (document.getElementById("map")) {
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(45.549864, -73.590774), 15);
			var p = new GLatLng(45.549864, -73.590774);					
			var m = new GMarker(p);
			map.addOverlay(m);
		}
	}
	
};