/*
	photoframe.js
	used scriptaculous (script.aculo.us/)
*/

/*	photo frame function
-----------------------------------------------
Win ie5.5,6.0,7.0 ns8.XX opera9 firefox
Mac Safari
Other browser is loaded "photoframe02.js";
*/
active = false;
PF = Class.create();
PF.prototype = {
	initialize: function(imgName) {
		if(active) return false;
		active = true;
		this.id = imgName;
		this.oldP = $$("#pictcol p")[0];
		this.loadimg = new Image();
		//this.loadimg.src = imgPath + this.id;
		this.loadimg.src = imgName;
		if(this.loadimg.complete){
			this.showImg();
		}else{
			if(navigator.userAgent.indexOf("Safari") != -1) {
				this.safariOnLoad = function(){
					if(this.loadimg.complete) {
						clearTimeout(this.timer);
						this.showImg();
					}else{
						this.timer = setTimeout(this.safariOnLoad.bind(this), 100);
					}
				}
				this.safariOnLoad();
			}else{
				try {
					Event.observe(this.loadimg, 'load', this.showImg.bind(this), false);
				} catch (e) {}
			}
		}
	},
	showImg: function(){
		var self = this;
		new Effect.Fade(self.oldP,{
			duration: 0.5,
			afterSetup: function() {
				id = self.id.match(/([^.jpg]+)/ig)[0];
				str = "<p id=\"" + id + "\"><img src=\"" + self.loadimg.src + "\"></p>";
				new Insertion.Top($("pictcol"),str);
				$(id).style.display = "none";
			},
			afterFinish: function() {
				new Effect.Appear($(id),{
					duration: 0.5,
					afterFinish: function() {
						active = false;
					}
				});
			}
		});
	}
}
