$(function(){
	$(".photogallery").each(function(){
		var photoGalleryModule = new PhotoGalleryModule(this)
	})
})

var PhotoGalleryModule = function(){
	this._container = null;
	this.initialize.apply(this, arguments);
}

PhotoGalleryModule.prototype = {
	initialize: function(container) {
		this._container = container;
		this.selected_id = 0;
		this.init();
    },
	init: function() {
		var ref = this;
		var my_id = -1;
		
		$(".photogallery_navi ul li",$(this._container)).each(function(){
			$(this).attr("my_id",++my_id);
			$(this).css({
				
			});
			$(this).mouseover(function(){
				ref.selectOnCSS($(this));
			});
			$(this).mouseout(function(){
				ref.selectOffCSS($(this));
			});
			var ref_li = $(this);
			$("a", $(this)).click(function(){
				ref.changeSelected(ref_li.attr("my_id"));
				$(".photogallery_main img:last",$(ref._container)).after("<img src='"+$(this).attr("href")+"' alt=''>");
				$(".photogallery_main img:last",$(ref._container)).fadeTo(0,0);
				$(".photogallery_main img:last",$(ref._container)).fadeTo(1000,1, function(){
					$(".photogallery_main img:first",$(ref._container)).fadeOut(0,function(){
			            $(this).remove()
			        });	
				});
		        return false;
			})
		})
		this.changeSelected(0);
		this.start();
    },
	changeSelected: function(id){
		var prevObj = $(".photogallery_navi ul li:eq("+this.selected_id+")",$(this._container));
		this.selected_id = id;
		this.selectOffCSS(prevObj);
		this.selectOnCSS($(".photogallery_navi ul li:eq("+id+")",$(this._container)));
	},
	selectOnCSS :function(obj){
		obj.css({
			border:"1px solid #cccccc"
		});
	},
	selectOffCSS :function(obj){
		if(obj.attr("my_id") != this.selected_id){
			obj.css({
				border:"1px solid #ffffff"
			});
		}
	},
	start: function() {
		this.setNewImage();
		var ref = this;	
		//setInterval(function(){ref.setNewImage();}, 5000);
	},
	setNewImage: function() {
	}
};
