var n = 0;
var speed = 5000; // in ms, for call to action rotation

$(document).ready
(
	function() 
	{
		// suckerfish style menu
		$('ul#nav').superfish();
		$('ul.nested li:last-child').addClass("last");
		$('.nested').bgiframe();
		$('ul#nav li a').addClass("cufon");
		$('ul#nav li ul li a').removeClass("cufon");
		Cufon.replace('a.cufon');

		// put the input label _inside_ the input
		$("#extra input").labelify
		(
			{ 
				text: "label", 
				labelledClass: "labelhilite" 
			}
		);

		$('a[rel="external"]').click
		( 
			function() 
			{
				window.open( $(this).attr('href') );
				return false;
			}
		);  
		showNextCallToAction();
		
		/*
		This handles the FAQ yes/no links
		*/
		$("#faqs p.useful a").click(function() {
			answer = $(this).children().attr("alt");
			faqID = $(this).closest("div").children("strong").attr("id");
			/*
			answer and question above can now be used in an ajax call to somewhere or other.
			
			It's pretty clever jQuery really, it'll send:
				- 'Yes' or 'No' (these are from the 'alt' attributes of the image inside the anchor which has been clicked)
				- faqID from the ID of the first <strong /> tag inside the same 'li' that the anchor is in)
			*/
			$.ajax
			(
			    {
                    type: "POST",
                    url: "Default.aspx",
                    data: "answer=" + answer + "&faqID=" + faqID
                }
            );
             
			$(this).parent().html("Thank you for your response");
		});
		/*
		Jump to top on FAQs page
		*/
		$("#faqs div.question").click(function() {
			$('html, body').animate({scrollTop:0}, 200);
		});
		$("#faqs div.answer").click(function() {
			return false;
		});
	}
);

function showNextCallToAction() {
	getElements = $("#sidecalltoaction div.inneritem");
	
	if(n == getElements.length) {
		n = 0;
	}
	
	$("#sidecalltoaction div.inneritem").hide();
	$(getElements[n]).show();
	
	setTimeout(function(){showNextCallToAction()}, speed);
	n++;
}

