/**
* class Slide
* TODO add load handler
*/
var Slide = Class.create({
	initialize: function(parent, src) {
	
		this.id = '' + new Date().getTime() + Math.round(Math.random()*1000);
		this.parent = parent;
		
		this.wrapper = this.parent.appendChild($(Builder.node('div',{id:this.id}))); // to position absolute
		this.innerwrapper = this.wrapper.appendChild($(Builder.node('div'))); // to position relative
		this.wrapper.absolutize();
		this.wrapper.setStyle({
			'left':'0px',
			'top':'0px',
			'width':'auto'
		});
//		this.innerwrapper.relativize();

		this.image = new Image();
		this.image = $(this.image);
		this.image.src = src;
		this.image.setStyle({
			'opacity':'0'
		});
		//this.image.hide();
		this.width = this.image.width;
		this.height = this.image.height;
		this.innerwrapper.appendChild(this.image);
		this.duration = 1;
	},
	
	appear: function() {
		new Effect.Appear(this.image, {duration:this.duration,queue: { position: 'end', scope: this.id, limit: 2 }});
	},
	
	fade: function() {
		new Effect.Fade(this.image, {duration:this.duration,queue: { position: 'end', scope: this.id, limit: 2 }});
	},
	
	show: function() {
		new Effect.Appear(this.image, {duration:0.01,queue: { position: 'end', scope: this.id, limit: 2 }});
	},
	
	hide: function() {
		new Effect.Fade(this.image, {duration:0.01,queue: { position: 'end', scope: this.id, limit: 2 }});
	},
	
	switchoff: function() {
		new Effect.SwitchOff(this.image, {duration:this.duration,queue: { position: 'end', scope: this.id, limit: 2 }});
	},
	
	/* repair later; use wrapper div
	slidedown: function() {
		this.hide();
		new Effect.SlideDown(this.wrapper, {duration:this.duration,queue: { position: 'end', scope: this.image.src }});
	},
	
	slideup: function() {
		this.show();
		new Effect.SlideUp(this.wrapper, {duration:this.duration,queue: { position: 'end', scope: this.image.src }});
	},

	grow: function() {
		new Effect.Grow(this.image, {duration:this.duration});
	},
	
	shrink: function() {
		new Effect.Shrink(this.image, {duration:this.duration});
	},*/
	
	setDuration: function(duration) {
		this.duration = duration;
	},

	setSize: function(w, h) {
		// find smallest factor
		var factW = w/this.image.getWidth();
		var factH = h/this.image.getHeight();
		var factor = factW>factH?factH:factW;
		if (factor<1) {
			this.image.setStyle({
				'width': (this.image.width * factor) + 'px',
				'height': (this.image.height * factor) + 'px'});
		}
	},
	
	positionedOffset: function() {
		return this.image.positionedOffset();
	},
	
	getWidth: function() {
		return this.image.width;
	},
	
	getHeight: function() {
		return this.image.height;
	},
	
	setPosition: function(x, y) {
		this.wrapper.setStyle({
			'left':x + 'px',
			'top':y + 'px'
		});
	}	
});








