var ShadowLayers = new Class({
	
	Implements:[Options,Events],
	
	options: {
		/*		
		width: '100px',
		height: '100px',
		left: '100px',
		top: '100px',
		uchwyt_res: false,
		uchwyt_drag: false,
		MainLayer: false,
		container:false
		*/
		autoheight: false,
		resize: true,
		height: '100px',
		overflow: 'hidden',
		zindex: '0'
					
		
	},
	

	initialize: function(id,idk,options) {
		
		
		this.setOptions(options);
		this.id = id;
		this.idk = idk;
		
		
		
		this.MakeLayer();
		this.MakeContent();
		this.MakeBorders();
		this.MakeCorners();
		
		
		if(this.options.resize == true){
		this.MakeResizable();
		this.MakeDraggable();
		}
		
		if(id>0){
			this.MakeToolbox();
			this.MakeToolboxUser();
			//this.MakeAddMainButton();
			//this.MakeRemMainButton();
			
		
		}
		
		
		if(this.options.overflow == 'auto'){
			
			this.MakeCloseButton();
		}	
		
		
		
		this.AddEvents();
		
		this.MakeRelative();
		
				
				
	},
	
	MakeStartDraggButton: function(){
		
		var textx = new Element('div', {
						'title':'Uwolnij',	
						
						'class':'lbuttons',	
								    			
		    			'styles': {
		        
			        		//'background': 'url(img/editcopy.png)',
			        		'background': 'rgb(230,230,230)',
			        		//'float':'left',
			        		'width':'15px',
			        		'height':'5px',
			        		'overflow':'hidden',
			        		'position':'absolute',
			        		'top':'4px',
			        		'right':'20px',
			        		'cursor':'pointer'
			        				        		
			        		
	    				},
	    				'events': {
        					'click': function(){
        						this.MainLayer.setStyle('position','absolute');
        						this.MainLayer.setStyle('margin','0px');
           						this.MakeResizable();
								this.MakeDraggable();
								textx.dispose();
							}.bindWithEvent(this),
							'mouseover': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'15px'
	              					
	              			 	});
								
							},
							'mouseout': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'5px'
	              					
	              			 	});
								
							}

    					}

							
				
							
							
							
							
		});
						
						
						
		this.textx = textx;
		this.textx.inject(this.MainLayer);
		
		},
		MakeAddMainButton: function(){
		
		var AddMainButton = new Element('div', {
						'title':'Dodaj do strony glownej',	
						'class':'lbuttons',			    			
		    			'styles': {
		        
			        		//'background': 'url(img/editcopy.png)',
			        		'background': 'rgb(245,188,51)',
			        		//'float':'left',
			        		'width':'15px',
			        		'height':'5px',
			        		'overflow':'hidden',
			        		'position':'absolute',
			        		'top':'4px',
			        		'right':'50px',
			        		'cursor':'pointer',
			        		'display':'none'
			        				        		
			        		
	    				},
	    				'events': {
        					'click': function(){
        						
								xajax_DodajMainProcess(this.id,'dodaj')
								
								
								
							}.bindWithEvent(this),
							'mouseover': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'15px'
	              					
	              			 	});
								
							},
							'mouseout': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'5px'
	              					
	              			 	});
								
							}

    					}

							
				
							
							
							
							
		});
						
						
						
		this.AddMainButton = AddMainButton;
		this.AddMainButton.inject(this.MainLayer);
		
		
	},
	MakeCloseButton: function(){
		
		var CloseButton = new Element('div', {
						'title':'Zamknij',	
						'class':'lbuttonsx',			    			
		    			'styles': {
		        
			        		//'background': 'url(img/editcopy.png)',
			        		'background': 'rgb(230,0,0)',
			        		
			        		'width':'15px',
			        		'height':'5px',
			        		'overflow':'hidden',
			        		'position':'absolute',
			        		'top':'4px',
			        		'right':'10px',
			        		'cursor':'pointer'
			        		
			        				        		
			        		
	    				},
	    				'events': {
        					'click': function(){
        						
								this.MainLayer.dispose();

								
								
								
							}.bindWithEvent(this),
							'mouseover': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'15px'
	              					
	              			 	});
								
							},
							'mouseout': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'5px'
	              					
	              			 	});
								
							}

    					}

							
				
							
							
							
							
		});
						
					
						
		this.CloseButton = CloseButton;
		this.CloseButton.inject(this.MainLayer);
		
		
	},
	
	
	MakeRemMainButton: function(){
		
		var RemMainButton = new Element('div', {
						'title':'Usun ze strony glownej',	
						'class':'lbuttons',			    			
		    			'styles': {
		        
			        		//'background': 'url(img/editcopy.png)',
			        		'background': 'rgb(220,0,0)',
			        		//'float':'left',
			        		'width':'15px',
			        		'height':'5px',
			        		'overflow':'hidden',
			        		'position':'absolute',
			        		'top':'4px',
			        		'right':'70px',
			        		'cursor':'pointer',
			        		'display':'none'
			        				        		
			        		
	    				},
	    				'events': {
        					'click': function(){
        						
								xajax_DodajMainProcess(this.id,'usun')
								
								
								
							}.bindWithEvent(this),
							'mouseover': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'15px'
	              					
	              			 	});
								
							},
							'mouseout': function(){
								this.set('morph', {duration: 'short', transition: 'bounce:out'});
								this.morph({
	              					'height':'5px'
	              					
	              			 	});
								
							}

    					}

							
				
							
							
							
							
		});
						
						
						
		this.RemMainButton = RemMainButton;
		this.RemMainButton.inject(this.MainLayer);
		
		
	},
	
	
	MakeResizable: function(){
		
		
		
		this.MainLayer.makeResizable({
							limit: {y: [50,1500],x:[50,990]},
							handle: this.uchwyt_res,
							"onStart": function(){
								
								this.SetIndex(this.MainLayer);
								
							}.bindWithEvent(this),
							
							"onDrag": function(){
    	   	 	
        						this.BorderTop.setStyle('width',(this.MainLayer.getStyle('width').toInt()-18)+'px');
        						this.BorderBottom.setStyle('width',(this.MainLayer.getStyle('width').toInt()-18)+'px');
        						this.BorderLeft.setStyle('height',(this.MainLayer.getStyle('height').toInt()-18)+'px');
        						this.BorderRight.setStyle('height',(this.MainLayer.getStyle('height').toInt()-18)+'px');
        						
        						this.Content.setStyle('width',(this.MainLayer.getStyle('width').toInt()-18)+'px');
        						this.Content.setStyle('height',(this.MainLayer.getStyle('height').toInt()-18)+'px');
        						
    						}.bindWithEvent(this),
    						
    						
    						"onComplete": function() {
																
								this.fireEvent("onCompleteResize");
								
																							
								
							}.bindWithEvent(this)
     				
                				
                			
							
					});	
			
	},
	
	
		
	
	
	MakeDraggable: function(){
		
		 	
		 						 				
		  this.MainLayer.makeDraggable({
							handle: this.uchwyt_drag,
							container: this.options.container_drag,
							"onStart": function(){
								
								this.SetIndex(this.MainLayer);
								
							}.bindWithEvent(this),
							
							"onComplete": function() {
																
								this.fireEvent("onCompleteDrag");
																							
								
							}.bindWithEvent(this)
					});
		
		
						
		
		
	},
	SetIndex:function(Layer){
		
			var xx=0;
                
                	var Elementy =new Array();
                		
                   		$$('.MainLayers').each(function(el) {
                			
                			
                			Elementy[ xx++]=el.getStyle('z-index').toInt();
                			
                			
                					
                		
                			
                			
                		});
                		
                		
						Elementy.sort(porownajLiczby);
						
						
						
						
						
                		              		
                	
                		//if (Layer.getStyle('z-index').toInt()==1 || Layer.getStyle('z-index').toInt()<Elementy[Elementy.length-1]){
                		
                			Layer.setStyle('z-index',(Elementy[Elementy.length-1])+1);
                			
                				
                			
                		//}
                		
                		//alert(Layer.getStyle('z-index').toInt());
                		
		
		
	},
	AddEvents: function(){
		
		
		
		
		this.MainLayer.addEvents({ 
                click: function(){
                	
                	//this.SetIndex(this.MainLayer);
                	
                	this.fireEvent("onClick");
                  	
                                   
	                               		
          		}.bindWithEvent(this)
          		/*	
          			
          		mouseenter: function(){
          			
          			//return false;
          			
                  	if(this.id>0 && this.RemMainButton && this.AddMainButton){
	                    this.RemMainButton.setStyle('display','block');
	                    this.AddMainButton.setStyle('display','block');
	                    
	                   	                    

	                    
                  	}
                  	
                  	//this.MainLayer.store('z-index', this.MainLayer.getStyle('z-index'));
                  	//this.SetIndex(this.MainLayer);
                    
	                               		
          		}.bindWithEvent(this),
          			
          			
          		mouseleave: function(){
          			//return false;
          			
                  	if(this.id>0 && this.RemMainButton && this.AddMainButton){
	                    this.RemMainButton.setStyle('display','none');
	                    this.AddMainButton.setStyle('display','none');
                  	}
                	  	 //this.MainLayer.setStyle('z-index',this.MainLayer.retrieve('z-index'));
                    
	                               		
          		}.bindWithEvent(this)
          		*/	
          			
				
		});
		
		
		
		this.TopRight.addEvents({ 
					click: function(){
					
						if(typeof xajax_DisplayToolboxUser =='function' && this.id>0) {
							if(this.ToolboxUser.getStyle('margin-left')==this.start_toolbox_user){
		            				 this.ToolboxUser.morph({
		              					'margin-left':'0px'
		              			 	});
		              			 	 this.ToolboxUserEmpty.morph({
		              					'margin-left':'0px'
		              			 	});
		              			 	
		              			 	if(!this.ToolboxUserContent.get('html')){
		              			 		
		              			 		xajax_DisplayToolboxUser(this.id,'toolbox_user_content');
		              			 		
		              			 		        			 		
		              			 		
		              			 	}
		              			 	
		              			 		              			 	
								}
								else{
									 this.ToolboxUser.morph({
		              					'margin-left':this.start_toolbox_user
		              			 	});
		              			 	this.ToolboxUserEmpty.morph({
		              					'margin-left':this.start_toolbox_user
		              			 	});
		              			 	
									
								}
						}
									
					}.bindWithEvent(this)
		});
		
		
		
		
		
		
	},
	
	MakeToolbox: function(){
		
		var Toolbox = new Element('div', {
	    
		    			'id': 'toolbox_'+this.id,
		    			'class': 'toolbox',
		    			
		    			'styles': {
		        
			        		'width': '300px',
			        		'height': '40px',
			        		'z-index': '2',
			        		'border': '0px solid rgb(255,0,0)',
			        		
			        		'position': 'absolute',
			        		'overflow': 'hidden',
			        		'top': '0px',
			        		'left': '0px'
	    				}
					});
					
		var ToolboxContent = new Element('div', {
	    
		    			'id': 'toolbox_content_'+this.id,
		    			'class': 'toolbox',
		    			
		    			'styles': {
		        
			        		'width': '300px',
			        		'height': '40px',
			        		'z-index': '3',
			        		'border': '0px solid rgb(255,0,0)',
			        		
			        		'position': 'absolute',
			        		'overflow': 'hidden',
			        		'top': '0px',
			        		'left': '0px'
	    				}
					});
					
		var ToolboxEmpty = new Element('div', {
	    
		    			'id': 'toolbox_empty_'+this.id,
		    			'class': 'toolbox',
		    			
		    			'styles': {
		        
			        		'width': '300px',
			        		'height': '40px',
			        		'z-index': '1',
			        		'border': '0px solid rgb(255,0,0)',
			        		'background-color': 'rgb(230,230,230)',
			        		'position': 'absolute',
			        		'overflow': 'hidden',
			        		'top': '0px',
			        		'background': 'url(img_style/toolsuser3.png) left top repeat-y',
			        		'left': '0px'
			        		
	    				}
					});
					
					
					
					Toolbox.inject(this.Content);
					ToolboxEmpty.inject(this.Content);
					ToolboxContent.inject(Toolbox);
					
		this.Toolbox = Toolbox;
		this.ToolboxEmpty = ToolboxEmpty;
		this.ToolboxContent = ToolboxContent;
		
		var widthtoolbox = Toolbox.getStyle('width').toInt();
		var widthtoolboxempty = ToolboxEmpty.getStyle('width').toInt();
		
		this.Toolbox.setStyle('margin-left',(-widthtoolbox)+'px');
		this.ToolboxEmpty.setStyle('margin-left',(-widthtoolboxempty)+'px');
				
		this.start_toolbox=(-widthtoolbox)+'px';
		this.start_toolbox_empty=(-widthtoolboxempty)+'px';
		
	},
	MakeToolboxUser: function(){
		
		var ToolboxUser = new Element('div', {
	    
		    			'id': 'toolbox_user_'+this.id,
		    			'class': 'toolbox',
		    			
		    			'styles': {
		        
			        		'width': '600px',
			        		'height': '30px',
			        		'z-index': '2',
			        		'border': '0px solid rgb(255,0,0)',
			        		
			        		'position': 'absolute',
			        		'overflow': 'hidden',
			        		'top': '0px',
			        		'left': '0px'
	    				}
					});
					
		var ToolboxUserContent = new Element('div', {
	    
		    			'id': 'toolbox_user_content_'+this.id,
		    			'class': 'toolbox',
		    			//'html':'toolbox user',
		    			'styles': {
		        
			        		'width': '600px',
			        		'height': '30px',
			        		'z-index': '3',
			        		'border': '0px solid rgb(255,0,0)',
			        		
			        		'position': 'absolute',
			        		'overflow': 'hidden',
			        		'top': '0px',
			        		'left': '0px'
	    				}
					});
					
		var ToolboxUserEmpty = new Element('div', {
	    
		    			'id': 'toolbox_user_empty_'+this.id,
		    			'class': 'toolbox',
		    			
		    			'styles': {
		        
			        		'width': '600px',
			        		'height': '30px',
			        		'z-index': '1',
			        		'border': '0px solid rgb(255,0,0)',
			        		'background-color': 'rgb(230,230,230)',
			        		'position': 'absolute',
			        		'overflow': 'hidden',
			        		'top': '0px',
			        		'background': 'url(img_style/toolsuser4.png) left top repeat-y',
			        		'left': '0px'
			        		
	    				}
					});
					
					
					
					ToolboxUser.inject(this.Content);
					ToolboxUserEmpty.inject(this.Content);
					ToolboxUserContent.inject(ToolboxUser);
					
		this.ToolboxUser = ToolboxUser;
		this.ToolboxUserEmpty = ToolboxUserEmpty;
		this.ToolboxUserContent = ToolboxUserContent;
		
		var widthtoolbox = ToolboxUser.getStyle('width').toInt();
		var widthtoolboxempty = ToolboxUserEmpty.getStyle('width').toInt();
		
		this.ToolboxUser.setStyle('margin-left',(-widthtoolbox)+'px');
		this.ToolboxUserEmpty.setStyle('margin-left',(-widthtoolboxempty)+'px');
				
		this.start_toolbox_user=(-widthtoolbox)+'px';
		this.start_toolbox_user_empty=(-widthtoolboxempty)+'px';
		
	},
	
	MakeRelative: function(){
		
		if(this.options.autoheight==true){
			this.Content.setStyle('height','auto');
			this.MainLayer.setStyle('position','relative');
			
			var heightC = this.Content.getCoordinates().height
			
			this.Content.setStyle('height',heightC+'px');
			
			this.MainLayer.setStyle('height',(heightC+18)+'px');
			
			
			this.MainLayer.setStyle('margin','10px');
			
			var cor_width =this.options.width.toInt()-(this.MainLayer.getStyle('margin-left').toInt()*2)+'px';
			
			this.MainLayer.setStyle('width',cor_width);
			
			//alert((this.options.width.toInt()-(this.MainLayer.getStyle('margin-left').toInt())*2)+'px');
			
			
			this.BorderLeft.setStyle('height',(heightC)+'px');
			this.BorderRight.setStyle('height',(heightC)+'px');
			
			this.BorderTop.setStyle('width',(cor_width.toInt()-18)+'px');
			this.BorderBottom.setStyle('width',(cor_width.toInt()-18)+'px');
			
			this.Content.setStyle('width',(cor_width.toInt()-18)+'px');
			
			this.MakeStartDraggButton();
			
			//alert(this.Content.getCoordinates().height);
		
		}
		
		
		
	},
			
	
	MakeLayer: function(){
		
		
		
		var MainLayer = new Element('div', {
	    
		    			'id': 'MainLayer_'+this.id,
		    			'class': 'MainLayers',
		    			//'html': $('rBC_60').get('html'),
		    			'styles': {
		        
			        		'width': this.options.width,
			        		'height': this.options.height,
			        		'z-index': this.options.zindex,
			        		'border': '0px solid rgb(255,0,0)',
			        		//'background-color': 'rgb(240,240,240)',
			        		'top': this.options.top,
			        		'left': this.options.left,
			        		'position': 'absolute',
			        		'overflow':'hidden'
			        		
	    				}
					});
					
					this.MainLayer = MainLayer;
				
					MainLayer.inject(this.options.container);
		/*			
		var MainLayer = $('Nazwa_'+this.id);
		
		MainLayer.setStyle('width',this.options.width);
		MainLayer.setStyle('height',this.options.height);
		//MainLayer.setStyle('z-index','0');
		MainLayer.setStyle('top',this.options.top);
		MainLayer.setStyle('left',this.options.left);
		MainLayer.setStyle('position','absolute');
		MainLayer.setStyle('overflow','hidden');
		
				this.MainLayer = MainLayer;
		*/
		
		
	},
	
	MakeContent: function(){
		
		
		//var Content = $('Nazwa_'+this.id);
		
		var Content = this.options.content;
		
		Content.setStyle('width',(this.options.width.toInt()-18)+'px');
		
		Content.setStyle('height',(this.options.height.toInt()-18)+'px');
		
		Content.setStyle('z-index','0');
		Content.setStyle('top','9px');
		Content.setStyle('left','9px');
		Content.setStyle('position','absolute');
		Content.setStyle('overflow',this.options.overflow);
		
		//alert(Content.getStyle('background-color'));
		
		//Content.setStyle('background-color','rgb(255,255,255)');
					
					this.Content = Content;
					
					Content.inject(this.MainLayer);
					
					
					
				
		
	},
	
	MakeBorders: function(){
		
		var BorderT = new Element('div', {
	    
		    			'id': 'tb_'+this.id,
		    			'class': 'brns_top',
		    			'text': '',
		    			'styles': {
		        
			        		'width': (this.MainLayer.getStyle('width').toInt()-18)+'px',
			        		'height': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,0,255)',
			        		'background': 'url(img_style/new_bor_t.png) left top',
			        		'top': '0px',
			        		'left': '9px',
			        		'position': 'absolute',
			        		'overflow':'hidden',
			        		'cursor':'move'
	    				}
		});
		/*
		BorderT.addEvents({ 
					mouseenter: function(event){
						
						BorderT.setStyle('cursor','move');
						//return false;
						
					},
					mouseleave: function(event){
						BorderT.setStyle('cursor','default');
						//return false;
						
							
						
					}
		});
		*/
		
		var BorderB = new Element('div', {
	    
		    			'id': 'bb_'+this.id,
		    			'class': 'brns_bottom',
		    			'text': '',
		    			'styles': {
		        
			        		'width': (this.MainLayer.getStyle('width').toInt()-18)+'px',
			        		'height': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,0,255)',
			        		
			        		'background': 'url(img_style/new_bor_b.png) left top',
			        		
			        		'bottom': '0px',
			        		'left': '9px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
		});
		
		
		var BorderL = new Element('div', {
	    
		    			'id': 'lb_'+this.id,
		    			'class': 'brns_left',
		    			'text': '',
		    			'styles': {
		        
			        		'height': (this.MainLayer.getStyle('height').toInt()-18)+'px',
			        		'width': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,0,255)',
			        		
			        		'background': 'url(img_style/new_bor_l.png) left top',
			        		
			        		'top': '9px',
			        		'left': '0px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
		});
		
		var BorderR = new Element('div', {
	    
		    			'id': 'rb_'+this.id,
		    			'class': 'brns_right',
		    			'text': '',
		    			'styles': {
		        
			        		'height': (this.MainLayer.getStyle('height').toInt()-18)+'px',
			        		'width': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,0,255)',
			        		
			        		'background': 'url(img_style/new_bor_r.png) left top',
			        		
			        		'top': '9px',
			        		'right': '0px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
		});
		
		BorderT.inject(this.MainLayer);
		BorderB.inject(this.MainLayer);
		BorderL.inject(this.MainLayer);
		BorderR.inject(this.MainLayer);
		
		
		
		this.BorderTop = BorderT;
		this.BorderBottom = BorderB;
		this.BorderLeft = BorderL;
		this.BorderRight = BorderR;
		
		this.uchwyt_drag = BorderT;
		
		
			
	},
	
	
	MakeCorners: function(){
		
		
		
		
		var TopLeft = new Element('div', {
	    
		    			'id': 'tl_'+this.id,
		    			'class': 'crns_top_left',
		    			'text': '',
		    			'styles': {
		        
			        		'width': '9px',
			        		'height': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,255,0)',
			        		
			        		'background': 'url(img_style/new_tl.png) left top',
			        		'top': '0px',
			        		'left': '0px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
					});
					
		this.TopLeft = TopLeft;	
					
		//TopLeft.inject(this.MainLayer);
		
		
		var TopRight = new Element('div', {
	    
		    			'id': 'tr_'+this.id,
		    			'class': 'crns_top_right',
		    			'text': '',
		    			'styles': {
		        
			        		'width': '9px',
			        		'height': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,255,0)',
			        		
			        		'background': 'url(img_style/new_tr.png) left top',
			        		'top': '0px',
			        		'right': '0px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
					});
					
		//TopRight.inject(this.MainLayer);
		
		this.TopRight = TopRight;
		
		
		var BottomRight = new Element('div', {
	    
		    			'id': 'br_'+this.id,
		    			'class': 'crns_bottom_right',
		    			'text': '',
		    			'styles': {
		        
			        		'width': '9px',
			        		'height': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,0,255)',
			        		'cursor':'nw-resize',
			        		'background': 'url(img_style/new_br.png) left top',
			        		'bottom': '0px',
			        		'right': '0px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
					});
					
		//BottomRight.inject(this.MainLayer);
		
		this.BottomRight = BottomRight;
		
		
		var BottomLeft = new Element('div', {
	    
		    			'id': 'bl_'+this.id,
		    			'class': 'crns_bottom_left',
		    			'text': '',
		    			'styles': {
		        
			        		'width': '9px',
			        		'height': '9px',
			        		'z-index': '0',
			        		'border': '0px solid rgb(0,255,0)',
			        		
			        		'background': 'url(img_style/new_bl.png) left top',
			        		'bottom': '0px',
			        		'left': '0px',
			        		'position': 'absolute',
			        		'overflow':'hidden'
	    				}
					});
					
		//BottomLeft.inject(this.MainLayer);
		
		
		this.MainLayer.adopt([TopLeft,TopRight,BottomLeft,BottomRight]);
		
		
		this.BottomLeft = BottomLeft;
		
		
		
		this.uchwyt_res = BottomRight;
		
	}
	
});

function CreateWindow(id){
	
	var HashCookieConf = new Hash.Cookie('HCWindow_'+id);
	
	settingsg =new Array();
	
	//alert($('t_icons').getCoordinates().top);
	//alert($('t_icons').getCoordinates().left);
	//alert($('main_content').getCoordinates().width);
	
	if(!$(id)){
		
		
	var Content = new Element('div', {
	    
		    			'id': id,
		    			'class': 'MyWidndow',
		    			'html': '<div style=\'width:30px;margin:0px auto;top:35%;position:relative;\'><img src=\'images/loading_small.gif\'  alt=\'Czekaj\'/></div>',
		    			'styles': {
		        
			        			        		
			        		'background-color': 'rgb(250,250,250)',
			        		'text-align': 'left'
			        		
			        		
	    				}
					});
	
	

	
	if (HashCookieConf.get('c_'+id) || HashCookieConf.get('s_'+id)) {
       				
       								
			
       	  			settingsg['c_'+id] = HashCookieConf.get('c_'+id);
       	  			settingsg['s_'+id] = HashCookieConf.get('s_'+id);
       	  			settingsg['w_'+id] = HashCookieConf.get('w_'+id);
       	
       	  			var loadStyles = new Array();
 			 
       	  		
					loadStyles['left'] = settingsg['c_'+id].x - 1;
					loadStyles['top'] = settingsg['c_'+id].y - 1;
					
					if(loadStyles['top'] <=0){
						
						loadStyles['top'] =10;
						
					}
					
					if(settingsg['s_'+id].width){
					loadStyles['width'] = settingsg['s_'+id].width;
					}
					else{
					loadStyles['width'] = 500;
					}
					
					if(settingsg['s_'+id].height){
					loadStyles['height'] = settingsg['s_'+id].height;
					}
					else{
					loadStyles['height'] = 200;
					}
					
					if(settingsg['w_'+id].zindex){
					loadStyles['zindex'] = settingsg['w_'+id].zindex;
					}
					else{
					loadStyles['zindex'] = 2;
					}
					
								
					
					delete loadStyles;
					
							
					var shlg = new ShadowLayers(0,0,{
					content:Content,
					container: document.body,
					container_drag: document.body,
					zindex: '9999',
					width: loadStyles['width'],
			        height: loadStyles['height'],
					top: loadStyles['top'],
			        left: loadStyles['left'],
			        zindex: loadStyles['zindex'],
			        overflow: 'auto',
			        onClick: function(){
			        
			        			shlg.SetIndex(shlg.MainLayer);
			        			
			        			settingsg['w_'+id] = {"zindex": shlg.MainLayer.getStyle('z-index').toInt()}; 
			        			
			        			  								
								HashCookieConf.extend(settingsg);
																					
								
			        
			        
			        
			        },
			        onCompleteDrag: function(){
			        
       							if(shlg.MainLayer.getStyle('top').toInt()<=0){
   									
   									shlg.MainLayer.setStyle('top','10px');
   								}
   								
   								
   								var pos = {"x": shlg.MainLayer.getStyle('left').toInt() + 1, "y": shlg.MainLayer.getStyle('top').toInt() + 1};
                    			settingsg['c_'+id] = pos;
                    			
                    			settingsg['w_'+id] = {"zindex": shlg.MainLayer.getStyle('z-index').toInt()};  
   								
								HashCookieConf.extend(settingsg);
								
								
   					},
   					onCompleteResize: function(){
       							var size = {"width": shlg.MainLayer.getStyle('width').toInt(), "height": shlg.MainLayer.getStyle('height').toInt()};
                                     
                    			settingsg['s_'+id] = size;
                    			settingsg['w_'+id] = {"zindex": shlg.MainLayer.getStyle('z-index').toInt()};  
				
                    			HashCookieConf.extend(settingsg);
                    			
   					}
										
					});
					
					
			
	    	       	
       			}
       			
       			else{
       				
       								
			
       	  			
					
							
					var shlg = new ShadowLayers(0,0,{
					content:Content,
					container: document.body,
					container_drag: document.body,
					zindex: '9999',	
					width: ($('main_content').getCoordinates().width-15)+'px',
			        height: '500px',
					top: ($('t_icons').getCoordinates().top+35)+'px',
			        left: ($('t_icons').getCoordinates().left+5)+'px',
			        overflow: 'auto',
			        onClick: function(){
			        
			        			shlg.SetIndex(shlg.MainLayer);
			        			
			        			settingsg['w_'+id] = {"zindex": shlg.MainLayer.getStyle('z-index').toInt()}; 
   								
			        			if (shlg.MainLayer.getStyle('position')!=('relative')){
									HashCookieConf.extend(settingsg);
			        			}
								       
			        
			        
			        },
			        onCompleteDrag: function(){
			        
       							if(shlg.MainLayer.getStyle('top').toInt()<=0){
   									
   									shlg.MainLayer.setStyle('top','10px');
   								}
   								
   								
   								var pos = {"x": shlg.MainLayer.getStyle('left').toInt() + 1, "y": shlg.MainLayer.getStyle('top').toInt() + 1};
                    			settingsg['c_'+id] = pos;
                    			
                    			var size = {"width": shlg.MainLayer.getStyle('width').toInt(), "height": shlg.MainLayer.getStyle('height').toInt()};
                        		settingsg['s_'+id] = size;
                    			
                    			
                    			settingsg['w_'+id] = {"zindex": shlg.MainLayer.getStyle('z-index').toInt()}; 
   								
								HashCookieConf.extend(settingsg);
								
								
								
   					},
   					onCompleteResize: function(){
   						
       							var size = {"width": shlg.MainLayer.getStyle('width').toInt(), "height": shlg.MainLayer.getStyle('height').toInt()};
                        		settingsg['s_'+id] = size;
                        		
                        		var pos = {"x": shlg.MainLayer.getStyle('left').toInt() + 1, "y": shlg.MainLayer.getStyle('top').toInt() + 1};
                    			settingsg['c_'+id] = pos;
                        		
                    			settingsg['w_'+id] = {"zindex": shlg.MainLayer.getStyle('z-index').toInt()}; 
				
                    			HashCookieConf.extend(settingsg);
                    			
   					}
										
					});
					
					
			
	    	       	
       			}
       			 	
	
}
	
	
}