var item_class=new Array,item_id=new Array,item_w=new Array,item_h=new Array,item_x=new Array,item_y=new Array,item_stat=new Array,item_zIndex=new Array;
var item_no=0;
var level1_color="";
var level2_class="";
var level1_width=150;
var level2_width=150;
var level1_off_x=0;
var level2_off_x=0;
var level_off_y=111;
item_y[0]=0;
item_x[0]=0;
item_h[0]=level_off_y;
item_y[-1]=0;
item_x[-1]=0;
item_h[-1]=level_off_y;
var int_id=-1;
var range=0;
var k=0;
var temp_height;

function update_maintable(off) {
	s=0;
	for (i=0;i<=item_no;i++){
		if (item_zIndex[i]==3) {s+=item_h[i];}
	}
	s+=off;
	document.getElementById("maincell").height=s;
}

function setColors(level1,level2){
	level1_color=level1;
	level2_color=level2;
	}

function up(item_n) {
	k=k+4;
	for(var i=item_n;i<=item_no;i++) {
		if (item_zIndex[i]==2) {item_zIndex[i]=0;}
	}
	item_zIndex[item_n]=2;
	for(var i=item_n;i<=item_no;i++) {
		document.getElementById(("zona"+i)).style.top=item_y[i]-k;
		document.getElementById(("zona"+i)).style.zIndex=item_zIndex[i];
	}
	if (k>=range) {clearInterval(int_id);
					int_id=-1;
						for(var i=item_n;i<=item_no;i++) {
						item_y[i]=item_y[i]-range;
						}
					update_maintable(0);}
	else {update_maintable(range-k);}
}

function down(item_n) {
	k=k+4;
	for(var i=item_n;i<=item_no;i++) {
		if (item_zIndex[i]==2) {item_zIndex[i]=0;}
	}
	item_zIndex[item_n]=2;
	for(var i=item_n;i<=item_no;i++) {
		document.getElementById(("zona"+i)).style.top=item_y[i]+k;
		document.getElementById(("zona"+i)).style.zIndex=item_zIndex[i];
	}
	if (k>=range) {clearInterval(int_id);
			int_id=-1;
				for(var i=item_n;i<=item_no;i++) {
				item_y[i]=item_y[i]+range;
				}
   				document.getElementById(("zona"+item_n)).style.zIndex=3;
				item_zIndex[item_n]=3;
				update_maintable(0);}
	else {update_maintable(k);}
}

function change_stat(item_n) {
	var str="zona"+item_n;
	if (int_id==-1) {
	if (item_stat[item_n]==1) {item_stat[item_n]=0;
							   item_zIndex[item_n]=0;
							   range=item_h[item_n];
							   k=0;
							   int_id=setInterval("up("+item_n+")",15);}
					    else  {item_stat[item_n]=1;
							   range=item_h[item_n];
							   k=0;
							   int_id=setInterval("down("+item_n+")",15);}}

	return false;
}

function create_item(level,content,height,expanded,level2_add) {
	if (level2_add==0) {
	item_no++;
	item_stat[item_no]=expanded;
	}
	if (level=="level1") {	item_zIndex[item_no]=3;
						 item_class[item_no]=1;
						 item_id[item_no]="zona"+item_no;
						 item_w[item_no]=level1_width;
						 item_h[item_no]=height;
						 item_x[item_no]=level1_off_x;
						 if (item_stat[item_no-1]==0) {item_y[item_no]=item_y[item_no-2]+item_h[item_no-2];}
						 	else {item_y[item_no]=item_y[item_no-1]+item_h[item_no-1];}
						 document.write("<div align=\"center\" style=\"background-color:"+level1_color+";height:"+item_h[item_no]+"; width:"+item_w[item_no]+"; position:absolute; left:"+item_x[item_no]+"; top:"+item_y[item_no]+"; z-index:3;\" id=\""+item_id[item_no]+"\"><a style=\"color: #FFFFFF\" class=\"regularlink2\" href=\"#\" onclick=\"return change_stat("+(item_no+1)+")\">"+content+"</a></div>");	update_maintable(0);}
						 
	if ((level=="level2") && (level2_add==0)) {	if (expanded==1) {item_zIndex[item_no]=3;}
									else {item_zIndex[item_no]=0;}
						 item_class[item_no]=2;
						 item_id[item_no]="zona"+item_no;
						 item_w[item_no]=level2_width;
						 item_h[item_no]=height;temp_height=0;
						 item_x[item_no]=level2_off_x;
						 if (expanded==0) {item_y[item_no]=item_y[item_no-1]+(item_h[item_no-1]-item_h[item_no]);
						 		   document.write("<div style=\"background-color:"+level2_color+";height:0"+"; width:"+item_w[item_no]+"; position:absolute; left:"+item_x[item_no]+"; top:"+item_y[item_no]+"; z-index:0;\" id=\""+item_id[item_no]+"\">");}
						 	else {item_y[item_no]=item_y[item_no-1]+item_h[item_no-1];
						 		document.write("<div style=\"background-color:"+level2_color+";height:0"+"; width:"+item_w[item_no]+"; position:absolute; left:"+item_x[item_no]+"; top:"+item_y[item_no]+"; z-index:3;\" id=\""+item_id[item_no]+"\">");}
						 }
						 
	if ((level=="level2") && (level2_add==1)) {
						 //document.write("<div style=\"background-color:"+level2_color+";height:"+height+"; width:"+item_w[item_no]+"; position:absolute; left:"+item_x[item_no]+"; top:"+item_y[item_no]+";\">"+content+"</div>");
						 document.write("<div style=\"background-color:"+level2_color+";height:"+height+";\">"+content+"</div>");
						 }
						 
	if ((level=="level2") && (level2_add==2)) {
						document.write("</div>");	update_maintable(0);
						}				
}