$(document).ready(function(){

	//add fish to buttons
	
	$('a.top').prepend('<span class="fish"></span>');
	$('.featured-image a.button').prepend('<span class="fish"></span>');
	$('.promo-content a.button, li .article-content a.button').prepend('<span class="fish"></span>');
	
	//add div to hr to hide borders in IE
	
	$('hr').wrap('<div class="hrfish" />');	

	$("table#comparison td:nth-child(1)").addClass("feature");
	
	$("table#comparison th:nth-child(1)").addClass("feature");
		
	$("table#comparison td:parent").addClass("not-empty");
	
	$("table#comparison tr:last-child td").addClass("feature-header");

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	/*$("a.expand").click(function(){
	
		$(this).toggleClass("active");
		$(this).parents("li").find(".article-content").slideToggle("1500");
		$(this).parents("li").find("h1").toggleClass("active");	
		
		return false; //Prevent the browser jump to the link anchor
		
		var cur = $(this).parents("article").next().find(".article-content").addClass("work");
		
	});	*/

});

$(function() {
	// Hide all the content except the first
	$('#accordion li:odd:gt(0)').hide();
	
	// Add a padding to the first link
	$('#accordion li:first h1').addClass('active');
	$('#accordion li:first a.expand').hide();
		
	// Add the dimension class to all the content
	$('#accordion li:odd').addClass('dimension');
	
	// Set the even links with an 'even' class
	$('#accordion li:even:even').addClass('even');
	
	// Set the odd links with a 'odd' class
	$('#accordion li:even:odd').addClass('odd');
	
	// Show the correct cursor for the links
	$('#accordion li:even').css('cursor', 'pointer');
	
	// Handle the click event
	$('#accordion li:even').click( function() {
		if (!$(this).hasClass("active")) {
		
		$(this).addClass("active");
		var cur = $(this).next();
		var old = $('#accordion li:odd:visible');
		
		old.slideToggle(500);
		cur.stop().slideToggle(500);
		
		// Animate (add) the padding in the new link
		$(this).find('a.expand').stop().hide();
		$(this).find('h1').addClass('active');
		
		// Animate (remove) the padding in the old link
		old.prev().stop().find('a.expand').fadeIn(400);
		old.prev().removeClass("active").stop().find('h1').removeClass('active');
			
		}
	return false;	
	});
	return false;
	
});


function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}   

  function calculate(){
    var f = document.booking;
    
    // update line totals
    if (IsNumeric(f.no_1.value) && IsNumeric(f.cost_pp_1.value)) f.total_1.value = f.no_1.value * f.cost_pp_1.value;
    if (IsNumeric(f.no_2.value) && IsNumeric(f.cost_pp_2.value)) f.total_2.value = f.no_2.value * f.cost_pp_2.value;
    if (IsNumeric(f.no_3.value) && IsNumeric(f.cost_pp_3.value)) f.total_3.value = f.no_3.value * f.cost_pp_3.value;
    if (IsNumeric(f.no_4.value) && IsNumeric(f.cost_pp_4.value)) f.total_4.value = f.no_4.value * f.cost_pp_4.value;
    if (IsNumeric(f.no_5.value) && IsNumeric(f.cost_pp_5.value)) f.total_5.value = f.no_5.value * f.cost_pp_5.value;
    if (IsNumeric(f.no_6.value) && IsNumeric(f.cost_pp_6.value)) f.total_6.value = f.no_6.value * f.cost_pp_6.value;
    
    // calculate total
    var total =  parseFloat(f.total_1.value) + parseFloat(f.total_2.value) + parseFloat(f.total_3.value) + parseFloat(f.total_4.value) + parseFloat(f.total_5.value) + parseFloat(f.total_6.value);
    
    // remove discount
    if (IsNumeric(f.discount.value)) {
      f.total.value = roundNumber(total - parseFloat(f.discount.value),2);
      f.total_copy.value = f.total.value;
    }
    else {
      f.total.value = roundNumber(total,2);
      t.total_copy.value = f.total.value;
      f.balance_due.value = f.total.value;
    }
    
    if (IsNumeric(f.deposit.value) && (f.total.value > 0)) {
      f.balance_due.value = roundNumber(parseFloat(f.total.value) - parseFloat(f.deposit.value),2);
    } else {
      f.balance_due.value = f.total.value;
    }    
  }


$(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	$(".bookPresentation").hide();
	/*$(".article-content:first").show();
	$(".article-content:first").parents("article").find("h1, a.expand").toggleClass("active");*/

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("a.showForm").click(function(){
		
		$(this).parents("aside").find(".presentation-promo").slideUp(800);
		$(this).parents("aside").find(".bookPresentation").delay(1000).slideDown(900);
		
		return false; //Prevent the browser jump to the link anchor
		
	});
	
	$("a.hideForm").click(function(){
	
		$(this).parents("aside").find(".bookPresentation").slideUp(900);
		$(this).parents("aside").find(".presentation-promo").delay(1000).slideDown(800);
		
		
		return false; //Prevent the browser jump to the link anchor
		
	});								

	$('.top').click( function() {
		$('html, body').animate({scrollTop:0},1000);
		return false;
	});

});

$().ready(function() {
	// validate the comment form when it is submitted
	$(".contactForm").validate();
	$(".bookPresentation").validate();
	$(".franchisee-confirm").validate();
});

