// JavaScript Document
$(function(){
	$(".arrow").hover(function(){
		$(this).addClass("op","slow")
	}, function(){
			$(this).removeClass("op");
	});
});

var photoScroll = {
	num: 0,
	timer: null,
	scroll: function(n){
		var $v_show = $('#photoScroll ul.act');
		var v_width = $v_show.find('li').width();
		var v_length = $v_show.find('li').length;
		var distance = 0;
		if (n === "-1"){
			i = this.num >0 ? this.num-1 : v_length-1;
		} else if (n === "+1"){
			i = this.num < (v_length-1) ? this.num+1 : 0;
		} else {
			i = n;
		}
		this.num = i;
		//$v_show.animate({left:-v_width*i},"slow");
		$v_show.find('li').hide();
		$v_show.find('li').eq(i).fadeIn('slow');
		$('#photoScroll .contentbottom2 span.current').removeClass('current');
		$('#photoScroll .contentbottom2 span').eq(i).addClass('current');
	},
	auto: function(){
		if (this.timer != null){
			clearTimeout(this.timer);
		}
		var scroll = function(){
			photoScroll.scroll("+1");
			photoScroll.timer = setTimeout(scroll,3000);
		}
		this.timer = setTimeout(scroll,3000);
	}
}

$(function(){
	$('#photoScroll ul.act li').hide();
	$('#photoScroll ul.act li').eq(0).show();
	$("#photoScroll div.forward").click(function(){
		photoScroll.scroll("-1");
		photoScroll.auto();
	});
	$("#photoScroll div.back").click(function(){
		photoScroll.scroll("+1");
		photoScroll.auto();
	});
	$("#photoScroll div.contentbottom2 span").each(function(i,n){
		$(n).click(function(){
			photoScroll.scroll(i);
			photoScroll.auto();
		});
	});
	photoScroll.auto();
});

/*
$(function(){
	var page=1
	var i=1
	$("div.back").click(function(){
		var $parent = $(this).parents("div.content");
		var $v_show = $parent.find("ul.act");
		var $v_content = $parent.find("div.height");
		var v_width = $v_content.width();
		var len = $v_show.find("li").length;
		var page_count = Math.ceil(len/i);
		if(!$v_show.is(":animated")){
			if(page == page_count){
				$v_show.animate({left:'0px'},"slow");
				page=1;
			}else{
				$v_show.animate({left:'-='+v_width},"slow");
				page++;
			}
		}


		  $parent.find("span").eq((page-1)).addClass("current")
                              .siblings().removeClass("current");
		  });

		   $("div.forward").click(function(){
								var $parent = $(this).parents("div.content");
								var $v_show = $parent.find("ul.act");
								var $v_content = $parent.find("div.height");
								var v_width = $v_content.width();
								var len = $v_show.find("li").length;
								var page_count = Math.ceil(len/i);

								if(!$v_show.is(":animated")){
									if(page == 1){
										$v_show.animate({left:'-='+v_width*(page_count-1)},"slow");
										page=page_count;
									}else{
										$v_show.animate({left:'+='+v_width},"slow");
										page--;
									}
		  }

		  $parent.find("span").eq((page-1)).addClass("current")
                              .siblings().removeClass("current");
		  });
});
*/
