/* Xtra Active Advertising BV - V0.2 08-04-2009 */
var MooWindow = new Class({

	  Implements: [Options, Events],

	  options: {
			overlayColor : '#000000',
			width : 800 ,
			height: 670,
			background : 'white', 
			color : 'black',
			top : 10,
			padding : 25,
			content : '',
			border : 'none',
			overlayOpacity : 0.7,
			topBarColor : '#1e77d3',
			topBarBorder : '1px solid black',
			position : 'absolute',
			title : '',
			titleColor : 'white',
			topclosehide : '1',
			containerClass : '',
			topBarBackground : '',
			closeLinkText : '[sluiten]'
			
	  },
	   initialize: function(options){
			this.setOptions(options);
			this.content = this.options.content;
			this.windowOverlay = new Element('div', {'id':'windowOverlay' }).inject($(document.body, 'top' ));	
			this.imageContainer = new Element( 'div', { 'id' : 'imageContainer' } ).inject($(document.body));
			this.topBar = new Element('div', {'id' : 'topBar'}).inject(this.imageContainer);
			
			if( this.options.containerClass != '' )
			{
				this.imageContainer.set('class', this.options.containerClass);
			}
			
			this.topBarTitle = new Element( 'div', {'id' : 'topBarTitle' } ).inject(this.topBar);
			this.topBarTitle.setStyles({
								  'float' : 'left',
								  'width' : ( this.options.width - 30) + 'px',
								  'color' : this.options.titleColor,
								  'border' : 0
								  });
								  
			this.topBarTitle.set('html', this.options.title);
			this.closeLink = new Element('span', {'id' : 'closeSpan'}).inject(this.topBar);
			
			if(this.options.topclosehide != '0'){
				this.closeLink.set('html', this.options.closeLinkText);
			}
			
			this.contentContainer = new Element( 'div', {'id' : 'mooWindowContent'} ).inject(this.imageContainer);
			
			var marginLeft = document.width || document.body.clientWidth ;
			marginLeft = ( marginLeft / 2);
			marginLeft = marginLeft - ( this.options.width / 2 );
			marginLeft += '';
			marginLeft = marginLeft + 'px';
			
			this.imageContainer.setStyles( { 
								'background' : this.options.background, 
								'color' : this.options.color, 
								'z-index' : 101, 
								'top' :  + this.options.top + 'px', 
								'position' : this.options.position, 
								'width' : this.options.width + 'px' ,
								'height': this.options.height +'px',
								'padding': this.options.padding + 'px',
								'display' : 'none',
								'margin-left' : marginLeft
								});
			
			if( this.options.border != 'none' )
				this.imageContainer.setStyle( 'border', this.options.border ); 
				
			this.topBar.setStyles({ 	
									 	/*'padding' : '3px 10px',*/
									 	'width' : (this.options.width) + 'px',
										'border-bottom' : this.options.topBarBorder,
									 	'line-height' : '20px',
									 	'vertical-align' : 'middle',
										//'text-align' : 'right',
									 	'background' : this.options.topBarColor,
										
										'height' : '20px', 
									 	'margin-left' : '-25px', 
										'margin-right' : '-25px',
										'margin-top' : '-25px', 
										'margin-bottom' : '10px',
										'cursor': 'move'
										});
			
			this.closeLink.setStyles({'cursor' : 'pointer', 'color' : this.options.titleColor});
			
			this.windowOverlay.setStyles({
				'background' : this.options.overlayColor,
				'position' : 'absolute',
				'width'	: '100%',
				'height': $(window).getScrollSize().y+$(window).getScroll().y,
				'top': 0,
				'left': 0,
				'right': 0,
				'z-index' :100,
				opacity : this.options.overlayOpacity,
				'display': 'none'
			 });
			
			
			this.closeLink.addEvent( 'click', function(){
				this.hide();
				
			}.bind(this));
			
			this.windowOverlay.addEvent( 'click', function(){
				this.hide();
			}.bind(this));
			
			this.contentContainer.set('html', this.content);	
			
	  },
	  content : '',
	  
	  setContent: function( content){
		  this.content = content;
		  this.contentContainer.set('html', this.content);
	  },
	  
	  appendContent: function( content){
		  this.content += content;
		  this.contentContainer.set('html', this.content);
	  },
	  
	  show: function(){

			this.windowOverlay.setStyle('display', 'block');		
			this.imageContainer.setStyle('display', 'block');
			var myDrag = new Drag.Move($('imageContainer')).detach(); 
			$('topBar').addEvent('mousedown', function(){
				myDrag.attach();
			});
			
			$('topBar').addEvent('mouseup', function(){
				myDrag.detach();
			});
			
			//var myFloatingDivShim = new IframeShim(this.windowOverlay);
			//myFloatingDivShim.show();
			
	  },
	  
	  hide: function(){
	  
			this.windowOverlay.setStyle('display', 'none');
			this.imageContainer.setStyle('display', 'none');
			$('imageContainer').setStyle('left' , 0);
			$('imageContainer').setStyle('top' , this.options.top);
			
			//var myFloatingDivShim = new IframeShim($('windowOverlay'));
			//myFloatingDivShim.hide();
	  }
	  
	  

});
