SlideShow = function(images, extended, options) {
	this._data = images || [];
	this._extended = extended || [];
	YAHOO.lang.augmentObject(this, options || {}, true);
	// this.render();	
};
SlideShow.prototype = {
	_activeControls : false,
	extended : {},
	_data : [],
	rootNode : 'project_details',
	auto: {
		enabled: false,
		delay: 1000,
		_obj : null
	},
	render : function(){ YAHOO.log('No function <em>render</em> provided')},
	getIndex: function(el) {
		var current = false;
		if(!el)
			current = this.getCurrent() || this.getNext();
		else
			current = el;
		var _children = Dom.getChildren(this.rootNode);
		for (var i in _children) {
			if(_children[i] == current) {
				return parseInt(i);
			};
		};
		return false;
	},
	getSlideShowElement: function(index) {
		var elt = this._data[index];
		if(typeof(elt)!='string')
			return elt;
		else {
			var img = new Image();
			img.src = elt;
			return img;
		}
	},
	setControls: function() {
		Event.addListener('pause', 'click', this._pause, {}, this);
		Event.addListener('play', 'click', this._play, {}, this);
		Event.addListener('forward', 'click', this._forward, {}, this);
		Event.addListener('backward', 'click', this._backward, {}, this);
		Event.addListener(['pause', 'play'], 'click', this.onControlEvent, [true], this);
	},
	activateControls: function() {
		this._activeControls = true;
	},
	deactivateControls: function() {
		this._activeControls = false;
	},
	hasActiveControls: function() {
		return this._activeControls;
	},
	_play: function(force) {
		force = force || false;
		if(!this.hasActiveControls() && (force!= true)) return;
		if(!this.auto._obj) {
			this.auto._obj = YAHOO.lang.later(this.auto.delay, this, this._forward, null, true);
			this._forward();
		}
		if(YAHOO.env.ua.ie)
			this.onControlEvent.call(this, true)
	},
	_pause: function(force) {
		force = force || false;
		if(!this.hasActiveControls() && (force!= true)) return;
		if(this.auto._obj) {
			this.auto._obj.cancel();
			this.auto._obj = null;
		}
		if(YAHOO.env.ua.ie)
			this.onControlEvent.call(this, true)
	},
	_playPause: function(force) {
		force = force || false;
		if(!this.hasActiveControls() && (force!=true)) return;
		if(this.auto._obj)
			this._pause();
		else
			this._play();
	},
	onControlEvent: function(evt, force) {
		force = force || false;
		if(!this.hasActiveControls() && (force!= true)) return;
		YAHOO.log(this.auto._obj ? 'OK' : 'NOK')
		if(this.auto._obj) {
			Dom.setStyle(['play', 'pause_inactive'], 'display', 'none');
			Dom.setStyle(['play_inactive', 'pause'], 'display', '');
		}
		else {
			Dom.setStyle(['play_inactive', 'pause'], 'display', 'none');
			Dom.setStyle(['play', 'pause_inactive'], 'display', '');
		}
	},
	_forward: function(force) {
		force = force || false;
		if(!this.hasActiveControls() && (force!=true)) return;
		var _current = this.getCurrent();
		if(_current) {
			this.fade(_current);
		}
		this.appear(this.getNext());
	},
	_backward: function(force) {
		force = force || false;
		if(!this.hasActiveControls() && (force!=true)) return;
		var _current = this.getCurrent();
		if(_current) {
			this.appearBack(_current);
		}
		this.fadeBack(this.getPrevious());
	},
	appear: function() { YAHOO.log('No function <em>appear</em> provided')},
	fadeBack: function() { YAHOO.log('No function <em>fadeBack</em> provided')},
	appearBack: function() { YAHOO.log('No function <em>appearBack</em> provided')},
	fade: function() { YAHOO.log('No function <em>fade</em> provided')},
	getCurrent: function() {
		var _c = Dom.getElementsByClassName('selected', null, this.rootNode);
		return _c.length ? _c[0] : null;
	},
	getNext: function() {
		var _c = this.getCurrent();
		if(this.getCurrent()){
			var _p = Dom.get(_c).parentNode;
			if(Dom.getLastChild(_p)==_c)
				return Dom.getFirstChild(this.rootNode);
			else
				return Dom.getNextSibling(_c);
		}
		else
		  return Dom.getFirstChild(this.rootNode);
	},
	getPrevious: function() {
		var _c = this.getCurrent();
		if(this.getCurrent()){
			var _p = Dom.get(_c).parentNode;
			if(Dom.getFirstChild(_p)==_c)
				return Dom.getLastChild(this.rootNode);
			else
				return Dom.getPreviousSibling(_c);
		}
		else
		  return Dom.getLastChild(this.rootNode);
	}
};
