// JavaScript Document
$(document).ready(function() {
	CreateList();
	
});
function CreateList(){

var IndexGallery = [];
var LastImage = 0;
var CurRightIm = 0;

LastImage = $('.gallery_body ul').children().length - 1;


if(LastImage>2){
	$('.gallery_body li').each(function(index){
		IndexGallery[index]=$(this).html();
	});
	$('.gallery_body ul').remove();
	
	GalleryList = '';
	for(i=0;i<4;i++){
		GalleryList = GalleryList + IndexGallery[i];
	};
	$('.gallery_body').html(GalleryList);
	
	$('.gallery_navigate img').show();
	CurRightIm=3;
}
// right click
$('.nav_right').click(function(){
	
	RightImageWidth=0;
	$('.gallery_body img').eq(0).stop(true,true);
	$('.gallery_body img').eq(4).stop(true,true);
	if(CurRightIm<LastImage) CurRightIm++;
	else CurRightIm = 0;
	$('.gallery_body').append(IndexGallery[CurRightIm]);
	RightImageWidth=$('.gallery_body img').eq(4).width();
	$('.gallery_body img').eq(4).css({
		width:0,
		height:170
	});
	$('.gallery_body img').eq(0).animate({
		width:0},function(){$(this).remove();});
	$('.gallery_body img').eq(4).animate({
		width:RightImageWidth});
});	
// left click
$('.nav_left').click(function(){
	LeftImageWidth=0;
	$('.gallery_body img').eq(0).stop(true,true);
	$('.gallery_body img').eq(4).stop(true,true);
	if(CurRightIm>4) CurRightIm--;
	else CurRightIm = LastImage+4;
	$('.gallery_body').prepend(IndexGallery[CurRightIm-4]);
	LeftImageWidth=$('.gallery_body img').eq(0).width();
	$('.gallery_body img').eq(0).css({
		width:0,
		height:170
	});
	$('.gallery_body img').eq(0).animate({
		width:LeftImageWidth});
	$('.gallery_body img').eq(4).animate({
		width:0},function(){$(this).remove();});
});	
	
	
}

