function changeColour ()
{
	counter++;
	counter = counter % counterMax;
	var colourRatio = blend(0, counterMax, 0, 1, counter);
	var newColour = getColour(colourRatio);
	$chameleonText.css('color', newColour);
	$chameleonImages.css('background', newColour);
}



function blend (sourceMin, sourceMax, destMin, destMax, input)
{
	var output = (((input - sourceMin) / (sourceMax - sourceMin)) * (destMax - destMin)) + destMin;
	return output;
}

function getColour (ratio)
{
	switch (ratio)
	{
		case 0:
			return 'rgb(' + colours[0].r + ',' + colours[0].g + ',' + colours[0].b + ')';			
			break;
		case 1:
			return 'rgb(' + colours[1].r + ',' + colours[1].g + ',' + colours[1].b + ')';
			break;
		default:
			// determine lower bound
			var multipliedRatio = ratio * (colours.length-1);
			var lowerIndice = Math.floor(multipliedRatio);
			var upperIndice = lowerIndice+1;
			var fauxRatio = blend(lowerIndice, upperIndice, 0, 1, multipliedRatio);
			return blendColours(colours[lowerIndice], colours[upperIndice], fauxRatio);
			break;
	}
}

function blendColours (point1, point2, ratio)
{
	var output = 'rgb(' + Math.round(blend(0,1,point1.r, point2.r, ratio)) + ',' + Math.round(blend(0,1,point1.g, point2.g, ratio)) + ',' + Math.round(blend(0,1,point1.b, point2.b, ratio)) + ')';
	return output;
}

var colours = [
	{ r: 0, g: 170, b: 160 }, // aqua
	{ r: 0, g: 116, b: 192 }, // blue
	{ r: 105, g: 0, b: 186 }, // purple
	{ r: 190, g: 0, b: 179 }, // pink
	{ r: 179, g: 0, b: 0 }, // red
	{ r: 202, g: 95, b: 0 }, //orange
	{ r: 225, g: 185, b: 0 }, // yellow
	{ r: 0, g: 176, b: 108 }, // green
	{ r: 0, g: 170, b: 160 } // aqua
];

var counter = 0;
var counterMax = 300; // larger number causes slower colour transition
var counterIntervalMilliseconds = 150;
var counterInterval = null;
var $chameleonText = null;
var $chameleonImages = null;

$(document).ready(function() {
	$chameleonText = $('h1,h2,h3,a');
	$chameleonImages = $('.chameleon');
	counterInterval = setInterval(changeColour, counterIntervalMilliseconds);
	//initializeMap();
	$('#services li:nth-child(3n)').addClass('thirdChild');
})

function initializeMap() 
{
	var storeLatLong = new google.maps.LatLng(-28.130639, 153.45638);
	var mapCenterLatLong = new google.maps.LatLng(-28.115, 153.464);
	
	/*
	var mapStyles = [
	    {
	      featureType: "all",
	      elementType: "all",
	      stylers: [
	        { saturation: -100 },
		    { gamma: 1.39 }
	      ]
	    }
	];
	*/
	
	var myOptions =
	{
		zoom: 13,
		mapTypeControl: false,
		/*mapTypeControlOptions:
		{
			style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
			mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'grayStyle']
		},*/
		center: mapCenterLatLong,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		streetViewControl: false
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var marker = new google.maps.Marker({
		position: storeLatLong,
		map: map,
		title: "Hello World!"
	});

	// info window with address
	var infowindow = new google.maps.InfoWindow({
		content: '<div id="infoWindow"><h3 style="margin-top:0;font-size:14px;">Impressions Imprint</h3>33 Doubleview Drive<br />Elanora, QLD 4221<br/>Australia</div>'
	});
	infowindow.open(map, marker);
	google.maps.event.addListener(marker, 'click', function () 
	{
		infowindow.open(map, marker);
	});
	
	//var mapType = new google.maps.StyledMapType(mapStyles, { name:"Mono" });    
	//map.mapTypes.set('grayStyle', mapType);
	//map.setMapTypeId('grayStyle');

}
