home_nav_on = 'home_mission';

home_nav = {
	show: function(slug){
		if($(slug)){
			$(home_nav_on).style.display = 'none';
			$(slug).style.display = 'block';
			home_nav_on = slug;
		}
	}
}

inits = {
	show: function(id){
		content = $('init_'+id).innerHTML;
		$('left_col').update("<div class='pad'>"+content+"</div>");
	}
}

friends = {
	show: function(id){
		content = $('friend_'+id).innerHTML;
		$('left_col').update("<div class='pad'>"+content+"</div>");
	}
}

cal = {
	load_event: function(id){
		$('left_col').update("<div class='pad'>Loading Event...</div>");
		new Ajax.Request('/news/load_event/'+id,{
			method: 'get',
			onSuccess: function(t){
				$('left_col').update("<div class='pad'>"+t.responseText+"</div>");
			}
		});
	}
}

function hide_msg(){
	if($('msg')){
		$('msg').fade();
	}
}

// function for the price updater on the product page
/*
function update_product_price(base_price,option_id){
	var parent_option_id = document.getElementById('product_option_'+option_id).options[document.getElementById('product_option_'+option_id).selectedIndex].value;
	var price_change = document.getElementById('price_change_' + parent_option_id).value;
	var new_price = parseInt(base_price) + parseInt(price_change);
	document.getElementById('current_product_price').innerHTML = "$" + new_price.toFixed(2);
	document.getElementById('modified_product_price').value = new_price.toFixed(2);
}
*/
// optimized product updater -wes
function update_product_price(base_price,option_id){
	var parent_option_id = $F('product_option_'+option_id);
	var price_change = $('price_change_'+parent_option_id).value;
	
	// PROBLEM: values to the right of the decimal are not being recognized
	// the parseInt() function's extracting logic: it does not attempt to round the extracted number the nearest integer
	//var new_price = parseInt(base_price) + parseInt(price_change);
	
	// SOLUTION: use parseFloat instead
	// for conversion to a floating-point number
	var new_price = parseFloat(base_price) + parseFloat(price_change);
	
	var final_price = new_price.toFixed(2);
	$('current_product_price').innerHTML = "$" + final_price;
	$('modified_product_price').value = final_price;
}

function yarn_check_field(){
	if($('weight_cat_check_field')){
		if($('weight_cat_check_field').checked == true){
			var show = 'block';
		}else{
			var show = 'none';
		}
		$('weightWrapField').setStyle('display: '+show+';');
	}
}
function discount_code_update(){
	$('discount_update_btn').disabled = true;
	$('discount_update_btn').update('Searching Discount Codes');
	var discount_code = $('discount_code').value;
	new Ajax.Request('/shop/apply_discount_code',{
		method: 'post',
		parameters: 'discount_code='+discount_code,
		onSuccess: function(t){
			var ret = t.responseText.split('|');
			$('discount_desc').update(ret[1]);
			$('discount_desc').addClassName(ret[0]);
			$('discount_update_btn').disabled = false;
			$('discount_update_btn').update('Apply Discount Code');
			setTimeout(function(){
				window.location='/shop/cart/';
			},1000);
		}
	});
}

/*
Element.observe(window,'load',function(){
	Element.observe('weight_cat_check_field','change',function(){
		yarn_check_field();
	});
	setTimeout('yarn_check_field()',200);
	setTimeout('hide_msg()',3000);	
});
*/





