	$(document).ready(
		function(){
			
			
			//innerfade for homepage promo area
			
			$('#promo-text-list').innerfade({
				animationtype: 'fade',
				speed: 'slow',
				timeout: 7000,
				type: 'sequence',
				containerheight: 'auto'
			});
			
			$('.modal').nyroModal();
		/*	
			$('#calculator_output a').click(function(e) {
			e.preventDefault()
			$.nmManual('demoSent.php');
		  });
		  */
			/*
			$('#NyroButton').delegate('a #modal','click', function(e) {
				alert('delegated: '+e.target);
				$.nmManual(e.target.href);
				console.log(e.target);
				e.preventDefault();
				
				//alert(event.target.href);
				
				
				//var hrefTemp = this.attr('href');
				//var hrefTemp =(e.target.href);
				
				//console.log(hrefTemp);
				//alert(hrefTemp);
				
				//$(this).nyroModal().nmCall();
				
				return false;
				//
			});
			*/
			
/*
			$('#portfolio').innerfade({
				speed: 'slow',
				timeout: 4000,
				type: 'sequence',
				containerheight: '220px'
			});
			
			$('.fade').innerfade({
				speed: 'slow',
				timeout: 1000,
				type: 'sequence',
				containerheight: '1.5em'
			});
			*/
		
		
		// end of innerfade
		
		
		//mega menu hover functions
//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}

//end of mega menu hover functions
   


		
        //mega menu hover
        //config

//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 500, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations

// end of mega menu hover 

// jquery validity setup
		//
		/*
		$.validity.setup({ outputMode:"summary" });
		
		$("#locator").validity(function(){
					  
		   $("#postcode_input_box").nonHtml().minLength(7,'The postcode you entered cannot be shorter than 7 characters').maxLength(8,'The postcode you entered should not be longer than 7 characters').require().match(/^([a-z][a-z]?\d\d? ?\d[a-z][a-z])$/i,'The postcode you entered is invalid');                     
													 
		});
		*/
		
    //if submit button is clicked
    $('#btn-calc').click(function () {  
			var h = $('input[name=height]').val();
			var w = $('input[name=width]').val();
			var d = $('input[name=depth]').val();
			//console.log('h:'+h+'w:'+w+'d:'+d);
			//alert('h:'+h+'w:'+w+'d:'+d);
			
		if	((h>0) && (w>0) && (d>0) ){	
			var mino = 0;
			var maxo = 0;
			
			if ($("input[name='measurement']:checked").val() == 'feet') {
				mino = Math.round((h * w * d) / 500);
				//console.log('measure in ft');
			} else {
				mino = Math.round((h * w * d) / 14);
			//	console.log('measure in m');		
			}
			
			maxo = Math.floor(mino * 1.8);
			if ((mino>=1) && (mino<11)){
			
			var result;
			result = '<div class="guided-steps stove_calc_shaded_gradient"><label><strong class="bolder_text brown_text">Step 4:</strong></label><p>For a room of that size we recommend a stove with an<br />output between <strong class=\"bolder_text  brown_text\">' + mino + '</strong> and <strong class=\"bolder_text  brown_text\">'+ maxo + 'kW</strong></p>';
       		result = result + '<div id=\"NyroButton\" ><a class=\"modal\" href=\"http://www.hamletstoves.co.uk/model_list_by_output.php?min=' + mino + '&max=' + maxo +'\">';
			result = result + '<img id=\"show-stove-image\" class=\"dark_box_shadow fivepx_corner_radius\" src=\"http://www.hamletstoves.co.uk/public/themes/hamlet/images/show_stoves_button.png\" alt=\"\Show me suitable Hamlet Stoves"/>'; 
			result = result + '</a></div></div>';

			
			$('#calculator_output').html(result);
			$('.modal').nyroModal();
			
				
			//$('#calculator_output').html("Minimum output:<br />" + mino+ " kW<br /><a class=\"nyroModal\" href=\"http://www.hamletstoves.co.uk/model_list_by_output.php?kwoutput="+ mino+"\">Show suitable stoves</a>");
			
			
			//$('#calculator_output').html("Minimum output:<br />" + mino+ " kW<br /><a class=\"nyroModal\" href=\"http://www.hamletstoves.co.uk/testdivtable.html\">Show suitable stoves</a>");
			}else if (mino<1){
			$('#calculator_output').html("<div class=\"guided-steps stove_calc_shaded_gradient\"><strong>Sorry</strong><br />We cannot recommend a stove for a room of that size.</div>");
			}else if (mino>=11){
			$('#calculator_output').html("<div class=\"guided-steps stove_calc_shaded_gradient\"><strong>Sorry</strong><br />We cannot recommend a stove for a room of that size.</div>");
			}
			//	$("input[name='measurement']").change(function(){
					

				//}
				
//cancel the submit button default behaviours
        return false;
		
		} else {
			$('#calculator_output').html('<div class="guided-steps stove_calc_shaded_gradient"><strong>You must enter all three room measurements</strong></div>');
			
			return false;
		}
		
	
		
    }); 	
	
	
	
	
	/*	
function altcalc(){
		
		
			var h = $('input[name=height]').val();
			var w = $('input[name=width]').val();
			var d = $('input[name=depth]').val();
			console.log('h:'+h+'w:'+w+'d:'+d);
			
	
	
	
	$("input[name='measurement']").change(function(){
	if ($("input[name='measurement']:checked").val() == '1') {
	alert(1);
	}
	else{
	alert(0);
	}
	
	
	
	
	if	((h>0) && (w>0) && (d>0) ){	
			var mino = 0;
			var maxo = 0;
			
			if ($('#output_calc.feet').is(':checked')){
	//		if ($('#output_calc.feet').checked = true){
				mino = Math.round((h * w * d) / 500);
			} else {
				mino = Math.round((h * w * d) / 14);		
			}
			
			maxo = Math.floor(mino * 1.8);
			$('#calculator_output').text('This is a test.');
		} else {
			$('#calculator_output').text('This is not a test.');
		}
		
	}	
*/

//$('#calculator_output a').nyroModal();
/*
			
			$('#calculator_output').delegate('p','click',function(event){
				alert('delegated: '+event.target);
				console.log('hello world');
				console.log(event.target);
			});
			*/
			
		
		}
	);
