// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

showToolTip = function() {
  $('tooltip').appear({ duration: .2 });
}

function hideDropDown() {
	parentObject = document.getElementById('company_drop_down');
	for (i=1; i<parentObject.childNodes.length; i++) {
		node = parentObject.childNodes[i];
		node.className=node.className.replace(" over", "");
	}
}

function revealDropDown() {
	parentObject = document.getElementById('company_drop_down');
	topObject = document.getElementById('top');
	topObject.onmouseover = function() {
		for (i=1; i<parentObject.childNodes.length; i++) {
			node = parentObject.childNodes[i];
			node.className+=" over";
		}
	}
}

function dropDown() {
	if (document.all&&document.getElementById) {
		revealDropDown();
		document.getElementById('content').onmouseover = function() {
			hideDropDown();
		}
		document.getElementById('subnav').onmouseover = function() {
			hideDropDown();
		}
		document.getElementById('header-photo').onmouseover = function() {
			hideDropDown();
		}
	}
}

function changeText(elementId, ingredientId) {
	textElement = document.getElementById(elementId);
	ingredient = document.getElementById(ingredientId);
	if (textElement.innerHTML == "[hide]") {
  	textElement.innerHTML = "[read more]";
		$(ingredient).morph('height:55px', {duration: 0.4});
	} else {
		textElement.innerHTML = "[hide]";
		ingredientHeight = ingredient.scrollHeight;
		ingredientHeight = 'height:'+ingredientHeight.toString()+'px';
		$(ingredient).morph(ingredientHeight, {duration: 0.6});
	}
}

function populateBillingInfo() {
	checkoutForm = document.getElementById('checkout_form');
	if (document.getElementById('billing_same_as_shipping_checkbox').checked) {
		checkoutForm.order_billing_first_name.value = checkoutForm.order_ship_to_first_name.value;
		//checkoutForm.order_billing_first_name.disabled = true;
		checkoutForm.order_billing_last_name.value = checkoutForm.order_ship_to_last_name.value;
		//checkoutForm.order_billing_last_name.disabled = true;
		checkoutForm.order_billing_address.value = checkoutForm.order_ship_to_address.value;
		//checkoutForm.order_billing_address.disabled = true;
		checkoutForm.order_billing_city.value = checkoutForm.order_ship_to_city.value;
		//checkoutForm.order_billing_city.disabled = true;
		checkoutForm.order_billing_state.value = checkoutForm.order_ship_to_state.value;
		//checkoutForm.order_billing_state.disabled = true;
		checkoutForm.order_billing_postal_code.value = checkoutForm.order_ship_to_postal_code.value;
		//checkoutForm.order_billing_postal_code.disabled = true;
	} else {
		checkoutForm.order_billing_first_name.value = '';
		checkoutForm.order_billing_first_name.disabled = false;
		checkoutForm.order_billing_last_name.value = '';
		checkoutForm.order_billing_last_name.disabled = false;
		checkoutForm.order_billing_address.value = '';
		checkoutForm.order_billing_address.disabled = false;
		checkoutForm.order_billing_city.value = '';
		checkoutForm.order_billing_city.disabled = false;
		checkoutForm.order_billing_state.value = '';
		checkoutForm.order_billing_state.disabled = false;
		checkoutForm.order_billing_postal_code.value = '';
		checkoutForm.order_billing_postal_code.disabled = false;
	}
}