
 
 
$(document).ready(function(){	
	mainmenu();
});





function mainmenu() {
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function() {
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},
		function() {
			$(this).find('ul:first').css({visibility: "hidden"});
		}
	);
}




function openWineExplorerWindow() {
	//alert('openWineExplorerWindow');
	window.open('http://www.banfiwineexplorer.com/', 'Explorer', 'height=400,width=900,status=yes,toolbar=no,menubar=no,location=no,resizable=yes');
	
	return false;
}




function showSavingData() {
	
	//alert('showSavingData');
	var content = $('#savingData span').clone();
	
	
	// get the form legend
	$('#editLegend span').append(content);
	

	
}


function hideSavingData() {
	// get the form legend
	$('#editLegend span span').remove();
}


function showDataSaved() {
	var content = $('#dataSaved span').clone();
	
	
	// get the form legend
	$('#editLegend span').append(content);
	
	setTimeout("hideSavingData()", 5000);
}




function disableEditForm(id) {
	
	$('#' + id + ' input[type=submit]').css('visibility', 'hidden');
	
	$('#' + id).fadeTo('normal', .3);
}


function enableEditForm(id) {
	$('#' + id + ' input[type=submit]').css('visibility', 'visible');
	
	$('#' + id).fadeTo('normal', 1.0);
}






function initWinePopUps() {
	
	$('a.wineDetailLink').click(
			function () {
				//alert('wineDetailLink ' + this.name);
				var popup_id = 'wineDetails' + this.name;
				//alert('popup_id = ' + popup_id);
				
				
				
				// get the document width and height
				var doc_width = $(window).width();
				var doc_height = $(window).height();
				//alert('doc_width = ' + doc_width);
				
				// get the popup width and height
				var popup_width = $('#' + popup_id).width();
				var popup_height = $('#' + popup_id).height();
				//alert('popup_width = ' + popup_width);
				
				var left = (doc_width - popup_width) / 2;
				
				var top = 10;
				/*
				if (popup_height > doc_height) {
					// if the popup is taller than the window switch the position type so the user can scroll the popup
					$('#' + popup_id).css('position', 'absolute');
					
					// place the top of the popup at the top of the clicked element
					var position = $(this).position();
					top = position.top;
				} else {
					// if the popup is smaller than the window switch the position type so the popup top is relative to the viewport and always appears in the window
					$('#' + popup_id).css('position', 'fixed');
					top = (doc_height - popup_height) / 4;
				}*/
				
				var alert_str = 'popup_id = ' + popup_id + "\n";
				alert_str += 'left = ' + Math.round(left) + "\n";
				alert_str += 'top = ' + Math.round(top) + "\n";
				//alert(alert_str);

				
				$('#' + popup_id).css('top', Math.round(top));
				$('#' + popup_id).css('left', Math.round(left));
				$('#' + popup_id).show();
				
				
				return false;
			}
		);
		
		
		
		
		$('.wineDetailClosePopupLink a').click(
			function () {
				$('.wineDetailsPopUp').hide();
				
				return false;
			}
		);
} // end initWinePopUps




function displayFormElementError(node_id, error_str) {
	//alert('displayFormElementError node_id = ' + node_id);
	
	var node_parent = $('#' + node_id).parent();
	//alert('displayFormElementError node_parent = ' + node_parent);
	var info_node = false;
	
	
	// get all the child nodes for the parent
	var kids = $(node_parent).children();
	
	// loop the kids to see if one has the class we are looking for
	$(kids).each(
		function (i) {
			if ($(this).hasClass('formElementInfoDiv')) {
				info_node = this;
			}
		}
	);
	
	// if we did not find a kid node with the class we want, make one
	if (! info_node) {
		$(node_parent).append('<div class="formElementInfoDiv">This field did not validate.</div>');
		
		// we can get the last child of the parent because we just appended a new div, so we know its the right one
		info_node = $(":last-child", node_parent)[0];
	}
	
	//alert('info_node = ' + info_node);
	
	if (info_node !== false) {
		$(info_node).html(error_str);
		
		// if the string is empty
		if (error_str == '') {
			$(info_node).hide();
		}
	}
}


function showFormSubmitError() {
	var content = $('#formError span').clone();
	
	
	// get the form legend
	$('#editLegend span').append(content);
	

	setTimeout("$('#editLegend span').html('')", 5000);
	
}