//When adding photos, change the photoCount variable accordingly

var margin = 0;
var photoCount = 2;
var current = 1;
var upperText = ['We can do it & we can do it anywhere.', 'We can do it & we can do it anywhere.'];
var bottomText = [
	'In the world of industrial electrical and instrumentation, our long-term committed employees, award-winning safety and quality programs, exceptional project controls and our ability to work all over the country, make us the perfect choice for your next project.',
	'In the world of industrial electrical and instrumentation, our long-term committed employees, award-winning safety and quality programs, exceptional project controls and our ability to work all over the country, make us the perfect choice for your next project.'
];
var colors = ['#fff', '#0067a5'];
var theText = $('div#flipper_text p');
var timer = 0;

jQuery(document).ready(function() {
	
	updateText();
	
    $('#prev').click(function(){
		previousPhoto();
	});
	
	$('#next').click(function(){
		nextPhoto();
	});
	
	setTimer();
});

function previousPhoto(){
	setTimer();
	if(current > 1){
		current--;
		margin = margin + 940;
	}
	else{
		current = photoCount;
		margin = -940 * (photoCount - 1);
	}
	transition();
}

function nextPhoto(){
	setTimer();
	if(current < photoCount){
		current++;
		margin = margin - 940;
	}
	else{
		current = 1;
		margin = 0;
	}
	transition();
}

function transition(){
	$('div#flipper_text p').hide();
    flip();

	
}

function flip(){
	$('#image_flipper').animate({marginLeft: margin + 'px'}, 300, function() {
    updateText();
  });
}

function updateText(){
	$('div#flipper_text p').css('color', colors[current-1]);
	$('div#flipper_text p#top').text(upperText[current-1]);
	$('div#flipper_text p#bottom').text(bottomText[current-1]);
	$('div#flipper_text p').show();
}

function setTimer(){
	if(timer)
		clearInterval(timer);
	timer = setInterval('nextPhoto()', 13000);
}
