/*******************************************************************/
/*                                                                 */
/* Copyright (c) 2005-2009 Solproject.it                          */
/* Author:                                                         */
/*                                                                 */
/*******************************************************************/
var SolBox = new Class({
	Implements: [Options, Events],
		options: {
			template:'default',
			BackgroundColor: '#FEC009',
			zIndex:35500,
			BoxStyles: {
				'width': 640,
				'height':540,
				'border':10
			},
			shadow:true
		},
	iconUrl:'/inc/templates/oikade/js/solbox/img/',
	initialize: function(options) {
		this.setOptions(options);
	},
	build: function(type,actions){
		var objectSolbox=this;
		var page=window.getSize();
		//------------------------Ghost-----------------------------------
		this.Ghost = new Element('div')
			.setProperties({
				'id': 'theGhost'
			})
			.setStyles({
				'display': 'inline',
				'z-index': this.options.zIndex,
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color':(this.options.shadow)?'#000':'none',
				'opacity': 0,
				'height': window.getScrollHeight() + 'px',
				'width': window.getScrollWidth() + 'px'
			});
		//------------------------Window Box------------------------------				
		this.Box = new Element('div')
			.setProperties({'id': 'theBox'})
			.setStyles({
				'position':'absolute',
				'margin':this.options.BoxStyles['border']+'px',
				'z-index': this.options.zIndex+3
			})
		//------------------------Content---------------------------------				
		this.Content = new Element('div')
			.setProperties({
				'id': 'theContent'
			})
			.setStyles({
				'background-color':this.options.BackgroundColor,
				'width': this.options.BoxStyles['width'],
				'height':this.options.BoxStyles['height']
			})
			.inject(this.Box);
		//------------------------Close-----------------------------------				
		this.Close = new Element('div')
			.setProperties({
				'id': 'TheCloseButton'
			})
			.setStyles({
				//'position':'absolute',
				//'left':(this.options.BoxStyles['width']-37),
				'top':0,
				'position':'relative',
				'float':'right',
				//'margin-top':'5px',
				//'margin-right':'10px',
				'background-image':'url(/inc/templates/'+objectSolbox.options.template+'/js/solbox/img/close.png)',
				'background-repeat':'no-repeat',
				'cursor':'pointer',
				'width': 14,
				'height':14
			})
			.addEvent(
				'mouseup',function(){
					objectSolbox.close();
				}
			)
			.inject(this.Content);
		//------------------------Icon---------------------------------				
		this.Icon = new Element('div')
			.setProperties({
				'id': 'theImageReference'
			})
			.setStyles({
				'background-image':'url('+this.iconUrl+type+'.png)',
				'background-repeat':'no-repeat',
				'background-position':'8px 8px',
				'position':'relative',
				'float':'left',
				'margin':'10px',
				'width': 80,
				'height':80
			})
			.inject(this.Content);
		//------------------------Message---------------------------------				
		this.Message = new Element('div')
			.setProperties({
				'id': 'theMessage'
			})
			.setStyles({
				'padding':'40px 0 0 0px',
				'width':'540px',
				'font':'bold 16px verdana',
				'float':'right'
			})
			.inject(this.Content);
		//------------------------Actions---------------------------------				
		if (actions){
			this.Actions = new Element('div')
				.setProperties({
					'id': 'theActions'
				})
				.setStyles({
					'clear':'both',
					'margin':'10px auto',
					'width': ((90 * actions.length) + ((10*actions.length)*4)),
					'height':60
				}).inject(this.Content);

			for(i=0;i<actions.length;i++){
				this.Actions.adopt(actions[i]);
			}
		}
		//------------------------Body------------------------------------				
		this.Body = new Element('div')
			.setProperties({
				'id': 'theBody'
			})
			.setStyles({
				'display': 'inline',
				'z-index': this.options.zIndex,
				'position': 'absolute',
				'top': 0,
				'left': ((page.x - this.options.BoxStyles['width']) / 2).toInt(),
				'width': this.options.BoxStyles['width'],
				'height':this.options.BoxStyles['height'],'opacity':0
			})
			.adopt(this.Box);
		//------------------------Frame-----------------------------------				
		this.Frame=new Element('div')
			.setProperties({
				'id': 'theFrame'
			})
			.setStyles({
				'position':'absolute',
				'width': this.options.BoxStyles['width'] + 'px',
				'height':this.options.BoxStyles['height'] + 'px',
				'-moz-border-radius': this.options.BoxStyles['border'] + 'px',
				'-webkit-border-radius': this.options.BoxStyles['border'] + 'px',
				'border': this.options.BoxStyles['border']+'px'+' solid #ccc',
				'opacity':0,
				'z-index': this.options.zIndex
			})
			.injectAfter(this.Box);
		//----------------------------------------------------------------			
		this.Ghost.inject(document.body);
		this.Body.inject(document.body);
		this.listener();
	},
	assign: function(type, actions, alert) {
		this.build(type,actions);
		var messaggio=new Element('div').set('html',alert);
		this.Message.adopt(messaggio);
	},
	listener: function(){
		var page=window.getSize();
		
		this.LoadGhost=new Fx.Morph(this.Ghost).start({'opacity':[0,0.4]});
		this.LoadBody = new Fx.Morph(this.Body,{duration:500,wait:true,link:'chain'})
			.start({
				opacity:[0,1],
				top:[0,((page.y - this.options.BoxStyles['height']) / 2).toInt()]
			})
		this.LoadFrame=new Fx.Morph(this.Frame,{duration:500,wait:true}).start({'opacity':[0.6]});
	},
	close: function(e) {
		this.Body.dispose();
		this.Ghost.dispose();
	}
});
SolBox.implement(new Options, new Events);

