$(function(){
		var gallery = new Object();

		eval("gallery.sites = new Array("+$('.gallery').attr('img')+")");
		
		gallery.gray = $('.gallery .bottom .gray');
		gallery.top = $('.gallery .top');

		gallery.active = $();
		gallery.steps = 0;
		
		eval("gallery.controls = "+$('.gallery').attr('scroll'));
		eval("gallery.sizes =  new Array("+$('.gallery').attr('sizes')+")");
		
		if(gallery.controls){
			gallery.left = $('<div></div>').css({
				position:'absolute',
				left:'18px',
				top:'53px',
				width:'36px',
				height:'46px',
				cursor:'pointer'
			}).appendTo(gallery.gray).hover(function(){
				gallery.gray.css('background-position','0px -97px');
			},function(){
				gallery.gray.css('background-position','0px 0px');
			}).click(function(){
				if(gallery.steps>0){
					gallery.steps--;
					gallery.target = $('.gallery .bottom .gray .window .wide img:eq('+gallery.steps+')');
					$('.gallery .bottom .gray .window .wide img').animate({
						left:'-'+gallery.target.data('left')+'px'
					},800);
				}
			});
	
			gallery.right = $('<div></div>').css({
				position:'absolute',
				left:'767px',
				top:'53px',
				width:'36px',
				height:'46px',
				cursor:'pointer'
			}).appendTo(gallery.gray).hover(function(){
				gallery.gray.css('background-position','0px -194px');
			},function(){
				gallery.gray.css('background-position','0px 0px');
			}).click(function(){
				if(gallery.steps<(gallery.sites.length - 1)){
					gallery.steps++;
					gallery.target = $('.gallery .bottom .gray .window .wide img:eq('+gallery.steps+')');
					$('.gallery .bottom .gray .window .wide img').animate({
						left:'-'+gallery.target.data('left')+'px'
					},800);
				}
			});		
		}
		
		gallery.counter = 0;
		
		$(gallery.sites).each(function(){
			gallery.sizeInfo = gallery.sizes[gallery.counter].split("x");
			gallery.full = $('<div></div>').css({'position':'absolute','top':'0px','left':'0px','text-align':'center','width':'820px','height':'670px'}).appendTo(gallery.top);
			gallery.img = $('<img/>').attr('src','img/gallery/'+this+'_full.jpg').css('display','none').appendTo(gallery.full);			
			gallery.thumb = $('<img/>').attr('src','img/gallery/'+this+'_thumb.jpg').width(gallery.sizeInfo[0]+'px').height(gallery.sizeInfo[1]+'px').appendTo('.gallery .bottom .gray .window .wide').data('full',gallery.full);

			gallery.thumb.bind('click',function(){
				if($(this).get(0) != gallery.active){

					$(gallery.active).colorChange({
						bgTo:'#cbced0',
						bgFrom:'#b6babd',
						duration:500
					});
						
					$(this).colorChange({
						bgFrom:'#cbced0',
						bgTo:'#b6babd',
						duration:500
					});

					gallery.newImg = $(this).data('full');
					
					gallery.newImg.appendTo(gallery.top);
					
					gallery.top.children().not(gallery.newImg).find('img').fadeOut(800,function(){
						gallery.newImg.find('img').fadeIn(800);
					});
										
					
					gallery.active = $(this).get(0);
				}
			}).hover(function(){
				if($(this).get(0) != gallery.active){
					$(this).colorChange({
						bgFrom:'#cbced0',
						bgTo:'#b6babd',
						duration:300
					});
				}
			},function(){
				if($(this).get(0) != gallery.active){
					$(this).colorChange({
						bgTo:'#cbced0',
						bgFrom:'#b6babd',
						duration:300
					});
				}
			});
			gallery.counter++;
		});

		$('.gallery .bottom .gray .window .wide img').each(function(){
			gallery.location = $(this).position();
			$(this).data('left',gallery.location.left);
		});
		
		$('.gallery .bottom .gray .window .wide img:first').click();
	});