﻿//When adding photos, change the photoCount variable accordingly

var margin = 0;
var pageCount = 2;
var current = 1;
var selected = 1;

var colors = ['#fff', '#0067a5'];
var theText = $('div#flipper_text p');
var timer = 0;

jQuery(document).ready(function() {
	
	pageCount = descriptions.length/6;
	$('#gallery').width(678 * pageCount);
	selected = Math.floor(Math.random()*6) + 1;
	chosen(selected);
	
    $('#left-arrow').click(function(){
		previousPage();
	});
	
	$('#right-arrow').click(function(){
		nextPage();
	});
	
	$.each(descriptions, function(index, value){
			$('#item-'+index).click(function(){
				chosen(index);
			});
		});	
});

function previousPage(){
	if(current > 1){
		current--;
		margin = margin + 678;
	}
	flip();
}

function nextPage(){
	if(current < pageCount){
		current++;
		margin = margin - 678;
	}
	flip();
}

function flip(){
	$('#gallery').animate({marginLeft: margin + 'px'}, {duration:1000});
}

function chosen(index){
	$('#item-'+selected).css('border-color','cdcdcd');	
	selected = index;
	$('#item-'+index).css('border-color','cab990');
	$('#description p').text(descriptions[index]);
	$('#fadeArea').hide();	
	$('#fadeArea').fadeIn("slow");
	$('#selected-image img').attr('src',path+images[index]);	
	
}
