function setupSelectBoxes(cssSelector, cssClass) {
	$(cssSelector).combobox({
		comboboxContainerClass: "combobox-container " + cssClass + "-container",
		comboboxValueContainerClass: cssClass + "-value-container",
		comboboxValueContentClass: cssClass + "-value-content",
		comboboxDropDownClass: "combobox-dropdown-container " + cssClass + "-dropdown",
		comboboxDropDownButtonClass: cssClass + "-dropdown-button",
		comboboxDropDownItemClass: "combobox-item " + cssClass + "-item",
		comboboxDropDownItemHoverClass: "combobox-item-hover " + cssClass + "-item-hover",
		comboboxDropDownGroupItemHeaderClass: cssClass + "-item-header",
		comboboxDropDownGroupItemContainerClass: cssClass + "-item-group-container",
		animationType: "",
		width: ""
	});
}

function textBoxClickBlur(cssSelector, defaultText) {
	$(cssSelector).each(function () {
		var def;
		
		if(typeof defaultText != 'undefined' && defaultText != '') {
			this.value = defaultText;
		}
		
		def = this.value;
		
		$(this).click(function () {
			if(this.value == def) {
				this.value = '';
			}
		}); 
		
		$(this).blur(function () {
			if(this.value == '') {
				this.value = def;
			}
		});
	});
}

function submitOnEnter(e, buttonId) {
	var key = (window.event) ? e.keyCode : ((e.which) ? e.which : 0);
	if (key == 13) {
		$("#" + buttonId).click();
		return false;
	} else {
		return true;
	}
}

$(document).ready(function() {
	//make the recipe categories expandible and collapsible
	recipeCategoryCollapse();
	
	//setup standard selectboxes
	setupSelectBoxes(".standard-combobox", "standard-combobox");
	setupSelectBoxes(".events-proximity", "events-proximity-combobox");
	
	//setup brand selectboxes
	setupSelectBoxes(".brand-combobox", "brand-combobox");
	
	textBoxClickBlur('#dnn_StoreLocatorSearchBox_StoreLocatorZipCode', 'Enter Zip');
	textBoxClickBlur('.store-locator-textbox', 'Enter Zip');
	textBoxClickBlur('#dnn_headersearch_txtSearchNew', 'Criteria');
	textBoxClickBlur('.recipe-search-textbox', 'Type here to search all recipes');
	
	//superfish menus
	$("ul.sf-menu").superfish({hoverClass:'sf-menu-hover',pathClass:'sf-menu-path',pathLevels:1,autoArrows:false});
});

function recipeCategoryCollapse() {
	$('.recipe-category-header + .bulleted-list').each(function() { 
		$(this).attr('style', 'display:none')
	});
	
	$('.recipe-category-header').each(function() { 
		$(this).html('<a class="category-expand" href="javascript:void(0);">' + $(this).text() + '</a>');
	});
	
	$('.recipe-category-header a').each(function() {
		$(this).click( function() {
			var newClass = '';
			var newStyle = '';
			
			if($(this).hasClass('category-expand')) {
				newClass = 'category-collapse';
				newStyle = 'display: block';
			} else {
				newClass = 'category-expand';
				newStyle = 'display: none';
			}
			
			$(this).attr('class', newClass);
			$(this).parent().next('.bulleted-list:first').each(function() {
				$(this).attr('style', newStyle)
			});
		});
	});
}