function newsTicker() {
	var pause = 4000;
	$('ul#ticker li').hide();
	$('ul#ticker li:first').fadeIn('slow');
	function removeFirst(){
		$('ul#ticker li:first').fadeOut('slow', function() {addLast(this);});
	}
	function addLast(first){
		$(first).insertAfter('ul#ticker li:last');
		$('ul#ticker li:first').fadeIn('slow');
	}
	interval = setInterval(removeFirst, pause);
}

function toggler(anchor, section) {
	$(section).hide();
	$(anchor).click(function(e) {
		e.preventDefault();
		$(section).slideUp('slow');
		var next = $(this).next(section);
		if (! next.length) {
			next = $(this).parent().next(section);	
		}
		if (next.is(':hidden')) {
			next.slideDown('slow');
		}
	});
}

function imageRollover() {
    $('.rollover').hover(function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    }, function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    });
}

function signupInterestRadioButtons() {
	// On page load, show the more info radio selector if one of the valid options is selected
	//if ($('#interest-questions input:not([value=1-updates]):checked').length && $('#interest-questions input:not([value=6-installer]):checked').length) {
	//	$('#more-info-div').show();	
	//}
	// Show the more info radio selector if one of the valid options is selected on click
	//$('#interest-questions input').change(function() {
	//	if (! $(this).attr('checked')) {
	//		return;
	//	}
	//	if ($(this).val() == '1-updates' || $(this).val() == '6-installer') {
	//		$('#more-info-div').hide();
	//		$('#moreinfo-questions input[value=No]').click().attr('checked','checked');
	//		$('#signup-submit-button').val('Submit Form');
	//	} else {
	//		$('#more-info-div').show();
	//		if ($('#moreinfo-questions input:not([value=Yes]):checked').length) {
	//			$('#signup-submit-button').val('Submit Form');
	//		}else{
	//			$('#signup-submit-button').val('Proceed to Next Step');
	//		}
	//	}
	//});
	//On page load, show the more info radio selector if one of the valid options is selected
	if ($('#interest-questions input:not([value=1-updates]):checked').length) {
		$('#more-info-div').show();	
	}
	// Show the more info radio selector if one of the valid options is selected on click
	$('#interest-questions input').change(function() {
		if (! $(this).attr('checked')) {
			return;
		}
		if ($(this).val() == '1-updates') {
			$('#more-info-div').hide();
			$('#moreinfo-questions input[value=No]').click().attr('checked','checked');
			$('#signup-submit-button').val('Submit Form');
		} else {
			$('#more-info-div').show();
			if ($('#moreinfo-questions input:not([value=Yes]):checked').length) {
				$('#signup-submit-button').val('Submit Form');
			}else{
				$('#signup-submit-button').val('Proceed to Next Step');
			}
		}
	});
}

$(document).ready(function() {
	$('body').removeClass('nojs');
	$('body').addClass('hasjs');

	// Setting up image rotators
	$('#rotator').cycle('scrollDown');
	$('#overview-rotator').cycle('scrollDown');

	newsTicker();
	toggler('a.faq-q', 'div.faq-a');
	imageRollover();
	signupInterestRadioButtons();
});
