$(document).ready(function() {
    $("#header h1").click(function() { location.href = "/"; });
    if ($("textarea").length > 0) {

        $('textarea').autoResize({
            onResize: function() {
                $(this).css({ opacity: 1 });
            },
            animateCallback: function() {
                $(this).css({ opacity: 1 });
            },
            animateDuration: 300,
            extraSpace: 40
        });

    }
    if ($("#homeImage").length > 0) {
        i = 0;
        j = 0;
        fancyImage();
        window.setInterval(function() {
            fancyImage();
        }, 5000);
    }

    // Google Maps
    if ($("#map").length > 0) {
        $("#map").gMap({
            latitude: 53.34725941698252,
            longitude: -6.2592244148254395,
            zoom: 14,
            markers: [{ latitude: 53.341998, longitude: -6.253978, html: "<p><strong>Care For The Elderly</strong><br />14 South Leinster Street,<br />Dublin 2,<br />Ireland.</p>"}],
            controls: ["GSmallMapControl", "GMapTypeControl"]
        });
    }

    // Load the tax refund calculator if the div 'calculateTax' is there.
    if ($("#calculateTax").length > 0) {
        $('#calculateTax').load('ajax/taxCalculator.html');
    }
});


function fancyImage(){
	/* 
		Title: FancyImageCycle
		Description: Image cycler with mouseover text
		Author: IPAG (Ireland) Ltd. KG
		Version: 0.2
	*/
	
	imageArray = [
		'url(\'images/template/homeImageRotator001.jpg\')',
		'url(\'images/template/homeImageRotator002.jpg\')',
		'url(\'images/template/homeImageRotator003.jpg\')'
	];
	textArray = [
		'Supporting you in just the way you need',
		'Helping you and your loved one stay at home',
		'We are always here to help with your home care needs'
	];
	
	if(i == imageArray.length){ i = 0; }
	if(j == textArray.length){ j = 0; }
	$("#homeImage").fadeOut(800, function(){
		$("#homeImageText").html(textArray[j]).animate({"backgroundColor" : "rgba(110, 0, 130, 0.3)", bottom : '-360'}, 0);
		$("#homeImage").css("background-image", imageArray[i]);
		$("#homeImage").fadeIn(800, function(){
			$("#homeImageText").animate({bottom: '-300'}, 500);
		});
		j++;
		i++;
	});
}
