function Layer(page, id, pos, size, color, visible, layerZone) {
	this.page= page;
	this.app= this.page.app;
	if(this.app.layers[id])return this.app.layers[id];
	this.id= id;
	this.type= LAYER_TYPE
	this.index= this.app.layers.length;
	this.appObjectModelPath= APP_NAME + ".layers[" + this.index + "]"
	var colorPart= "";
	this.layerZone= (layerZone==0?0:(!layerZone?DEFAULT_LAYER_ZONE:layerZone));
	LAYER_FRONT_ZINDEX[this.layerZone] ++;
	if(color) colorPart= " background-color:" + color + "; layer-background-color:"+ color;
	var FIRSTWIDTH=1200; FIRSTHEIGHT=1200;
	var filters=(ie4?"Filter:revealTrans(duration=1.7, transition=12);":"");
		if (ns4) {
			document.write('<STYLE TYPE="text/css"><!--\n#' +
								id + '{position:absolute; left:'+
								pos.x + '; top:'+
								pos.y + '; z-index:'+
								LAYER_FRONT_ZINDEX[this.layerZone] + '; width:'+
								FIRSTWIDTH + '; height:'+
								FIRSTHEIGHT + '; clip:rect(0,'+
								FIRSTWIDTH + ','+
								FIRSTHEIGHT + ',0);' + colorPart + ';visibility:'+
								(visible?VISIBLE:NOT_VISIBLE) + ';}' +
								'--></STYLE>');
			document.write('<DIV ID="' + id+ '" NAME="' + id+ '"></DIV>');
			this.layer= document.layers[id].document;
			this.css= document.layers[id];
		}else if (ie4) {
		var thestyle= 'STYLE="position:absolute; left:'+
								pos.x + '; top:'+
								pos.y + '; z-index:'+
								LAYER_FRONT_ZINDEX[this.layerZone] + '; width:'+
								FIRSTWIDTH + '; height:'+
								FIRSTHEIGHT + '; clip:rect(0,'+
								FIRSTWIDTH + ','+
								FIRSTHEIGHT + ',0);' + colorPart + ';visibility:'+
								(visible?VISIBLE:NOT_VISIBLE)+ ';"';
			document.write('<DIV ID="' + id+ '" NAME="' + id+ '" ' + thestyle + '></DIV>');
			this.layer= document.all[id];
			this.css= document.all[id].style;
			this.css.visibility= (visible?VISIBLE:NOT_VISIBLE);
			this.css.filter= "blendTrans(duration=1.5)";
		}
this.firstPos= this.pos= pos;this.css.left= pos.x;this.css.top=pos.y;this.size=size;this.layerClip= new Rectangle(new Coord(0,0), size);this.scrClip= null;this.nextHtml= this.curHtml= this.fadeHTML= "";this.brother= null;this.lastMovementIndex= 0;this.speed= 50;this.ownerObject= null;this.alwaysVisible= false;this.hiding= false;this.moveTo= layerObjMoveTo;this.moveBy= layerObjMoveBy;this.moveToOrigin= new Function("this.moveTo(this.firstPos.x,this.firstPos.y)");this.slideCircle= slideCircle;this.slideFromTo= slideFromTo;this.hide= hide;this.show= show;this.addHtml= addHtml;this.addLinkToHtml= addLinkToHtml;this.addPreImageToHtml= addPreImageToHtml;this.rewrite= rewrite;this.renderAndShow= new Function("this.rewrite();this.show()");this.fadeText= fadeText;this.clear= new Function("this.nextHtml='';this.rewrite('')");this.setColor= setColor;this.sendToBack= sendToBack;this.sendToFront= sendToFront;this.resize= resizeLayer;this.resizeClip= resizeClip;this.resizeClipBy= resizeClipBy;this.resizeToOrigin= new Function("this.resize(this.firstWidth,this.firstHeight)");this.setClip= setClip;this.setScrClip= setScrClip;this.slideClipTo= slideClipTo;this.isAllowedMovement= isAllowedMovement;this.resize(size.width,size.height);this.app.layers[this.app.layers.length]= this.app.layers[id]= this;this.page.assignLayer(this);return this}
function hide(noFade) {var thisLayer= (this.type==LAYER_TYPE?this:this.layer);if(thisLayer.css.visibility== VISIBLE){thisLayer.hiding= true;if(thisLayer.moving){thisLayer.lastMovementIndex++;window.setTimeout("theApp.layers[" + thisLayer.index + "].hide()",50)}else{if(ie4 && !noFade)thisLayer.layer.filters.blendTrans.apply();thisLayer.css.visibility= NOT_VISIBLE;if(ie4 && !noFade)thisLayer.layer.filters.blendTrans.play();thisLayer.hiding= false}}}
function show(noFade) {var thisLayer= (this.type==LAYER_TYPE?this:this.layer);if(thisLayer.css.visibility== NOT_VISIBLE){matchScrClip(thisLayer)
if(ie4 && !noFade)thisLayer.layer.filters.blendTrans.apply();thisLayer.css.visibility= VISIBLE;if(ie4 && !noFade)thisLayer.layer.filters.blendTrans.play()}}
function rewrite(content,valign,align,noMatch) {this.nextHtml= content?content:this.nextHtml;if(this.nextHtml != this.curHtml){if(!valign)valign="top";if(!align)align="left";content= this.nextHtml?"<table width='" + this.size.width + "' height='" + this.size.height + "' border='0' cellpadding='0' cellspacing='0'><tr><td valign='" + valign +"' align='" + align + "'>" + this.nextHtml + "</td></tr></table>":"";if(ns4){this.layer.write(content);this.layer.close();if(!noMatch)matchScrClip(this)}else{this.layer.innerHTML= content}
this.curHtml= this.nextHtml}}
function addHtml(html) {this.nextHtml= this.nextHtml + html}
function addLinkToHtml(id, preImageOff, evalOnClick, label, alt, preImageOn, preImageSel, target, evalOnMouseOver, evalOnMouseOut,size){var lnk= new Link(this, id, preImageOff, evalOnClick, label, alt, preImageOn, preImageSel, target, evalOnMouseOver, evalOnMouseOut,size)
if(lnk)this.nextHtml= this.nextHtml + lnk.getHtml()}
function addPreImageToHtml(prei,size,alt) {if(prei.type!= PREIMAGE_TYPE)prei= this.app.preImages[prei]
this.page.assignPreImage(prei)
this.nextHtml= this.nextHtml + prei.getHtml(size,alt)}
function setColor(c) {var thisLayer= (this.type==LAYER_TYPE?this:this.layer);if(ns4){c=!c?null:c;thisLayer.css.bgColor= c}else{c=!c?"":c;thisLayer.css.backgroundColor= c}}
function layerObjMoveBy(w,h) {w= parseInt(w,10) + parseInt(this.pos.x,10);h= parseInt(h,10) + parseInt(this.pos.y,10);this.moveTo(w,h)}
function layerObjMoveTo(x,y) {this.pos.x=x;this.pos.y=y;this.css.left= this.pos.x;this.css.top= this.pos.y;matchScrClip(this)}
function slideFromTo(pos1,pos2,horinzontally, speed, smooth,infinite,moveIndex,toDoAfter){var x1;var x2;var y1;var y2;var arrived=false;x1= x2= y1= y2= 0;if(horinzontally){x1= pos1;x2=pos2;if(pos1<pos2){if(this.pos.x>=pos2){this.moveTo((infinite?pos1:pos2),this.pos.y);arrived=true}else{this.moveBy(smooth,0)}}else{if(this.pos.x<=pos2){ this.moveTo((infinite?pos1:pos2),this.pos.y);arrived=true}else{this.moveBy(-smooth,0)}}}else{y1= pos1;y2=pos2;if(pos1<pos2){if(this.pos.y>=pos2){this.moveTo(this.pos.x,(infinite?pos1:pos2));arrived=true}else{this.moveBy(0,smooth)}}else{if(this.pos.y<=pos2){this.moveTo(this.pos.x,(infinite?pos1:pos2));arrived=true}else{this.moveBy(0,-smooth)}}}
if(!this.isAllowedMovement(moveIndex) || (arrived&& !infinite) ){ this.moving= false; if(toDoAfter)eval(toDoAfter)} else{toDoAfter= toDoAfter?"'" + toDoAfter +"'":null
var tmp=this.appObjectModelPath +".slideFromTo('" +pos1 + "'," + pos2 + "," +horinzontally + "," + speed + "," + smooth + "," + infinite + "," + moveIndex + "," + toDoAfter + ") ";this.moving= true;window.setTimeout(tmp, (1000 - speed *9))}}
function slideCircle(radius,angle1,angle2,totalSteps,moveIndex,speed,incX,incY,toDoAfter,circleX,circleY,steps){var newX;var newY;var inc;var PI= Math.PI;incX= incX?(isNaN(incX)?0:incX):0;incY= incY?(isNaN(incY)?0:incY):0;steps= steps?(isNaN(steps)?0:steps):0;if(!this.isAllowedMovement(moveIndex) || steps>=totalSteps || angle1<0 || angle2<0 || angle1==angle2){ this.moving= false; if(toDoAfter!="")eval(toDoAfter)} else{if(!speed)speed=this.speed;if(!circleX && circleX!=0){circleX= this.pos.x - radius*Math.cos(angle1);circleY= this.pos.y + radius*Math.sin(angle1)}
newX= parseInt( (circleX + radius*Math.cos(angle1) ),10);newY=parseInt( (circleY - radius*Math.sin(angle1) ) , 10);if(isNaN(newX))newX=0;if(isNaN(newY))newY=0;newX += (incX*steps);newY += (incY*steps);this.moveTo(newX,newY);inc= (angle2-angle1)/(totalSteps-steps);if(!toDoAfter)toDoAfter="";var tmp= this.appObjectModelPath + ".slideCircle(" +radius + "," + (angle1+inc) + "," +angle2 + "," + totalSteps + "," + moveIndex + "," + speed + "," + incX + "," + incY + ",'"+ toDoAfter + "'," + circleX + "," + circleY + "," + (steps+1) + ") ";window.setTimeout(tmp, speed)}}
function isAllowedMovement( mov ){if(!mov || mov != this.lastMovementIndex || this.hiding)
return false;else
return true}
function sendToBack(strictly){if(strictly){this.css.zIndex= MIN_ZINDEX--}else{this.css.zIndex= LAYER_BACK_ZINDEX[this.layerZone]--}}
function sendToFront(strictly){if(strictly){this.css.zIndex= MAX_ZINDEX++}else{this.css.zIndex= LAYER_FRONT_ZINDEX[this.layerZone]++}}
function resizeLayer(){var w= arguments[0]
var h= arguments[1]
if(ns4){this.css.clip.right= w;this.css.clip.bottom= h}else{this.css.width= w + "px";this.css.height= h + "px"}
this.size.set(w,h);matchScrClip(this)}
function resizeClip(w,h){var theW= this.layerClip.coord1.x + w;var theH= this.layerClip.coord1.y + h;if(ns4){this.css.clip.right=theW;this.css.clip.bottom= theH}else{this.css.clip= "rect("+this.layerClip.coord1.y+"px," + theW + "px,"+theH+"px,"+this.layerClip.coord1.x+"px)"}
this.layerClip.size.width=w;this.layerClip.size.height= h}
function resizeClipBy(w,h){ this.resizeClip(this.layerClip.size.width + w, this.layerClip.size.height + h)}
function setClip(x,y){var newR= x+this.layerClip.size.width;var newB= y+this.layerClip.size.height;if(ns4){this.css.clip.left= x;this.css.clip.top= y;this.css.clip.right= newR;this.css.clip.bottom= newB}else{this.css.clip= "rect("+y+"px," + newR + "px,"+newB+"px,"+x+"px)"}
this.layerClip.coord1.x= x;this.layerClip.coord1.y= y}
function slideClipTo(xy,horinzontally,smooth,speed,indexControl){var pos1= 0;var pos2= xy
var arrived= false;if(indexControl==this.lastMovementIndex ){if(horinzontally){pos1= this.layerClip.coord1.x;if(pos1<pos2){if(pos2-pos1<11)smooth=1;this.setClip(pos1+smooth,this.layerClip.coord1.y)}else{if(pos2<pos1){if(pos1-pos2<11)smooth=1;this.setClip(pos1-smooth,this.layerClip.coord1.y)}else{arrived= true}}}else{pos1= this.layerClip.coord1.y;if(pos1<pos2){if(pos2-pos1<11)smooth=1;this.setClip(this.layerClip.coord1.x,pos1+smooth)}else{if(pos2<pos1){if(pos1-pos2<11)smooth=1;this.setClip(this.layerClip.coord1.x,pos1-smooth)}else{arrived= true}}}
if(!arrived)window.setTimeout('theApp.layers["' + this.id + '"].slideClipTo(' + xy + ',' + horinzontally + ',' + smooth + ',' + speed + ',' + indexControl + ')', speed)}}
function setScrClip(t,b,l,r){var thisLayer= (this.type==LAYER_TYPE?this:this.layer);if(!thisLayer.scrClip){thisLayer.scrClip= new Rectangle(new Coord(l,t), new Coord(r,b))}else{thisLayer.scrClip.setCoord1(l,t);thisLayer.scrClip.setCoord2(r,b)}
if(thisLayer.css.visibility== VISIBLE)matchScrClip(thisLayer)}
function fadeText(col1,col2,steps,cont,noMatch){if(this.css.visibility== NOT_VISIBLE)return
var className= (ns4?"normaldataNS":"normaldataIE");var font1= "<DIV class='" + className + "'><FONT color='";var font2= "' >";var font3= "</FONT></DIV>";var theColor;if(steps>0){var col1arr= new Array(parseInt(col1.substring(1,3),16),parseInt(col1.substring(3,5),16),parseInt(col1.substring(5,7),16));var col2arr= new Array(parseInt(col2.substring(1,3),16),parseInt(col2.substring(3,5),16),parseInt(col2.substring(5,7),16));theColor= "#";for(var i=0;i<3;i++){var inc= (col2arr[i] - col1arr[i])/steps;col1arr[i]= parseInt(col1arr[i] + inc ,10);if(col1arr[i].toString(16).length==1)theColor= theColor + "0";theColor= theColor + "" + col1arr[i].toString(16)}}else{theColor= col2}
if(cont)this.fadeHTML= cont;else cont= this.fadeHTML;this.nextHtml= font1 + theColor + font2 + cont + font3;if(ns4)this.rewrite(null,null,null,true);else this.rewrite();if(steps>0) {var tmp= 'theApp.layers["' + this.id + '"].fadeText("'+ theColor + '","' + col2 + '",' + (steps-1) + ',null,true)';window.setTimeout(tmp , 50)}else{if(this.ownerObject && this.ownerObject.type==TEXT_TYPE){if(this.ownerObject.shadow== this || !this.ownerObject.usingShadow){this.ownerObject.finishShowOrHide()}}}}
function matchScrClip(layer){if(layer.scrClip != null){var lx1= layer.pos.x;var lx2= layer.pos.x + layer.size.width;var scl= layer.scrClip.left;var scr= layer.scrClip.right;var ly1= layer.pos.y;var ly2= layer.pos.y + layer.size.height;var sct= layer.scrClip.top;var scb= layer.scrClip.bottom;var newClipX= newClipY= newClipWidth= newClipHeight= 0;if(lx1<scr){if(lx1<scl){if(lx2<scl){newClipX= 0;newClipWidth= 0}else{if(lx2<scr){newClipX= scl-lx1;newClipWidth= lx2-scl}else{newClipX= scl-lx1;newClipWidth= scr-scl}}}else{if(lx2<scr){newClipX= 0;newClipWidth= layer.size.width}else{newClipX= 0;newClipWidth= scr-lx1}}}else{newClipX= 0;newClipWidth= 0}
if(ly1<scb){if(ly1<sct){if(ly2<sct){newClipY= 0;newClipHeight= 0}else{if(ly2<scb){newClipY= sct-ly1;newClipHeight= ly2-sct}else{newClipY= sct-ly1;newClipHeight= scb-sct}}}else{if(ly2<scb){newClipY= 0;newClipHeight= layer.size.height}else{newClipY= 0;newClipHeight= scb-ly1}}}else{newClipY= 0;newClipHeight= 0}
layer.setClip(newClipX,newClipY);layer.resizeClip(newClipWidth,newClipHeight)}}
