$(function() {
	$("div.expand").click(function () {
		$(this).toggleClass("active");
	});
   	 $("#random").randomChild();

	$("p.view-all a").toggle(function() {
		$("#random").children().show();
			$(this).text("Fewer testimonials");
			}, function() {
			$(this).text("More testimonials");
			$("#random").randomChild();
	});
	$.ajax({
		type: "GET",
		url: "/site/strapline",
		dataType: "xml",
		success: function(xml) {
			$('<ul id="strapline"></ul>').appendTo('#header');
			var preloadQueue = new Array();
			$(xml).find('slide').each(function(i){
				var content = $(this).find('content').text();
				$('<li></li>').html(content).appendTo("ul#strapline");
			});
			callCycle();
		}
	});


	$("#contact-form").click(function () {
		$(this).toggleClass("active");
		$("#contact").toggle("fast");
	});
	$("tr:even").addClass("even");
	$('#freeform').ajaxForm(
		{
		target:"#hiddenDIV",
		clearForm: true,
		resetForm: true,
		beforeSubmit:function()  
	  {
	     $("#msg").html("<h2>Contacting the server....</h2>");
	  },
	   success:function(rtn) 
	   { 
	    if(rtn=="success")
	    {
		$("#msg").load("/includes/thanks");
			}else{
		$("#msg").html($("#hiddenDIV ul").html());

			$("#hiddenDIV").empty();
			
			}
		} 
	  }
	);
    
});

function callCycle() {
	$('#strapline').cycle({ 
	    delay:8, 
	    speed:1000
	});
};


jQuery.fn.randomChild = function(settings) {
	return this.each(function(){
		var c = $(this).children().length;
		var r = Math.ceil(Math.random() * c);
		$(this).children().hide().parent().children(':nth-child(' + r + ')').show();
	});
};