$(document).ready(function() {
    //try
    //{
    //$('ul#nav li a').append(' <span>&#62;</span> ');
	
	//var childurl = $('ul#nav li ul.children li:first a').attr('href');
	//$('ul#nav li ul.children').prev().append(' <span>&#62;</span> ').attr('href',childurl);
	$("ul#nav li:not(.page-item-397) ul li:first a").each(function (i) {;
		var childurl = $(this).attr('href');
		$(this).parent().parent().prev().append(' <span>&#62;</span> ').attr('href',childurl);
	});
	
	var bannerHeight = $('ul#banner ul li:first img').height();

	$('ul#banner ul').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: bannerHeight
	});
	
	$('ul#footnav li:last a').css({backgroundImage:"none"});
	
	$("a[rel='colorbox']").colorbox({transition:"fade"});

	var email = $("input#esi_news_email");
	email.attr("rel",email.val());
	var emailRel = email.attr("rel");
	
	$("input#esi_news_email").focus(function() {
		var element = $(this);
		if (emailRel == element.val()) {
			element.val('');
		}
	});
	$("input#esi_news_email").blur(function() {
		var element = $(this);
		if (element.val() == '') {
			element.val(emailRel);
		}
	});
	
	 
	$("input[name^='esi_wine_total_']").each(function (i) {;
		$(this).replaceWith('<div id="' + $(this).attr("id") + '"></div>');
	});
	$("input[name^='esi_wine_price_']").each(function (i) {;
		$(this).replaceWith('<div class="hide" id="' + $(this).attr("id") + '">' + $(this).val() + '</div>');
	});
	
	$.Calculation.setDefaults({
		// a regular expression for detecting European-style formatted numbers
		reNumbers: /(-|-\R)?(\d+(,\d{3})*(\.\d{1,})?|\.\d{1,})/g
	});
	
	// bind the recalc function to the quantity fields
	$("input[name^='esi_wine_qty_']").bind("change", recalc);
	// run the calculation function now
	recalc();

	
    // catch (o) {}
});

function recalc(){
	$("[id^=esi_wine_total_]").calc(
		// the equation to use for the calculation
		"qty * price",
		// define the variables used in the equation, these can be a jQuery object
		{
			qty: $("input[name^=esi_wine_qty_]"),
			price: $("[id^=esi_wine_price_]")
		},
		// define the formatting callback, the results of the calculation are passed to this function
		function (s){
			// return the number as a dollar amount
			return "R" + s.toFixed(2);
		},
		// define the finish callback, this runs after the calculation has been complete
		function ($this){
			// sum the total of the $("[id^=total_item]") selector
			var sum = $this.sum();
			
			$("#grandTotal").text(
				// round the results to 2 digits
				"R" + sum.toFixed(2)
			);
		}
	);
}




