var imageCount = 0;
var number = 0;

function rotate() 
	{
		if (imageCount == 0) {
                           $('#secondChoiceImg').addClass('selected').attr(
				"src", "js/images/button_dot_w.png"
                           )
                           $('#firstChoiceImg').removeClass('selected').attr(
				"src", "js/images/button_dot_b.png"
                           )
			imageCount++;
		} else if (imageCount == 1) { 
                           $('#thirdChoiceImg').addClass('selected').attr(
				"src", "js/images/button_dot_w.png"
                           )
                           $('#secondChoiceImg').removeClass('selected').attr(
				"src", "js/images/button_dot_b.png"
                           )
			imageCount++;
		} else { 
                           $('#firstChoiceImg').addClass('selected').attr(
				"src", "js/images/button_dot_w.png"
                           )
                           $('#thirdChoiceImg').removeClass('selected').attr(
				"src", "js/images/button_dot_b.png"
			   )
			imageCount = 0;
		}
	}	
	
var t;

function startRotation(stop, start) 
	{
		if (!stop) 
		{
			if (start) {

t = setTimeout("startRotation(false, false)", 7000);
				
			} else {
				rotate();
				t = setTimeout("startRotation(false, false)", 7000);
			}
		} else {
			clearTimeout(t);
			return;
		}
	}	 
	
function stopRotation()
	{
		startRotation(true);
	}

function dot_functions()
{
			$('#firstChoiceImg').hover(function()
							{
								$('#firstChoiceImg').attr(
									"src", "js/images/button_dot_w.png"
								)
							}, function()
							{
								if (!$(this).hasClass('selected')) {
									$('#firstChoiceImg').attr(
										"src", "js/images/button_dot_b.png"
									)
								}								
			});
			$('#secondChoiceImg').hover(function()
							{
								$('#secondChoiceImg').attr(
									"src", "js/images/button_dot_w.png"
								)
							}, function()
							{
								if (!$(this).hasClass('selected')) {
									$('#secondChoiceImg').attr(
										"src", "js/images/button_dot_b.png"
									)
								}
			});
			
			$('#thirdChoiceImg').hover(function()
							{
								$('#thirdChoiceImg').attr(
									"src", "js/images/button_dot_w.png"
								)
							}, function()
							{
								if (!$(this).hasClass('selected')) {
									$('#thirdChoiceImg').attr(
										"src", "js/images/button_dot_b.png"
									)
								}
			});
			$('#firstChoiceImg').click(function()
				{
					stopRotation();
					$('.slideshow').cycle('stop');
					$(this).addClass('selected').attr(
						"src", "js/images/button_dot_w.png"
					)
					$("#secondChoiceImg").removeClass('selected').attr(
						"src", "js/images/button_dot_b.png"
					)
					$("#thirdChoiceImg").removeClass('selected').attr(
						"src", "js/images/button_dot_b.png"
					)
					$('.mainPicture:eq(2)').css(
					{
						"display": "none",
						"opacity": "0"
					})
					$('.mainPicture:eq(1)').css(
					{
						"display": "none",
						"opacity": "0"
					})
					$('.mainPicture:eq(0)').css(
					{
						"display": "inline",
						"opacity": "1"
					})
				});		
			$('#secondChoiceImg').click(function()
				{
					stopRotation();
					$('.slideshow').cycle('stop');
					$(this).addClass('selected').attr(
						"src", "js/images/button_dot_w.png"
					)
					$("#firstChoiceImg").removeClass('selected').attr(
						"src", "js/images/button_dot_b.png"
					)
					$("#thirdChoiceImg").removeClass('selected').attr(
						"src", "js/images/button_dot_b.png"
					)
					$('.mainPicture:eq(0)').css(
					{
						"display": "none",
						"opacity": "0"
					})
					$('.mainPicture:eq(2)').css(
					{
						"display": "none",
						"opacity": "0"
					})
					$('.mainPicture:eq(1)').css(
					{
						"display": "inline",
						"opacity": "1"
					})
				});
			$('#thirdChoiceImg').click(function()
				{
					stopRotation();
					$('.slideshow').cycle('stop');
					$(this).addClass('selected').attr(
						"src", "js/images/button_dot_w.png"
					)
					$("#firstChoiceImg").removeClass('selected').attr(
						"src", "js/images/button_dot_b.png"
					)
					$("#secondChoiceImg").removeClass('selected').attr(
						"src", "js/images/button_dot_b.png"
					)
					$('.mainPicture:eq(0)').css(
					{
						"display": "none",
						"opacity": "0"
					})
					$('.mainPicture:eq(1)').css(
					{
						"display": "none",
						"opacity": "0"
					})
					$('.mainPicture:eq(2)').css(
					{
						"display": "inline",
						"opacity": "1"
					})
				});

}
$(document).ready(function() {
    $('.slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:7000
	});
    $('.newsslideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
    startRotation(false, true);
    dot_functions();
});

