function animate()
{

	current_left = 0;
	current_top = 0;

	$('.simage').each(function() {
		
		new_left = current_left * 145 + 14;
		new_top = current_top * 145 + 14;
		
		$(this).animate({
			left: 	new_left,
			top:	new_top,
			height:	140,
			width:	140
		},
		3000);
		
		current_left = current_left + 1;
		if (current_left == 7)
		{
		
			current_left = 0;
			current_top = current_top + 1;
		
		}
		
	});

	setTimeout(function() {
		
		$('#image_container').animate({
			left: 	-14,
			top: 	160,
			height: 460,
			width: 1040
		}, 
		1200);
	
	}, 2000);

}

function enlarge_image(id)
{

	$('#img_'+id).css('z-index', '99');
	$('#img_'+id).css('border', '1px solid #CCC');
	$('#img_'+id).css('box-shadow', '2px 2px 5px #000');
	$('#img_'+id).css('background-position', 'center left');
	
	$('#img_'+id).animate({
		left: 	'-=10',
		top: 	'-=10',
		height: 160,
		width: 160,
	}, 
	'fast');	

}

function shrink_image(id)
{

	$('#img_'+id).css('z-index', '50');
	$('#img_'+id).css('border', '0px');
	$('#img_'+id).css('box-shadow', '');
	$('#img_'+id).css('background-position', 'center');
	
	$('#img_'+id).animate({
		left: 	'+=10',
		top: 	'+=10',
		height: 140,
		width: 140,
	},
	'fast');	

}

function change_page(direction)
{

	if (direction == 'up')
	{
		pagenum++;
	}

	if (direction == 'down')
	{
		pagenum--;
	}
	
	if (content_showing) { hide_content(); }
	
	if (pagenum > numpages) { pagenum = 1; }
	if (pagenum < 1) { pagenum = numpages; }
	
	offset = (pagenum - 1) * 21;

	$('#image_container').css('height', '430px');
	$('#image_container').css('width', '1010px');
	$('#image_container').css('left', '0px');
	$('#image_container').css('top', '174px');	
	
	$('.simage').each(function()
	{

		new_left = -150;
		new_top = -150;

		randomise = Math.floor(Math.random()*5);

		if (randomise == 1) { 

			new_left = -150;
			new_top = $(this).css('top');
			
		}

		if (randomise == 2) { 

			new_left = 1115;
			new_top = $(this).css('top');
			
		}

		if (randomise == 3) { 

			new_left = $(this).css('left');
			new_top = 480;
			
		}

		if (randomise == 4) { 

			new_left = $(this).css('left');
			new_top = -150;
			
		}

		$(this).animate({
			left: 	new_left,
			top: 	new_top,
			height: 140,
			width: 140
		}, 
		3000);

	});

	setTimeout(function() {
		
		$.ajaxSetup ({
			cache: false
		});
	
		var loadUrl = baseUrl + "home/ajax_images/"+offset;
		$("#image_container").html('<div id="loading"></div>').load(loadUrl, function() { 
		
			animate();
		
		});
				
	}, 3000);

}

function image_choose(id)
{
	
	doc_height = $(document).height();
	doc_width = $(document).width()
	
	loadUrl = baseUrl + "home/ajax_showimage/"+id;
	
	$("#image_show").html('<div id="loading"></div>').load(loadUrl, function() 
	{ 
		$('#current_image').height(doc_height-5);	
		if ($('#current_image').width() > doc_width) { $('#current_image').width(doc_width); }
	});
	
	$('#image_show').fadeIn(2000);

}

function image_hide()
{

	$('#image_show').fadeOut(3000);	

}

function image_showinfo()
{
	$('#image_info').fadeIn(1000);
}

function image_hideinfo()
{
	$('#image_info').fadeOut(1000);
}

function load_content(content)
{

	content_showing = true;

	loadUrl = baseUrl + 'home/show_content/' + content;

	$("#content_show").html('<div id="loading"></div>').load(loadUrl, function() 
	{ 
		$('#content_show').fadeIn(1000);
		$('#image_container').animate({ 
			width: 580,
			left: 430,
			opacity: 0.4
		}, 2000);
		
	});	
	
}

function hide_content()
{

	content_showing = false;

	$('#content_show').fadeOut(1000);
	$('#image_container').animate({ 
		width: 1040,
		left: -14,
		opacity: 1
	}, 1000);

}

function submit_contact()
{
	
	$.post(baseUrl+"home/contact_form", { name: $('#name').val(), email: $('#email').val(), company: $('#company').val(), phone: $('#phone').val(), message: $('#message').val() },
	   function(data) {
		
			$('#content_show').html(data);
		
	   });	

}
