//Document on ready functions ~njackson
$(document).ready(function() {
	$('ul#print').append('<li><a href="#print" class="print" title="Print this page from Acorn Stairlifts" style=" color: #8E2C45; text-align:center; font-weight:bold; padding: 8px 10px 0px 30px ; background: url(http://resources.acornstairlifts.com/images/icons/set/printer.png) 8px 8px no-repeat #E8DFB5; width: auto; height: 22px; display:block; -moz-border-radius-topleft:10px; -webkit-border-radius-topleft:10px; -moz-border-radius-topright:10px; -webkit-border-radius-topright:10px;">Print this page<\/a><\/li>');
	$('ul#print li a.print').click(function() {
		window.print();
		pageTracker._trackEvent('Buttons', 'Print', window.location.pathname);
		return false;
	});
	
	$("#callback_form_click").click(function(){
		if($("#header-box-form").css("display") != 'none')
		{
			$("#header-box-form").css("display","none");
			$("#header-box-form-callback").css("display","block");
			$(".h3-callback-form").css("visibility","visible");
			$("#call-or-post").html('for info via mail');
			pageTracker._trackEvent('FormToggle', window.location.pathname, 'Callback');
			//sIFR.redraw();
		}
		else
		{
			$("#header-box-form").css("display","block");
			$("#header-box-form-callback").css("display","none");
			//sIFR.redraw();
			$("#call-or-post").html('and we\'ll call you');
			pageTracker._trackEvent('FormToggle', window.location.pathname, 'Mail');
		}
		return false;
	});

	$("#Who_For_other_div").css("display","none");
	$("#Who_For").change(function(){
		if($("#Who_For :selected").val()=='Other'){
			$("#Who_For_other_div").css("display","block");
		}
		else
		{
			$("#Who_For_other_div").css("display","none");
		}
	});
	
	$("#Source_other_div").css("display","none");
	$("#Source").change(function(){
		if($("#Source :selected").val()=='Other'){
			$("#Source_other_div").css("display","block");
		}
		else
		{
			$("#Source_other_div").css("display","none");
		}
	});
	
	//Load the slideshow
	theRotator();
	theNumberRotator();
	
	$('li.headlink').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); }
	); 
	
	
});
//Functions ~njackson
function theRotator() {
	//Set the opacity of all images to 0
	$('#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('#rotator ul li.show')?  $('#rotator ul li.show') : $('#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rotator ul li:first') :current.next()) : $('#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

function theNumberRotator() {
	//Set the opacity of all images to 0
	$('#numberrotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#numberrotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('numberrotate()',6000);
	
}

function numberrotate() {	
	//Get the first image
	var current = ($('#numberrotator ul li.show')?  $('#numberrotator ul li.show') : $('#numberrotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#numberrotator ul li:first') :current.next()) : $('#numberrotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};
