///////////////////////////////////////////////////////////////////
//
//					CORE
//					Module Class Version 2.0
//					Bases on Mootools 1.2.1 / CoreExtensionLib
//					Copyright by Christoph Stitz
//
///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
//Info
///////////////////////////////////////////////////////////////////
/*

Bugs:

	- internetexplorer geht der mausfokus der module fl?ten - evtl ist das kein richtiger bug
		kann aber trotzdem etwas verwirren
		(evtl wegen style cheet fehler, der bereits behoben ist...aber noch mal testen)
		
	- im internetexplorer fangen die scrollbars der module (sofern vorhanden)
		an zu flackern, wenn dragger und resizer ein und ausgeblendet werden

behobene Bugs:
	
	-im internetexplorer scheinen selectboxen durch divs und damit durch unsere module
		im internetexplorer werden nun hinter den content in die divs iframes injiziert
		um somit ein durchscheinen zu verhindern
		- Danke an Microsoft f?r diese tolle programmierarbeit -
	
*/

///////////////////////////////////////////////////////////////////
//Globals
///////////////////////////////////////////////////////////////////
var CoreModuleArray = new Array();//save all modules
var CoreModuleStartZ = 1;//start z-index from here

var CoreModuleOverlayer = null;

var CoreModuleChanged = false;

var CoreModuleEditAllSwitch = false;

//var CoreModuleDropables = new Array();//array to save droppables for the drag.move function

///////////////////////////////////////////////////////////////////
//Old Index Functions
///////////////////////////////////////////////////////////////////

function update_module_style(module_page_id,style_id,transparent,backgroundimage,backgroundcolor,bordercolor,borderwidth,borderstyle,opacity)
{
	CoreModuleArray[module_page_id].style_id = style_id;
	CoreModuleArray[module_page_id].backgroundcolor = backgroundcolor;
	CoreModuleArray[module_page_id].bordercolor = bordercolor;
	CoreModuleArray[module_page_id].borderwidth = borderwidth;
	CoreModuleArray[module_page_id].borderstyle = borderstyle;
	CoreModuleArray[module_page_id].opacity = opacity;
	CoreModuleArray[module_page_id].backgroundimage = backgroundimage;
	CoreModuleArray[module_page_id].transparent = transparent;
	CoreModuleArray[module_page_id].morph();//apply changes via morph
}

function update_module_content(module_page_id,content_id,content)
{
	CoreModuleArray[module_page_id].content.set('html',content);
	CoreModuleArray[module_page_id].content_id = content_id;//speichere id
	//wird sp?ter irgendwas mit array.push oder so
}

function CoreModuleArrayAddDropzone(handle)
{
	for (var i = 0; i < CoreModuleArray.length; i++)//for each module
	{
		if(CoreModuleArray[i]!=handle)//dont add yourself...
		{
			if(CoreModuleArray[i].editable==true&&handle.editable==true)//if editable
			{
				CoreModuleArray[i].drag.droppables.push(handle.main);//add me to that list
				handle.drag.droppables.push(CoreModuleArray[i].main);//add this to my own list
			}
		}
	}
}

function load_module(name,parent,iframe,overflow,autoheight,page,global,editable,article,database_id,zindex,top_unit,left_unit,height_unit,width_unit,top,left,height,width,style_id,backgroundimage,transparent,backgroundcolor,bordercolor,borderwidth,borderstyle,opacity)
{
	var m = new CoreModule();
	m.style_id = style_id;
	m.database_id = database_id;
	
	m.name=name;
	
	m.article = article;
	
	m.editable = editable;
	
	m.page = page;
	
	m.zindex = zindex;
	m.top = top;
	m.left = left;
	m.height = height;
	m.width = width;
	m.top_unit = top_unit;
	m.left_unit = left_unit;
	m.height_unit = height_unit;
	m.width_unit = width_unit;
	m.backgroundimage = backgroundimage;
	m.transparent = transparent;
	m.backgroundcolor = backgroundcolor;
	m.bordercolor = bordercolor;
	m.borderwidth = borderwidth;
	m.borderstyle = borderstyle;
	m.opacity = opacity;
	m.global = global;
	m.overflow = overflow;
	m.iframe = iframe;
	m.parent = parent;
	
	m.create();
	
	//save to dropables array of each module
	CoreModuleArrayAddDropzone(m);
	
	//load content to modules
	if(m.iframe!=1)//fals nicht im iframemodus
	{
	     // m.content.set('html',$("content_"+database_id).get('html'));//lade inhalt
		 
         $("content_"+database_id).injectInside(m.content);
	}  
	else
	{
		m.setUrl('article.php?load&article_id='+m.article);
		
		//delete loader content
		$("content_"+database_id).set('html','');
	}
	
	
	if(autoheight==1)
	{
		m.autoheight=1;
		m.autoheight_start();
	}
	
}






///////////////////////////////////////////////////////////////////
//Functions
///////////////////////////////////////////////////////////////////

function CoreModuleGetModuleByDatabaseId(database_id)
{
	for (var i = 0; i < CoreModuleArray.length; i++)//for each module
	{
		if(CoreModuleArray[i].database_id==database_id)
		{
			return CoreModuleArray[i];
		}
	}
	return null;
}

function CoreModuleGetModuleByMain(main_handle)
{
	for (var i = 0; i < CoreModuleArray.length; i++)//for each module
	{
		if(CoreModuleArray[i].main==main_handle)
		{
			return CoreModuleArray[i];
		}
	}
	return null;
}

function CoreModuleToFront(handle)//function to bring window to front
{
	if(handle.zindex<=CoreModuleArray.length)//if window is not on top
	{
		for (var i = 0; i < CoreModuleArray.length; i++)//for each module
		{
			if(CoreModuleArray[i].zindex>handle.zindex)//if index is heigher than the handle index
			{
				CoreModuleArray[i].zindex = CoreModuleArray[i].zindex-1;//put it down one step
				CoreModuleArray[i].main.setStyle('z-index', CoreModuleArray[i].zindex);//update me in dom
			}
		}
		handle.zindex = CoreModuleArray.length+CoreModuleStartZ;//bring me to front now
		handle.main.setStyle('z-index', handle.zindex);//update me in dom
		//alert("Mein z-index ist jetzt "+handle.zindex+"!");
	}
	else//restore my z
	{
	handle.main.setStyle('z-index', handle.zindex);//restore z
	}
}

function CoreModuleNormalizeAll()
{
	for (var i = 0; i < CoreModuleArray.length; i++)
	{
		if(CoreModuleArray[i].maximized==true)
		{
			CoreModuleArray[i].normalize();
		}
	}
}

function CoreModuleSwitchEditAll()
{
	if(CoreModuleEditAllSwitch==true)
	{
		for (var i = 0; i < CoreModuleArray.length; i++)
		{
			if(CoreModuleArray[i].editable==true)
			{
				CoreModuleHideEdit(CoreModuleArray[i]);
			}
		}
		CoreModuleEditAllSwitch = false;
	}
	else
	{
		for (var i = 0; i < CoreModuleArray.length; i++)
		{
			if(CoreModuleArray[i].editable==true)
			{
				CoreModuleShowEdit(CoreModuleArray[i]);
			}
		}
		CoreModuleEditAllSwitch = true;
	}
}

function CoreModuleShowEdit(that)
{
	if(that.editable==true)
	{
		//show dragger
		that.dragger.setStyle('display','block');
		var myDEffect = new Fx.Morph(that.dragger, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myDEffect.start({'opacity': 1});
		//show resizer
		that.resizer.setStyle('display','block');
		var myREffect = new Fx.Morph(that.resizer, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myREffect.start({'opacity': 1});
		//add clicker
		that.main.addEvent( 'click' , function()//bring to front on click
		{
			CoreModuleToFront(that);
		});
		//switch
		that.showtools = true;
	}
}

function CoreModuleHideEdit(that)
{
	if(that.editable==true)
	{
		//hide dragger
		var myDEffect = new Fx.Morph(that.dragger, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myDEffect.start({'opacity': 0});
		myDEffect.addEvent('onComplete', function()
		{
			that.dragger.setStyle('display','none');
		});
		//hide resizer
		that.resizer.setStyle('display','block');
		var myREffect = new Fx.Morph(that.resizer, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myREffect.start({'opacity': 0});
		myREffect.addEvent('onComplete', function()
		{
			that.resizer.setStyle('display','none');
		});
		//remove clicker
		that.main.removeEvents('click');
		//switch
		that.showtools = false;
	}
}

function CoreModuleSwitchEdit(that)
{
	if(that.editable==true)
	{
		if(that.showtools==false)
		{	
			CoreModuleShowEdit(that);
		}
		else
		{
			CoreModuleHideEdit(that);
		}
	}
}

function CoreModuleBorderBalance(that)
{	
	// calculate contentsize and position for border
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		var conttop = that.borderwidth+'px';
		var contleft = that.borderwidth+'px';
		var contheight = Number(that.height-2*that.borderwidth)+'px';
		var contwidth = Number(that.width-2*that.borderwidth)+'px';
		var borderheight = Number(that.height-2*that.borderwidth)+'px';
		var borderwidth = Number(that.width-2*that.borderwidth)+'px';
	}
	else
	{
		var conttop = that.borderwidth+'px';
		var contleft = that.borderwidth+'px';
		var contheight = Number(that.height-2*that.borderwidth)+'px';
		var contwidth = Number(that.width-2*that.borderwidth)+'px';
		var borderheight = Number(that.height-that.borderwidth*2)+'px';
		var borderwidth = Number(that.width-that.borderwidth*2)+'px';
	}
	that.borderdiv.setStyle('width',borderwidth);
	that.borderdiv.setStyle('height',borderheight);
	that.content.setStyle('top',conttop);
	that.content.setStyle('left',contleft);
	that.content.setStyle('height',contheight);
	that.content.setStyle('width',contwidth);
}

function CoreModuleAutoHeight(id)
{
	//alert(CoreModuleArray[id].content.scrollHeight+"\n\n"+CoreModuleArray[id].height);
	if (CoreModuleArray[id].content.scrollHeight>CoreModuleArray[id].height)//fals inhalt gr??er als div
	{	
		CoreModuleArray[id].main.setStyle('height',CoreModuleArray[id].content.scrollHeight+2*CoreModuleArray[id].borderwidth);
		CoreModuleArray[id].update_options();
		//CoreModuleBorderBalance(CoreModuleArray[id]);
	}
}

/*function CoreModulePluginOption(key,value)
{
	this.key = key;
	this.value = value;
}*/

document.addEvent( 'domready' , function()
{

	//create FlowBar
	CoreModuleFlowBar = new Element ( 'div' , { 
	'style' : 'position:absolute;z-index:1000;top:0px;right:50px;width:100px;height:0px;'
	});
	CoreModuleFlowBar.injectInside($(document.body));
	CoreModuleFlowBar.fade(0);//internet explorer fix
	
	//create CoreWindowOverlayer
	CoreModuleOverlayer = new Element ( 'div' , { 
	'style' : 'overflow:hidden;position:absolute;z-index:9999;top:0px;left:0px;height:0px;'
	});
	CoreModuleOverlayer.injectInside($(document.body));
	
	
	//scroll event
	window.addEvent( 'scroll' , function(){CoreModuleNormalizeAll()});
	document.addEvent( 'scroll' , function(){CoreModuleNormalizeAll()});
	
});


///////////////////////////////////////////////////////////////////
//Class
///////////////////////////////////////////////////////////////////
function CoreModule()
{
	
	//copy to array
	CoreModuleArray.push(this);
	
	//private
	var that = this; //copy handel for lower classes	
	
	//public
	
	this.maximized = false;
	
	//options
	this.id = CoreModuleArray.length-1;//use module -1 (array index) count as id
	this.database_id = "null";
	this.editable = true;
	this.style_id = 0;

	this.article = 0;
	
	this.autoheight = 0;
	this.autoheight_interval = null;
	this.overflow = 1;
	this.iframe = 0;
	
	this.global = 0;
	this.page = 0;
	
	this.height = 200;
	this.width = 200;
	this.top = 0;
	this.left = 0;
	
	this.top_unit = "px";
	this.left_unit = "px";
	this.height_unit = "px";
	this.width_unit = "px";
	
	this.zindex = this.id + CoreModuleStartZ;//z = id + Zstart
	
	this.transparent = 0;
	this.borderwidth = 0;
	this.borderstyle = "solid";
	this.bordercolor = "ffffff";
	this.opacity = 1;
	this.backgroundcolor = "ffffff";
	backgroundimage = "";
	
	this.parent = 0;
	
	this.showtools = false;
	
	this.deleteme = false;
	
	this.create = function()
	{	
		//create module div
		this.main = new Element('div',{'id':'core_module_'+this.id,'style':'position:absolute;z-index:'+this.zindex+';top:'+this.top+this.top_unit+';left:'+this.left+this.left_unit+';width:'+this.width+this.width_unit+';height:'+this.height+this.height_unit+';'});
		//alert(CoreModuleGetModuleByDatabaseId(this.parent).database_id);
		if(CoreModuleGetModuleByDatabaseId(this.parent)==null)
		{
			this.main.injectInside($(document.body));
		}
		else
		{
			this.main.injectInside(CoreModuleGetModuleByDatabaseId(this.parent).main);
		}
		
		
		/*
		//create border
		this.borderdiv = new Element ( 'div' , {'style':'overflow:hidden;position:absolute;'}) ;
		this.borderdiv.injectInside(this.main);
		this.borderdiv.setStyle('border-color','#'+this.bordercolor);
		this.borderdiv.setStyle('border-width',this.borderwidth);
		this.borderdiv.setStyle('border-style',this.borderstyle);
		
		//<<<<<<<<internet explorer select field fix>>>>>>>>>>>
		if(navigator.appName=="Microsoft Internet Explorer")
		{
			this.borderdiv.set('html',"<iframe height='100%' width='100%' framespacing='0' frameborder='0' allowtrancparency='true' style='filter:chroma(COLOR=#FFFFFF);' >");
		}
		//<<<<<<<<internet explorer select field fix>>>>>>>>>>>
		*/
		
		//create content div
		this.content = new Element ( 'div' , {'style':'overflow:'+this.overflow+';position:absolute;top:0px;left:0px;height:100%;width:100%;'}) ;
		this.content.injectInside(this.main);
		this.content.setStyle('opacity',this.opacity);
		if(this.transparent==0)//if not transparent
		{
			this.content.setStyle('background-image','url(_file/'+this.backgroundimage+')');
			this.content.setStyle('background-color','#'+this.backgroundcolor);
		}
		else//if transparent
		{
			this.content.setStyle('background-color','transparent');
		}
		
		/*
		not working jet
		apply
		'class':'mod_round_'+this.id to an object to make rounded corners
		
		//curvy coners
		settings =
		{
			tl: { radius: 20 },
			tr: { radius: 20 },
			bl: { radius: 20 },
			br: { radius: 20 },
			antiAlias: true,
			autoPad: true,
			validTags: ["div"]
		}
		var myBoxObject = new curvyCorners(settings,'mod_round_'+this.id);
		myBoxObject.applyCornersToAll();
		*/

		
		//CoreModuleBorderBalance(that);//balance border
		
		
		if(this.editable==true)
		{
			//create dragger
			this.dragger = new Element ( 'div' , {'style':'background-color:#ccccff;overflow:hidden;position:absolute;top:0px;left:0px;height:25px;width:100%;'}) ;
			this.dragger.injectInside(this.main);
			this.dragger.setStyles({display:'none',opacity: 0});
	
			//make dragable
			this.drag = new Drag.Move(this.main, {
			snap: 0,
			handle: this.dragger,
			//droppables: CoreModuleDropables,
			onStart: function()
			{
				that.main.setStyle('z-index', '8888');//bring to front
				that.show_overlayer();
				CoreModuleChanged = true;
				if(that.main.getParent()!=$(document.body))//if module has a parent
				{
					that.main.getParent().setStyle('border','dotted 5px #ffff00');
				}
				
			},
			onComplete: function()
			{	
				CoreModuleToFront(that);
				that.update_options();
				that.hide_overlayer();
				if(that.main.getParent()==$(document.body))//if no parent module...
				{
					if(that.top<0)//set it back if out of screen
					{
						that.main.setStyle('top',0);
						that.update_options();
					}
					if(that.left<0)//set it back if out of screen
					{
						that.main.setStyle('left',0);
						that.update_options();
					}
				}
				that.top_unit = 'px';
				that.left_unit = 'px';
			},
			onDrop: function(element, droppable)
			{
				if(that.main.getParent()!=$(document.body))//if module has a parent
				{
					that.main.getParent().setStyle('border','dotted 0px #ffff00');//set parent highlight back
				}
				//adopt element
				if(!droppable)//if not droppen over a container
				{
					if(element.getParent()!=$(document.body))//if a parent exist
					{
						if(CoreModuleGetModuleByMain(element.getParent()).showtools==true)//if module parent is in edit mode
						{
							element.injectInside($(document.body));//set parent to document.body
						}
					}
				}
				else
				{
					if(element.getParent()!=$(document.body))//if a parent exist
					{
						if(CoreModuleGetModuleByMain(element.getParent()).showtools==true)//if module parent is in edit mode
						{
							if(CoreModuleGetModuleByMain(droppable).showtools==true)//if in edit mode
							{
								if(element.getParent()!=droppable)//if parent has changed
								{
									element.setStyle('top','20px');
									element.setStyle('left','20px');
									//.grab(element);
									element.injectInside(droppable);//inject
								}
								droppable.setStyle('border','dotted 0px #000000');
							}
						}
					}
					else
					{
						if(CoreModuleGetModuleByMain(droppable).showtools==true)//if in edit mode
						{
							if(element.getParent()!=droppable)//if parent has changed
							{
								element.setStyle('top','20px');
								element.setStyle('left','20px');
								//.grab(element);
								element.injectInside(droppable);//inject
							}
							droppable.setStyle('border','dotted 0px #000000');
						}
					}
				}
			},
			onEnter: function(element, droppable)
			{
				if(element.getParent()!=$(document.body))//if a parent exist
				{
					if(CoreModuleGetModuleByMain(element.getParent()).showtools==true)//if module parent is in edit mode
					{
						if(CoreModuleGetModuleByMain(droppable).showtools==true)//if in edit mode
						{
							droppable.setStyle('border','dotted 5px #ffff00');
						}
					}
				}
				else
				{
					if(CoreModuleGetModuleByMain(droppable).showtools==true)//if in edit mode
					{
						droppable.setStyle('border','dotted 5px #ffff00');
					}
				}
			},
			onLeave: function(element, droppable)
			{
				if(CoreModuleGetModuleByMain(droppable).showtools==true)//if in edit mode
				{
					droppable.setStyle('border','dotted 0px #000000');
				}
			}
			});
			
			//create resizer
			this.resizer = new Element ( 'div' , {'style':'background-color:#ccccff;overflow:hidden;position:absolute;bottom:0px;right:0px;height:25px;width:25px;'}) ;
			this.resizer.injectInside(this.main);
			this.resizer.setStyles({display:'none',opacity: 0});			
			
			//make resizeable
			this.main.makeResizable({
			handle: this.resizer,
			limit: {x: [25, null], y: [25, null]},
			snap: 0,
			onStart: function()
			{
				CoreModuleToFront(that);
				that.show_overlayer();
				CoreModuleChanged = true;
			},
			onDrag: function()
			{	
				that.update_options();
				//CoreModuleBorderBalance(that);
			},
			onComplete: function()
			{
				that.update_options();
				that.hide_overlayer();
				that.width_unit = 'px';
				that.height_unit = 'px';
			}
			});
			
			//editor
			e = new Element('div',{'style':'background-image:url(_image/icons/applications.png);position:absolute;width:24px;height:24px;top:0px;left:0px;'});
			e.injectInside(this.dragger);
			e.addEvent( 'click' , function()
			{
				open_moduleprops_window(
				that.name,
				that.iframe,
				that.overflow,
				that.autoheight,
				that.page,
				that.id,
				that.database_id,
				that.content_id,
				that.style_id,
				that.height_unit,
				that.width_unit,
				that.top_unit,
				that.left_unit,
				that.height,
				that.width,
				that.top,
				that.left,
				that.global);
				CoreModuleChanged = true;
			});
			
			//deletor
			d = new Element('div',{'style':'background-image:url(_image/icons/close.png);position:absolute;width:24px;height:24px;top:0px;left:25px;'});
			d.injectInside(this.dragger);
			d.addEvent( 'click' , function()
			{
				CoreModuleDelete(that.id,that.database_id);
				CoreModuleChanged = true;
			});
			
			//hide tools on doomready
			/*this.main.addEvent( 'domready' , function()
			{
				//that.dragger.fade(0);
				//that.resizer.fade(0);
			});*/
			
			//toggle tools on double click
			this.main.addEvent( 'dblclick' , function()
			{
				CoreModuleSwitchEdit(that);
			});
			
		}//if
		
				
		
	};//create
	
	this.morph = function()//function to take on new options
	{
		//morph main top
		var topMEffect = new Fx.Morph(this.main, {duration: 'long', unit: this.top_unit, transition: Fx.Transitions.Sine.easeOut});
		topMEffect.start({	'top': this.top	});
		//morph main left
		var leftMEffect = new Fx.Morph(this.main, {duration: 'long', unit: this.left_unit, transition: Fx.Transitions.Sine.easeOut});
		leftMEffect.start({	'left': this.left	});
		//morph main height
		var heightMEffect = new Fx.Morph(this.main, {duration: 'long', unit: this.height_unit, transition: Fx.Transitions.Sine.easeOut});
		heightMEffect.start({	'height': this.height	});
		//morph main width
		var widthMEffect = new Fx.Morph(this.main, {duration: 'long', unit: this.width_unit, transition: Fx.Transitions.Sine.easeOut});
		widthMEffect.start({	'width': this.width	});
		
		//morph content
		var myCtopleftEffect = new Fx.Morph(this.content, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myCtopleftEffect.start({
			'background-color': '#'+this.backgroundcolor,
			'background-image': 'url(_file/'+this.backgroundimage+')',
			'opacity': this.opacity
		});
		
		/*
		// calculate contentsize and position for border
		if(navigator.appName=="Microsoft Internet Explorer")
		{
			var conttop = that.borderwidth;
			var contleft = that.borderwidth;
			var contheight = Number(that.height-2*that.borderwidth);
			var contwidth = Number(that.width-2*that.borderwidth);
			var borderheight = Number(that.height-2*that.borderwidth);
			var borderwidth = Number(that.width-2*that.borderwidth);
		}
		else
		{
			var conttop = this.borderwidth;
			var contleft = this.borderwidth;
			var contheight = Number(this.height-2*this.borderwidth);
			var contwidth = Number(this.width-2*this.borderwidth);
			var borderheight = Number(this.height-this.borderwidth*2);
			var borderwidth = Number(this.width-this.borderwidth*2);
		}
		
		//morph content top and left and opacity and bg
		var myCtopleftEffect = new Fx.Morph(this.content, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myCtopleftEffect.start({
			'background-color': '#'+this.backgroundcolor,
			'background-image': 'url(_file/'+this.backgroundimage+')',
			'opacity': this.opacity,
			'top' : conttop,
			'left' : contleft
		});
		
		//morph content height
		var myCEffect = new Fx.Morph(this.content, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myCEffect.start({
			'height' : contheight
		});
		
		//morph content width

		myCEffect.addEvent('onComplete', function()
		{
			if(that.transparent==1)//if not transparent
			{
				that.content.setStyle('background-color','transparent');
			}
		});
		
		// morph border
		var myBEffect = new Fx.Morph(this.borderdiv, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myBEffect.start({
			'border-color': '#'+this.bordercolor, 
			'border-width': this.borderwidth+'px',
			'border-style': this.borderstyle,
			'height' : borderheight,
			'width' : borderwidth
		});*/
		
	};//morph
	
		
	this.show_overlayer = function()
	{
		CoreModuleOverlayer.setStyle('height',$(document.body).getScroll().y+getViewSizeY());
		CoreModuleOverlayer.setStyle('width',$(document.body).getScroll().x+getViewSizeX());
	};
	
	this.hide_overlayer = function()
	{
		CoreModuleOverlayer.setStyle('height',0);
		CoreModuleOverlayer.setStyle('width',0);
	};
	
	this.update_options = function()
	{
		this.height = parseInt($('core_module_'+this.id).getStyle('height'));
		this.width = parseInt($('core_module_'+this.id).getStyle('width'));
		this.top = parseInt($('core_module_'+this.id).getStyle('top'));
		this.left = parseInt($('core_module_'+this.id).getStyle('left'));
	};
	
	this.destroy = function()
	{

		//destroy children dom
		this.main.destroy();		
		
		//remove from array
		CoreModuleArray.array_value_delete(this.id);
		
		//destroy class data
		that = 0;
		return 0;
	
	};//destroy
	
	this.show  = function()
	{
	
	this.main.fade(1);

	};//show
	
	this.hide = function()
	{
	this.main.fade(0);
		
	};//hide
	
	this.maximize = function()
	{
		this.main.setStyle('z-index', '8888');
		this.maximized = true;//tel prog that a win is maximized
		
		var myEffect = new Fx.Morph(this.main, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
		myEffect.start({
			'height': getViewSizeY()+'px', //use own function because of netscape
			'width': getViewSizeX()+'px', //use own function because of netscape
			'top': $(document.body).getScroll().y, 
			'left': $(document.body).getScroll().x  
		});
		//onComplete will not work here but:
	};
	
	this.normalize = function()
	{
		var myEffect = new Fx.Morph(this.main, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
		myEffect.start({
		'height': that.height-50, 
		'width': that.width-50,
		'top': that.top+25, 
		'left': that.left+25
		});
		myEffect.addEvent('onComplete', function()
		{
		that.main.setStyle('z-index', that.zindex);//restore z
		that.maximized = false;
		});
	};
	
	this.toggle_maximize = function()
	{
		if(this.maximized==true)
		{
		this.normalize();
		}
		else
		{
		this.maximize();
		}
	};
	
	this.autoheight_start = function()
	{
		this.autoheight_interval = window.setInterval("CoreModuleAutoHeight("+this.id+")", 1000);
	};
	
	this.autoheight_stop = function()
	{	
		window.clearInterval(this.autoheight_interval);
	};
	
	this.setUrl = function(url)
	{	
		this.content.setStyle('overflow','hidden');//prevent firefox from drawing scrollbars
		this.content.set('html',"<iframe name='"+this.name+"' frameborder='0' src='"+url+"' height='100%' width='100%'>");
	};
	
	/*this.border_balance = function()
	{
		//alert(this.top-parseInt(this.main.getStyle("border-top-width")));
		this.main.setStyle("top",this.top-parseInt(this.main.getStyle("border-top-width")));
		this.main.setStyle("left",this.left-parseInt(this.main.getStyle("border-top-width")));
	};*/
	
}

