// JavaScript Document

var $j = jQuery.noConflict();

$j(function(){
	//alert('home')
	var homeSlideSpeed = 3000;
	var delayTime = 6000;
	var slideCount = 0;
	var slide = 1;
	var activeSlide = 1;
	var clicked = false;
	var stopAnimation = false;
	

	$j(document).ready(function(){		
		$j("#slide2").hide();
		$j("#slide3").hide();
		$j("#slide4").hide();
		
		document.getElementById('box1').style.backgroundColor = '#f9d239';
		automate();
	});



	// function to set automation timer
	var animationTimer = '';
	function automate(change){
		animationTimer = window.setTimeout(function() { doSlide(); }, delayTime); // set time
	};

	

	function doSlide(){
		if (activeSlide <= 3){
			what = parseInt(activeSlide)+1;
		} else {
			what = 1;
		}
		$j('#slide'+activeSlide).fadeOut(homeSlideSpeed);
		$j('#slide'+what).fadeIn(homeSlideSpeed);
		
		changeColor(what);
		activeSlide = what;
		automate();
	}

	function hideAll(what){
		if (activeSlide != what){
			$j('#slide'+activeSlide).fadeOut(homeSlideSpeed);
			$j('#slide'+what).fadeIn(homeSlideSpeed, function (){ clicked = false; automate(); });
			activeSlide = parseInt(what);
		}
	}

	
	
	$j("#box1").click(function () {
		if (clicked != true){
			clicked = true
			window.clearTimeout(animationTimer);
			slideCount = 1;
			changeColor('1');
			hideAll('1');
		}
	});

	$j("#box2").click(function () {
		if (clicked != true){
			clicked = true
			window.clearTimeout(animationTimer);
			changeColor('2');
			hideAll('2');
		}
	});

	$j("#box3").click(function () {
		if (clicked != true){
			clicked = true
			window.clearTimeout(animationTimer);
			changeColor('3');
			hideAll('3');
		}
	});

	$j("#box4").click(function () {
		if (clicked != true){
			clicked = true
			window.clearTimeout(animationTimer);
			changeColor('4');
			hideAll('4');
		}
	});

	

	function changeColor(Value){
		document.getElementById('box1').style.backgroundColor = '#3c529a';
		document.getElementById('box2').style.backgroundColor = '#3c529a';
		document.getElementById('box3').style.backgroundColor = '#3c529a';
		document.getElementById('box4').style.backgroundColor = '#3c529a';
		document.getElementById('box'+Value).style.backgroundColor = '#f9d239';

	};



});
