// Main.js.php

$(document).ready(function(){
	
	// Selecting Restaurant/Cuisine/Food Type links
	if( $('#choice').length ) {
		
		var bowls = $("#choice div");
		
		bowls.bind("click", choiceMouseClick);
		
		bowls.each(mouseOverEffect);
		
		// Preload Images
		$.preloadImages("http://saintdelivery.com/images/layout/restaurant.png", "http://saintdelivery.com/images/layout/restaurant2.png",
					"http://saintdelivery.com/images/layout/cuisine.png", "http://saintdelivery.com/images/layout/cuisine2.png",
					"http://saintdelivery.com/images/layout/food.png", "http://saintdelivery.com/images/layout/food2.png");
	
		$('.shopping-food-item').live("click", foodItemMouseClick);
		
		$(".get-list-link").live("click", getListLinkMouseClick);
		
		$("span.back").live("click", goBackMouseClick);
		
		$('.search-results-link').live("click", searchResultsFoodItemClick);
	
	}
		
	// Autocomplete search bar
	if ( $('#keywords').length ) {$("#keywords").autocomplete("http://saintdelivery.com/index.php/ajax/search-autocomplete", 
		{
			max:10,
			formatItem:autocompleteFormatItem,
			formatResult:autocompleteFormatResults,
			matchContains: true,
			cacheLength: 0,
			delay: 2000,
			highlight: false,
			selectFirst: false
		});
		
		$("#keywords").bind("result", submitEntryIDSearchForm);
		
		
		$('#keywords').live('keydown', function(e) {
			if(e.keyCode == 13) {
				if( $('#search_form_submit').length ) {submitKeywordSearchForm();}
			}
		});

	}
	
	if( $('#search_form_submit').length ) {
		
		$('#search_form_submit').bind("click", submitKeywordSearchForm);
	}
	
	
	// Registration form 
	/*
	if( $("form#register_member_form").length ) {
		
		$("form#register_member_form").submit(function() {
		
			var email_address = $("input#username").attr("value");
			
			$("input#email").attr("value", email_address);
		});
		
	}
	*/
	
	$('div.defaultBold').each(function() {

		var field_name = $(this).text();
		
		if(field_name.length > 0) {
			if ( (field_name.indexOf("Screen Name") >= 0) || (field_name.indexOf("URL") >= 0) ){$(this).parent().parent().hide();}
		}
		
		$("input[type=checkbox]", this).parent().parent().parent().hide();
	
	}); 
	
	// Custom Order
	
	
	if ( $('form#customOrderForm').length ) {
	
		$('form#customOrderForm').bind("submit", addEmailToForm);
	}
	
	// Complaint form
	
	if ( $('form#complaintsForm').length ) {
	
		$('form#complaintsForm').bind("submit", addEmailToForm);
	}
	
	if ( $('a.fe_checkout').length ) {
	
		$('a.fe_checkout').bind("click", onCheckout); 
	}	
	
	if ( $('button#yes-checkout').length ) {
		$('button#yes-checkout').bind("click", onContinueCheckoutYes);
	}
	
	if ( $('button#no-checkout').length ) {
		$('button#no-checkout').bind("click", onContinueCheckoutNo);
	}
	
	if(	$('span#change_coupon').length ) {

		$('span#change_coupon').bind("click", changeCoupon);
		
	}
	
	if ( $('form#customOrderForm').length ) {
	
			$("select#restaurant").attr("value", "---");
			$('input#restaurant_name').attr("value", '');
			$('input#restaurant_address').attr("value", '');
			$('input#restaurant_phone_number').attr("value", '');
			
			$("select#restaurant").change(function() {
			
				var entry_id = $("select#restaurant option:selected").attr("value");
				var name = '';
				var address = '';
				var phone = '';
				
				
				if(entry_id != '---') {
					name = $('span#restaurant-data-' + entry_id + '-name').text();
					address = $('span#restaurant-data-' + entry_id + '-address').text();
					phone = $('span#restaurant-data-' + entry_id + '-phone').text();
				}
				
				
				$('input#restaurant_name').attr("value", name);
				$('input#restaurant_address').attr("value", address);
				$('input#restaurant_phone_number').attr("value", phone);

			});
	}
	
	// Default for Country in registration
	
	if ( $('input[name="m_field_id_8"]').length ) {
		$('input[name="m_field_id_8"]').attr('value', 'United States');
	}

				
});




