// Version 2 Beta

function initLayer (name, parent, box, background, border, zindex, visibility, contentpos, content, exclip, handle, otherstyle) {
	var left, top, width, height;
	boxArray=box.split(' ');
	left=boxArray[0]; top=boxArray[1]; width=(!boxArray[2])?0:boxArray[2]; height=(!boxArray[3])?0:boxArray[3];

// Background
	if (background=='') background=''
	else if (background.indexOf('#')!=-1) {
		if (bw.ns4) background='layer-background-color:'+background+';'
		else background='background-color:'+background+';'
	} else {
		background='background-image: url('+background+');'
	}
	
// Border and Width Height
	if (border=='') {
		border='border:none;';
		borderWidth=0;
		imgHeight=height-16;
		formWidth=width; formHeight=height
	} else {
		borderArray=border.split(' '); borderWidth=borderArray[0]; borderColor=borderArray[1];
		if (bw.ns5) {formWidth=width-borderWidth*2; formHeight=height-borderWidth*2; imgHeight=formHeight;}
		if (bw.ns4) {formWidth=width; formHeight=height-(borderWidth*2-2); imgHeight=formHeight-8;}
		if (bw.ie4||bw.ie5) {formWidth=width; formHeight=(borderWidth>=7)?(height-(borderWidth-6)*2):height;imgHeight=formHeight-12;}
		border='border:'+borderWidth+'px solid '+borderColor+';';
	}
	if (imgHeight<1) imgHeight=1;

// Content
	contentpos=(!contentpos)?'':contentpos;
	if (contentpos=='') {
		cPadX=borderWidth; cPadY=borderWidth; cWidth=width-borderWidth*2; cHeight=height-borderWidth*2;
	} else {
		contentposArray=contentpos.split(' ');
		cPadX=eval(borderWidth)+eval(contentposArray[0]);
		cPadY=eval(borderWidth)+eval((!contentposArray[1])?cPadX:contentposArray[1]);
		cWidth=(!contentposArray[2])?(width-cPadX*2):contentposArray[2];
		cHeight=(!contentposArray[3])?(height-cPadY*2):contentposArray[3];
	}
	cClips='clip:rect(0,'+cWidth+','+cHeight+',0); overflow:hidden;'
	content=(!content)?'':content;

// Clip
	if (!exclip) {
		clips='clip:rect(0,'+width+','+height+',0); overflow:hidden;'
	} else {
		exclipArray=exclip.split(' ');
		exclip1=exclipArray[0]; exclip2=exclipArray[1]; exclip3=exclipArray[2]; exclip4=exclipArray[3];
		clips='clip:rect('+exclip1+','+exclip2+','+exclip3+','+exclip4+'); overflow:hidden;'
	}

// Visibility
	if (visibility==-1) visibility='';
	else visibility=visibility?'visibility:visible;':'visibility:hidden;';

// for 0 Width and 0 Height
	if (width<=0) {width=''; clips=''}
	else width='width:'+width+';'
	if (height<=0) {height=''; clips=''}
	else height='height:'+height+';'
	if (formWidth<=0) formWidth=''
	else formWidth='width:'+formWidth+';'
	if (formHeight<=0) formHeight=''
	else formHeight='height:'+formHeight+';'
	if (cWidth<=0) {cWidth=''; cClips=''}
	else cWidth='width:'+cWidth+';'
	if (cHeight<=0) {cHeight=''; cClips=''}
	else cHeight='height:'+cHeight+';'

// Stylesheet
	MainStyleCode='#'+name+' {'+
		'position:absolute;'+
		'left:'+left+';'+
		'top:'+top+';'+
		width+
		height+
		background+
		clips+
		'z-index:'+zindex+';'+
		visibility+
		'}\n';	

	FormStyleCode='#'+name+'Form {'+
		'position:absolute;'+
		'left:0;'+
		'top:0;'+
		formWidth+
		formHeight+
		border+
		'z-index:'+1+';'+
		'}\n';	

	ContentStyleCode='#'+name+'Content {'+
		'position:absolute;'+
		'left:'+cPadX+';'+
		'top:'+cPadY+';'+
		cWidth+
		cHeight+
		cClips+
		'z-index:'+5+';'+
		'}\n';
//	alert(ContentStyleCode)

	styleAll+=(MainStyleCode+FormStyleCode+ContentStyleCode);

// LayerCode
	layerCode=''+
		'<DIV ID="'+name+'">\n'+
		'	<DIV ID="'+name+'Form"><IMG SRC="images/dot.gif" WIDTH="1" HEIGHT="'+imgHeight+'"></DIV>\n'+
		'	<DIV ID="'+name+'Content">'+content+'</DIV>\n'+
		'	<!-- '+name+'InsContent -->\n'+
		'</DIV>\n';

// insert into LayerAll
	if (parent=='htmlbody') {
		layerAll+=layerCode
	} else {
		reg=eval('/\<!-- '+parent+'InsContent --\>/')
		layerAll=layerAll.replace(reg, layerCode+'<!-- '+parent+'InsContent -->')
	}

// insert obj into Array
	objPair=name+' '+parent+' '+left+' '+top;
	objArray[objArray.length]=objPair
// for IE 5.5, and Netscape, we can use Push Method
//	objArray.push(objPair)  
}