/**
	@name FORCERScreenDynamic
	@version 0.1
	@copyright 2009 EURIP.com
**/
var FORCERScreenDynamicClass = Class.create({
	Version: '0.0.1',

	LocalData: {changebox: []},



//	FORCER Constructor
  initialize: function() {
	  },

//	function: SelectBoxOpen
	SelectBoxOpen: function(box,boxid,boxrev) {
		var container,insidecontent,insideset;
		if (container = $(box))  {
			var c = 0;
			while (insidecontent = $('c'+box+'['+c+']')) {
				insideset = $('s'+box+'['+c+']')
				if (c!=boxid)  {
					insidecontent.setStyle({visibility: 'hidden'});
					insideset.removeClassName('box_dynselect_selecta'+boxrev);
					insideset.addClassName('box_dynselect_select');
					}
				else  {
					insidecontent.setStyle({visibility: 'visible'});
					insideset.removeClassName('box_dynselect_select');
					insideset.addClassName('box_dynselect_selecta'+boxrev);
					}
				c++;
				}
			}
	  }
});
var FORCERScreenDynamic = new FORCERScreenDynamicClass();


/**
@name FORCERBoxLoop
@version 0.1
@copyright 2011 EURIP.com
**/
var FORCERBoxLoop = Class.create({
	Data:{defaultCFG:{"sec":10,"transformsec":1}},

//	Constructor
	initialize: function(box,boxcfg) {
		if (typeof(boxcfg) == 'object') {this.Config = $H(this.Data.defaultCFG).merge(boxcfg).toObject();}
		else {this.Config = this.Data.defaultCFG;}
		this.ObjStatus = {active:0,exec:false,box:false,childs:false};
		try {this.ObjStatus.box = $(box);}
		catch(e) {this.ObjStatus.box = false;}
		if (this.ObjStatus.box) {
			this.ObjStatus.childs = this.ObjStatus.box.childElements();
			if (this.ObjStatus.childs.length > 1)  {
				for (var i = 0; i < this.ObjStatus.childs.length; i++) {
					this.ObjStatus.childs[i].setStyle({
						"display":'none',"opacity":1,
						"transition":'opacity '+this.Config.transformsec+'s',"-webkit-transition":'All '+this.Config.transformsec+'s',
						"-moz-transition":'All '+this.Config.transformsec+'s',"-o-transition":'All '+this.Config.transformsec+'s'});}
				this.ObjStatus.active = this.ObjStatus.childs.length-1;
				this.doNext();
				this.ObjStatus.exec = setInterval(this.doNext.bind(this),(this.Config.sec*1000));
				}
			return this;
			}
		else {alert('FORCERBoxLoop error: box not found: '+box);return false;}
		},

//	doNext()
	doNext: function() {
		var c = this.ObjStatus.active;
		var n = ((this.ObjStatus.active+1)<this.ObjStatus.childs.length) ? (this.ObjStatus.active+1) : 0;
		this.ObjStatus.childs[n].setStyle({"display":'',"opacity":1});
		this.ObjStatus.childs[c].setStyle({"opacity":0});
		switch (Math.floor(Math.random()*6)) {
			case 1:	break;
			case 2:	this.ObjStatus.childs[c].setStyle({"top":'-500px'});break;
			case 3:	this.ObjStatus.childs[c].setStyle({"top":'500px'});	break;
			case 4:	this.ObjStatus.childs[c].setStyle({"left":'-500px'});break;
			default:this.ObjStatus.childs[c].setStyle({"left":'500px'});break;
			}
		this.hide.bind(this).delay(this.Config.transformsec,c);
		this.ObjStatus.active = n;
		},

//	hide()
	hide: function(box) {
		this.ObjStatus.childs[box].setStyle({"display":'none',"opacity":.1,"left":0,"top":0});
		}
	});


/**
@name FORCERShowElementsLoop
@version 0.1
@copyright 2011 EURIP.com
**/
var FORCERShowElementsLoop = Class.create({
	Data:{defaultCFG:{"maxshow":3,"repeat":false,"sec":3,"transformsec":1}},

//	Constructor
	initialize: function(box,boxcfg) {
		if (typeof(boxcfg) == 'object') {this.Config = $H(this.Data.defaultCFG).merge(boxcfg).toObject();}
		else {this.Config = this.Data.defaultCFG;}
		this.ObjStatus = {current:0,exec:false,box:false,childs:false,activeElements:[]};
		try {this.ObjStatus.box = $(box);}
		catch(e) {this.ObjStatus.box = false;}
		if (this.ObjStatus.box) {
			this.ObjStatus.childs = this.ObjStatus.box.childElements();
			if (this.ObjStatus.childs.length > 1)  {
				for (var i = 0; i < this.ObjStatus.childs.length; i++) {
					this.ObjStatus.childs[i].setStyle({
						"opacity":0,"display":'none',
						"transition":'opacity '+this.Config.transformsec+'s ease',"-webkit-transition":'opacity '+this.Config.transformsec+'s ease',
						"-moz-transition":'opacity '+this.Config.transformsec+'s ease',"-o-transition":'opacity '+this.Config.transformsec+'s ease'});}
				this.doNext();
				this.ObjStatus.exec = setInterval(this.doNext.bind(this),(this.Config.sec*1000));
				}
			return this;
			}
		else {alert('FORCERBoxLoop error: box not found: '+box);return false;}
		},

//	doNext()
	doNext: function() {
		var c = this.ObjStatus.current;var d;
		if (c>0 || this.ObjStatus.activeElements.length==0) {
			this.ObjStatus.childs[c].setStyle({"display":'',"opacity":1});
			this.ObjStatus.activeElements.push(this.ObjStatus.childs[c]);
			var n = ((c+1)<this.ObjStatus.childs.length) ? (c+1) : 0;
			this.ObjStatus.current = n;
			if (n==0 && this.ObjStatus.activeElements.length>0 && !this.Config.repeat) {
				clearInterval(this.ObjStatus.exec);
				}
			}
		if (this.ObjStatus.activeElements.length > this.Config.maxshow || (c==0 && this.ObjStatus.activeElements.length>0)) {
			d = this.ObjStatus.activeElements.shift()
			d.setStyle({"opacity":0});
			this.hide.bind(this).delay(this.Config.transformsec,d);
			}
		},

//	hide()
	hide: function(box) {
		box.setStyle({"display":'none',"opacity":0});
		}
	});
