$(document).ready(function()
{

	// Home page
	if($('div.intro').length > 0)
	{					
		el = $('div.intro-1');
		direction = 'rtl';
		thecount = 1;
		
		intro_animation();
	}
	

	// Content pages
	if($('div.text').length > 0)
	{
		top_pos = $('div.text').css('top');
		the_height = $('div.text').outerHeight() + 10;
		$('div.text-inner').hide();
		
		if(top_pos == '0px')
		{
			$('div.text').
				css('top', '-' + the_height + 'px').
				delay(2000).
				animate(
					{top: '0px'},
					{duration: 1000, complete: function()
					{
						$('div.text-inner').show().animate(
							{opacity:0},
							{duration:0, complete: function()
							{
								$('div.text-inner').jScrollPane(
								{
									showArrows: true,
									scrollbarWidth: 12,
									scrollbarMargin: 30
								});
								$('div.text-inner').animate({opacity:1}, 1000)
							}}
						)
					}}
				);
		}
		else
		{
			$('div.text').
				css('bottom', '-' + the_height + 'px').
				delay(2000).
				animate(
					{bottom: '0px'},
					{duration: 1000, complete: function()
					{
						$('div.text-inner').show().animate(
							{opacity:0},
							{duration:0, complete: function()
							{
								$('div.text-inner').jScrollPane(
								{
									showArrows: true,
									scrollbarWidth: 12,
									scrollbarMargin: 30
								});
								$('div.text-inner').animate({opacity:1}, 1000)
							}}
						)
					}}
				);
		}
	}
		
});


function intro_animation()
{
	$(el).show();
	$("div, p", el).removeAttr('style');
	
	var topWidth = $("div.line-top", el).css('width');
	var bottomWidth = $("div.line-bottom", el).css('width');
	var textWidth = parseInt($("p", el).css('width'));
	var textLeft = parseInt($("p", el).css('left'));

	if(direction == 'ltr')
	{
		$("div.line-top", el).css('width', '0');
		$("div.line-bottom", el).css('width', '0');
		$("p", el).css('left', '-' + (textWidth + textLeft) + 'px');
	}
	else
	{
		$("div.line-top", el).css('right', '-' + topWidth );
		$("div.line-bottom", el).css('right', '-' + bottomWidth);
		$("p", el).css('left', '900px');
	}
	
	
	$(el).hide().fadeIn(2000, function() //speed of white bg fade-in
	{
		if(direction == 'ltr')
		{
			$("p", el).animate({ left: textLeft }, { duration: 2000, complete: function() // speed of slide in from left
			{
				setTimeout(function()
				{
					$('div.intro-block', el).animate({ right: '900px' }, { duration: 1000 }); // speed out slide out to left
					$(el).fadeOut(1500, function(){ intro_close(); }); // speed of fade out during left hand text
				}, 3000) // length of time that slide displays
			}});
		}
		else
		{
			$("p", el).animate({ left: textLeft }, { duration: 2000, complete: function() // speed of slide in from right
			{
				setTimeout(function()
				{
					$('div.intro-block', el).animate({ left: '900px' }, { duration: 1000 });
					$(el).fadeOut(1500, function() { intro_close(); });
				}, 3000) // length of time that slide displays
			}});
		}
	});
};
	
	
function intro_close()
{
	switch(thecount)
	{	
		case 1:
			el = $('div.intro-2');
			direction = 'ltr';
			thecount = 2;
			intro_animation();
			break;
		case 2:
			el = $('div.intro-3');
			direction = 'rtl';
			thecount = 3;
			intro_animation();
			break;			
		case 3:
			el = $('div.intro-4');
			direction = 'ltr';
			thecount = 4;
			intro_animation();
			break;	
		case 4:
			el = $('div.intro-5');
			direction = 'rtl';
			thecount = 5;
			intro_animation();
			break;	
		case 5:
			el = $('div.intro-1');
			direction = 'l';
			thecount = 1;
			intro_animation();
			break;	
	}
}
