
// Site slideshows use jQuery Cycle Plugin
// see: http://jquery.malsup.com/cycle/options.html

// home: home carousel
function homeCarousel(){
	$('.home-carousel').cycle({
            fx: 'fade',
            height: '212',
            width: '700',
            fit: 1
    });
}

// running a hotel: carousel
function runningCarousel(){
	$('.running-carousel').cycle({
            fx: 'fade',
            height: '212',
            width: '490',
            fit: 1
    });
}

// module: principal partners carousel
function partnersCarousel(){
	$('.partners-carousel').cycle({
            fx: 'fade',
            height: '80',
            width: '210',
            fit: 1
    });
    
    /* Cheating here, don't want to create 1 custom template for about for 1 function call, piggybacking on existing function call  */
    $('.running-carousel').cycle({
            fx: 'fade',
            height: '212',
            width: '490',
            fit: 1
    });
    
    $('.train-carousel').cycle({
            fx: 'fade',
            height: '230',
            width: '660',
            fit: 1
    });
}

// module: banner
function bannersCarousel(){
	$('.banners-carousel').cycle({
            fx: 'fade',
            height: '60',
            width: '468',
            fit: 1
    });
}

// zebraStriping for modules
function stripeChildElementsOnPage(){
	// add filter class to blog site summary module output
	$(".blogsitesummary").addClass("toStripe");
	// stripe only even children (and not children of children) of elements classed with filter
	$(".toStripe > :nth-child(even)").addClass("stripe");
}

// Login actions display
function checkLoginStatus(loggedIn){
	
	var loginBool = loggedIn; // Boolean supplied by BC Environment
	
	if (loginBool == 1){ // user is logged in
		$(".inside-box").hide() 
		
	} else { // user is not logged in
		$(".outside-box").hide() 
	};
	
};

// Event booking Cost Calculator
function calculateBookingAmount(){
	// This script expects:
	// + a p element that contains "Cost:" substring and price substring in form of "$x.xx" i.e <p>Cost: $150.00pp GST Inc.</p>
	// If the cost is $0.00 then the event booking payment form is hidden 
	// a form called #catwebformform56957
	// a text input called #CAT_Custom_147144
	
	var ticketCost = getTicketCost(); // get ticket amount by parsing text on page
	var ticketQuantity;
	
	// Set default total amount
	calculateTotal();
	
	// Set handler event for select input #CAT_Custom_147144 
	// note that a select element has been used as change event is triggered immediately
	$("#CAT_Custom_147144").change( function() {
  		calculateTotal();
	});
	
	function calculateTotal(){
		ticketQuantity = $("#CAT_Custom_147144").attr("value"); // get updatd quantity total after event
		
		var totalCost = ticketQuantity * ticketCost; // calc total cost
		var displayCost = totalCost.toFixed(2); // ensure end result has 2 decimal places i.e. cents for transaction
		
		$("#Amount").attr("value", displayCost); // display cost in non-editable #Amount field
	}
	
	function getTicketCost(){
		var source = $("p:contains(Cost:)").text(); // find p that contains "Cost:"
		
		var start = source.indexOf("$") + 1; // get pos of first char after "$" char
		var decimal = source.indexOf("."); // get pos of decimal point
		var end = decimal + 3; // get end pos after decimal chars
		var cost = source.substring(start, end); // get the cost substring and return
		
		if (cost != "0.00"){
			return cost;
		} else {
			hideForm();
		}
	}
	
	function hideForm(){
		$("p:contains(Cost:)").hide();
		$("#catwebformform56957").hide();
	}
};

// function for showing and hiding divs in forms
    $(document).ready(function(){
       
       $("#mailing-details").css("display","none");
       $("#billing-details").css("display","none");
       $("#additional-contacts").css("display","none");

       $("#checkbox-mailing").click(function(){   
        if ($("#checkbox-mailing").is(":checked"))
        {
            $("#mailing-details").show("fast");
        }
        else
        {     
            $("#mailing-details").hide("fast");
        }
      });

       $("#checkbox-billing").click(function(){   
        if ($("#checkbox-billing").is(":checked"))
        {
            $("#billing-details").show("fast");
        }
        else
        {     
            $("#billing-details").hide("fast");
        }
      });

       $("#checkbox-contacts").click(function(){   
        if ($("#checkbox-contacts").is(":checked"))
        {
            $("#additional-contacts").show("fast");
        }
        else
        {     
            $("#additional-contacts").hide("fast");
        }
      });

   
    });
	

	
//suckerfish hover effect for IE6

$(document).ready(function () {
  var li = $('.nav li');
  li.mouseover(function () {
    $(this).addClass('sfhover');
  });
  li.mouseout(function () {
    $(this).removeClass('sfhover');
  });
});
