var photoGallery = {
	
	_container: null,
	
	$: function(id) {
		return (document.getElementById) ? document.getElementById(id) : null ;
	},
	
	addEvent: function( o, e, f ) {
		if(typeof o == "object") {
			if( o.addEventListener ) o.addEventListener(e, f, false );
			else if( o.attachEvent ) o.attachEvent( 'on'+e , f);
		}
	},
	
	targ: function(e) {
		var targ;
		if (!e) e = window.event;
		if (e.target) {
			targ = e.target;
		} else if (e.srcElement) {
			targ = e.srcElement;
		}
		if (targ.nodeType == 3) {// defeat Safari bug
			targ = targ.parentNode;
		}
		return targ;
	},
	
	init: function(id) {
		this._container = this.$(id);
		if(!this._container) return;
		var elementGroup = this._container.getElementsByTagName("a");
		
		for( key in elementGroup ) {
			if( elementGroup[key].getAttribute ) {
				if( elementGroup[key].getAttribute("rel") == "photo" ) {					
					
					this.addEvent( elementGroup[key], "click", function(e) {
						var el = photoGallery.targ(e).parentNode;					
						if( el.getAttribute ) {
							photoGallery.show( el.getAttribute("href") );
						}
						
						if (e.stopPropagation) e.stopPropagation();
						else e.cancelBubble = true;
				
						if (e.preventDefault) e.preventDefault();
						else e.returnValue = false;
						
						return false;
						
					} );
				}
			}
		}
		
	},
	
	show: function(src) {
		var container = photoGallery.$('image');
		var img = container.getElementsByTagName("img")[0];
		
		new Fx(img).fadeOut(function() {
			for( key in container.childNodes ) {
				if(container.firstChild) {
					container.removeChild(container.firstChild);
				}
			}
			var img = document.createElement("img");
			var myFx = new Fx(img);
			img.setAttribute("src", src);
			img.setAttribute("alt", src);
			myFx.set(0);
			container.appendChild(img);
			myFx.fadeIn();
		});
	}
}