


$(document).ready(function() {
	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hover(megaHoverOver, megaHoverOut);
	$("input[type='text']").change( function() {
		subtotal();
	});
});


function megaHoverOver(){
	$(this).find("a").css({'background-color': '#6A93D4'});
	$(this).find(".sub").stop().fadeTo('fast', 1).show();
		
	(function($) { 
		jQuery.fn.calcSubWidth = function() {
			rowWidth = 0;

			$(this).find("ul").each(function() {					
				rowWidth += $(this).width(); 
			});	
		};
	})(jQuery); 
	
	if ( $(this).find(".row").length > 0 ) {
		var biggestRow = 0;	

		$(this).find(".row").each(function() {							   
			$(this).calcSubWidth();

			if(rowWidth > biggestRow) {
				biggestRow = rowWidth;
			}
		});

		$(this).find(".sub").css({'width' :biggestRow});
		$(this).find(".row:last").css({'margin':'0'});
		
	} else { 
		
		$(this).calcSubWidth();

		$(this).find(".sub").css({'width' : rowWidth});
		
	}
}


function megaHoverOut(){ 
  $(this).find(".sub").stop().hide(); 
  $(this).parent().find('a.menuItem').css({'background-color' : 'blue'});
  $(this).parent().find('a.menuItemLast').css({'background-color' : 'blue'});
}

	


	
$(document).ready(function() {
	$("input[type='text']").change( function() {
		subtotal();
	});
});


function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);	
	return result;
}


function subtotal() {
	$sumTotal = 0
	for (i=1; i<=10; i++) {
		$q = parseInt($("#quantity"+i).val());
		$p = parseFloat($("#price"+i).val());
		$total = $q * $p;
		$total = roundNumber($total, 2);
		if (isNaN($total)) {
			$("#subtotal"+i).val('');
		} else {
			$("#subtotal"+i).val($total.toFixed(2));
			$sumTotal += $total;
		}
		$sumTotal = roundNumber($sumTotal, 2);
		$("#subtotal").val($sumTotal.toFixed(2));
	}

}





function clickIE4(){
  if (event.button==2){
    return false;
  }
}

function clickNS4(e){
  if (document.layers||document.getElementById&&!document.all){
    if (e.which==2||e.which==3){
      return false;
    }
  }
}

if (document.layers){
  document.captureEvents(Event.MOUSEDOWN);
  document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
  document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")