// JavaScript Document

function scrollWin(target)
{
	//console.log('scrolling to '+target);
	$('html, body').animate({
		scrollTop: $(target).offset().top
	}, 1000);
	
	return false;
}

function loadSection(target)
{
	//console.log('changing section to '+target);
	if(target == 'introduction')
	{
		var xLocation = '300px';
		var xWidth = '15px';
	}
	$(this).parent().find('.navbar').animate( { width: xWidth, marginLeft: xLocation }, 500 )
	
	return false;
}

function NavBar(el)
{
	function _hide()
	{
		$(el).hide();
	}
	function _show()
	{
		$(el).fadeIn("slow");
	}
	this.Hide = _hide;
	this.Show = function()
	{
		_hide();
		if(selected == $(el).attr('id'))
		{
			_show();
		}
	}
}

function Testimonial(el)
{
	//console.log($(el).attr('id'));
	function _hide()
	{
		$(el).hide();
	}
	function _show()
	{
		$(el).fadeIn("slow");
	}
	this.Hide = _hide;
	this.Show = _show;
}

var selected;
var currentTestimonial = 0;

var testimonials = [];

var allWhoItems = [];
var allWhereItems = [];

function HideAllWho()
{
	for(var i = 1; i < allWhoItems.length; i++)
	{
		allWhoItems[i].Hide();
	}
}

function HideAllWhere()
{
	for(var i = 1; i < allWhereItems.length; i++)
	{
		allWhereItems[i].Hide();
	}
}

function HideAndShowWho()
{
	for(var i = 0; i < allWhoItems.length; i++)
	{
		allWhoItems[i].Show();
	}
	return false;
}

function HideAndShowWhere()
{
	for(var i = 0; i < allWhereItems.length; i++)
	{
		allWhereItems[i].Show();
	}
	return false;
}

function HideAllTestimonials()
{
	for(var i = 0; i < testimonials.length; i++)
	{
		testimonials[i].Hide();
	}
}

function HideAndShowTestimonials()
{
	//console.log('HideAndShow');
	for(var i = 0; i < testimonials.length; i++)
	{
		if(currentTestimonial == i)
		{
			//console.log('showing '+i);
			testimonials[i].Show();
		}
		else
		{
			testimonials[i].Hide();
		}
	}
}

function RightArrow()
{
	//console.log('RightArrow');
	currentTestimonial = currentTestimonial + 1;
	if(currentTestimonial == testimonials.length)
	{
		currentTestimonial = 0;
	}
	HideAndShowTestimonials();
		
	return false;
}
function LeftArrow()
{
	//console.log(testimonials.length);
	currentTestimonial = currentTestimonial - 1;
	if(currentTestimonial < 0)
	{
		//console.log('less than 0');
		currentTestimonial = testimonials.length - 1;
	}
	HideAndShowTestimonials();
	
	return false;
}

$(document).ready(function()
{
	/*$('div#whoweare div#testimonials div.testimonial-container div.testimonial').each(function()
	{
		testimonials.push(new Testimonials($(this)));
	});*/
	$('#whoweare div.section').each(function()
	{
		allWhoItems.push(new NavBar($(this)));
	});
	$('#whereweare div.section').each(function()
	{
		allWhereItems.push(new NavBar($(this)));
	})
    //scrollWin('#wrapper');
	HideAllWho();
	HideAllWhere();
	//HideAllTestimonials();

});
