// JavaScript Document to animate Olay UK microsites.

$(document).ready(function(){

	var initiativeNo = 0;

	function autoAnimateInitiatives() {

		

		$('#switchOver').fadeOut(2500, function() {

			$('#containerMain').removeClass();

			$('#containerMain').addClass(initiativeClasses[initiativeNo]);

			for (var i = 0; i < initiatives.length; i++) {

				if (i == initiativeNo) {

					$('.' + initiativeShow[i]).css('display', 'block');
					$('.' + initiativeShow[i]).find('div').css('display', 'block');

				} else {

					$('.' + initiativeShow[i]).css('display', 'none');
					$('.' + initiativeShow[i]).find('div').css('display', 'none');
				}

			}

			if (initiativeNo == 0) {

				$('#prevUrl').attr('href', initiatives[initiatives.length - 1]);
				$('#nextUrl').attr('href', initiatives[1]);
				initiativeNo = 1;

			} else if (initiativeNo == initiatives.length -1) {

				$('#prevUrl').attr('href', initiatives[initiativeNo - 1]);
				$('#nextUrl').attr('href', initiatives[0]);
				initiativeNo = 0;

			} else {

				$('#prevUrl').attr('href', initiatives[initiativeNo - 1]);
				$('#nextUrl').attr('href', initiatives[initiativeNo + 1]);
				initiativeNo = initiativeNo + 1;

			}

			$('#switchOver').fadeIn(2500, function() {
				fixMicroSiteLoadSifr();
			});

		});

	};

	//var anim = setInterval (autoAnimateInitiatives, 7000);

	$('.animationPause').click(function() {

		if (isPlaying) {

			clearInterval (anim);
			$('.animationPause').html('> Play');
			$('.animationPause').attr('title', '> Play');
			isPlaying = false;

		} else {

			anim = setInterval (autoAnimateInitiatives, 7000);
			$('.animationPause').html('II Pause');
			$('.animationPause').attr('title', 'II Pause');
			isPlaying = true;

		}

		return false;

	});

	$('.animation').click(function() {


		clearInterval (anim);
		$('.animationPause').html('> Play');
		$('.animationPause').attr('title', '> Play');
		isPlaying = false;

		return false;

	});

});
