/**
 * @class Třída modulu mmReference
 * @param {object} tabs objekt RISE.Tab
 * @param {string} legend Text na záložce
 * @param {string} idContent ID obsahu záložky
 * @constructor
 */
RISE.MmReference = SZN.ClassMaker.makeClass({
	NAME: "MmReference",
	VERSION: "1.0",
	CLASS: "class"
});
RISE.MmReference.prototype.$constructor = function(id) {
	this.id = id;
	this.rfs = [];
	this.steptime = 7000;
	this.actual = false;
	this.slideInterval = false;
	this.eventsCache = [];
	this.eventsCache.push(SZN.Events.addListener(window,"unload",this,"$destructor",false,true));
	this.prevButt = SZN.gEl(this.id+'-prev');
	this.nextButt = SZN.gEl(this.id+'-next');
	this.eventsCache.push(SZN.Events.addListener(this.nextButt,"click",this,"next",false,true));
	this.eventsCache.push(SZN.Events.addListener(this.prevButt,"click",this,"prev",false,true));
	//this.eventsCache.push(SZN.Events.addListener(SZN.gEl("references"),"mousewheel",this,"wheel",false));
	//this.eventsCache.push(SZN.Events.addListener(SZN.gEl("references"),"DOMMouseScroll",this,"wheel",false));
}
RISE.MmReference.prototype.$destructor = function() {
	for (var i=0;i<this.eventsCache.length;i++) {
		SZN.Events.removeListener(this.eventsCache[i]);
	}
	for (var p in this) { this[p] = null; }
}
RISE.MmReference.prototype.add = function(idReference) {
	var ref = SZN.gEl(idReference);
	if(ref){
		this.rfs.push(ref);
		/*
		var image = new Image();
		image.src = ref.style.backgroundImage;
		*/
	}
}
RISE.MmReference.prototype.start = function() {
	if(this.rfs.length>0 && !this.slideInterval){
		mThis = this;
		this.slideInterval = setInterval(function(){mThis.next()},this.steptime);
	}
}

RISE.MmReference.prototype.stop = function() {
	clearInterval(this.slideInterval);
}
RISE.MmReference.prototype.next = function() {
	$('#mmReference div.reference').css('left','0px').css('right','auto');
	if(this.actual+1>=this.rfs.length){
		this.show(0);
	}else{
		this.show(this.actual+1);
	}
}
RISE.MmReference.prototype.wheel = function(e,elm) {
	SZN.Events.cancelDef(e);
	delta=false;
	if (!e){ e = window.event; }
	if (e.wheelDelta){
		delta = e.wheelDelta/120;
	}else if (e.detail) { delta = -e.detail/3; }
	if(delta!=false){
		if(delta<0) this.next();
		if(delta>0) this.prev();
	}
}
RISE.MmReference.prototype.prev = function() {
	$('#mmReference div.reference').css('right','0px').css('left','auto');
	if(this.actual-1<0){
		this.show(this.rfs.length-1);
	}else{
		this.show(this.actual-1);
	}
}
RISE.MmReference.prototype.show = function(key) {
	if(this.rfs[key]){
		this.hide(this.actual);
		$(this.rfs[key]).fadeIn("slow");
		this.actual = key;
		if(key==0) $(this.prevButt).fadeOut("slow");
		else $(this.prevButt).fadeIn("slow");
		if(key==this.rfs.length-1) $(this.nextButt).fadeOut("slow");
		else $(this.nextButt).fadeIn("slow");
	}
	if(this.slideInterval){
		clearInterval(this.slideInterval);
		mThis = this;
		this.slideInterval = setInterval(function(){mThis.next()},this.steptime);
	}
}
RISE.MmReference.prototype.hide = function(key) {
	if(this.rfs[key]){
		$(this.rfs[key]).hide("slow");
		if(this.actual==key) this.actual = false;
	}	
}

