var Photo = {};
Photo.Slider = {
	imgPath : 'img/',
	thumbPath : 'thumb.php?link=',
	sliderContainer:'#img_slider_container',
	slider:"#img_slider",
	prevImg:"#prev_img",
	mainImg:"#main_img",
	sliderWidth:0,
	sliderContainerWidth:0,
	imageWidths: Array(),
	images : {},
	sliderConstants:0,
	currSlide:1,
	offset:0,
	start:function(){
		$("#leftArrow,#rightArrow").css("visibility","visible");
		this.sliderContainerWidth = $(this.sliderContainer).width();
		for (i=0;i<$(this.slider+" img").length;i++){
			this.images[i] = document.createElement('img');
			this.images[i].src = $(this.slider+" img").eq(i).attr("src").replace(Photo.Slider.thumbPath,Photo.Slider.imgPath);
			$(this.slider+" img").eq(i).click(function(e){
//				var offset = (e.pageX - $(Photo.Slider.sliderContainer).offset().left) * (Photo.Slider.sliderWidth-Photo.Slider.sliderContainerWidth) / Photo.Slider.sliderContainerWidth;
//			    $(Photo.Slider.slider).animate({left:(-offset)}, 1000);
				$(Photo.Slider.mainImg).css("display","none");
				$(Photo.Slider.mainImg).attr("src",(this.src.replace(Photo.Slider.thumbPath,Photo.Slider.imgPath)));
				$(Photo.Slider.mainImg).fadeIn(1000,function(){
					$(Photo.Slider.prevImg).attr("src",$(Photo.Slider.mainImg).attr("src"));
				});
			});
			this.imageWidths[i]=$(this.slider+" img").eq(i).width();
			this.sliderWidth+=this.imageWidths[i];
		}
		this.sliderConstants = (Photo.Slider.sliderWidth-Photo.Slider.sliderContainerWidth) /Photo.Slider.sliderWidth;
		Photo.Slider.offset=Photo.Slider.imageWidths[0];
	},
	moveSlides:function(direction){
		Photo.Slider.offset =  parseInt($(Photo.Slider.slider).css("left"));
		if (direction ==1){
			Photo.Slider.offset -=  (Photo.Slider.sliderContainerWidth-50);
			if (Photo.Slider.offset<(-Photo.Slider.sliderWidth+Photo.Slider.sliderContainerWidth)) Photo.Slider.offset=(-Photo.Slider.sliderWidth+Photo.Slider.sliderContainerWidth);
		}else {
			Photo.Slider.offset +=  (Photo.Slider.sliderContainerWidth-50);
			if (Photo.Slider.offset>0) Photo.Slider.offset=0;
		}
		$(Photo.Slider.slider).animate({left:(Photo.Slider.offset)}, 700);
	},
	animate:function(){
		if (this.currSlide<$(this.slider+" img").length){
			$("#leftArrow,#rightArrow").css("visibility","hidden");
			$(Photo.Slider.slider).animate({left:(-(this.offset+this.imageWidths[this.currSlide]/2)*this.sliderConstants)}, 1800);
			$(Photo.Slider.mainImg).css("display","none");
			$(Photo.Slider.mainImg).attr("src",this.images[this.currSlide].src);
			$(Photo.Slider.mainImg).fadeIn(1800,function(){
				$(Photo.Slider.prevImg).attr("src",$(Photo.Slider.mainImg).attr("src"));
				Photo.Slider.offset+=Photo.Slider.imageWidths[Photo.Slider.currSlide];
				Photo.Slider.currSlide++;
				Photo.Slider.animate();
			});
		} else {
			$("#leftArrow,#rightArrow").css("visibility","visible");
		}
	}
}