function init(doit){
	for (i=0; document.getElementById('div_open_'+i+'_0'); i++) for (k=0; d=document.getElementById('div_open_'+i+'_'+k); k++) {
		var childs=d.getElementsByTagName('div');
		for(j=0;j<childs.length;j++){
			var id=childs[j].id.split('_');
			if(id[0] == 'yyy'){
				var yyy=document.getElementById(childs[j].id);
				//alert(yyy.innerHTML);
				if(yyy.innerHTML == 0){
					name=yyy.getAttribute('name');
					tmp=name.split('_');
					if(doit == 1){
						innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');aj('+id[1]+', \'edit\',\'div_element_child_'+tmp[2]+'_'+tmp[3]+'\');change_class(\''+childs[j].id+'\',\'xxx\');">';
					}else{
						if(document.getElementById(name).style.display == 'none' && yyy.className=='xxx'){
							innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');">';
						}else{
							innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');aj('+id[1]+', \'edit\',\'div_element_child_'+tmp[2]+'_'+tmp[3]+'\');change_class(\''+childs[j].id+'\',\'xxx\');">';
						}
					}
					innertxt+=			'<tr>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
											'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
												'<div class="count_change">'+
													meb_select+
												'</div>'+
											'</td>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
										'</tr>'+
									'</table><div class="small_br"></div>';
					document.getElementById(name+'-title').innerHTML=innertxt;
					//add_event(name+'-title', 'click', name);
				}else{
					name=yyy.getAttribute('name');
					tmp=name.split('_');
					if(doit == 1){
						innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');aj('+id[1]+', \'edit\',\'div_element_child_'+tmp[2]+'_'+tmp[3]+'\');change_class(\''+childs[j].id+'\',\'xxx\');">';
					}else{
						if(document.getElementById(name).style.display == 'none' && yyy.className=='xxx'){
							innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');">';
						}else{
							innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');aj('+id[1]+', \'edit\',\'div_element_child_'+tmp[2]+'_'+tmp[3]+'\');change_class(\''+childs[j].id+'\',\'xxx\');">';
						}
					}
					innertxt+=			'<tr>'+
												'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
													'&nbsp;'+
												'</td>'+
												'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
													'<div class="count_change">'+
														meb_change+
													'</div>'+
												'</td>'+
												'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
													'&nbsp;'+
												'</td>'+
											'</tr>'+
										'</table>'+
										'<div class="small_br"></div>';
					document.getElementById(name+'-title').innerHTML=innertxt;
					//add_event(name+'-title', 'click', name);
				}
				//alert('asas');
			}
			//alert(id);
		}
	}
	close_galleries_div();
}
function init_edit(){
	for (i=0; document.getElementById('div_open_'+i+'_0'); i++) for (k=0; d=document.getElementById('div_open_'+i+'_'+k); k++) {
		var childs=d.getElementsByTagName('div');
		for(j=0;j<childs.length;j++){
			var id=childs[j].id.split('_');
			if(id[0] == 'yyy'){
				var yyy=document.getElementById(childs[j].id);
				//alert(yyy.innerHTML);
				if(yyy.innerHTML == 0){
					name=yyy.getAttribute('name');
					innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');">';
					innertxt+=			'<tr>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
											'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
												'<div class="count_change">'+
													meb_select+
												'</div>'+
											'</td>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
										'</tr>'+
									'</table><div class="small_br"></div>';
					document.getElementById(name+'-title').innerHTML=innertxt;
					//add_event(name+'-title', 'click', name);
				}else{
					name=yyy.getAttribute('name');
					innertxt='<div class="small_br"></div><table cellspacing="0" cellspacing="0"  onclick="open_gallery(\''+name+'\');">';
					innertxt+=			'<tr>'+
												'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
													'&nbsp;'+
												'</td>'+
												'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
													'<div class="count_change">'+
														meb_change+
													'</div>'+
												'</td>'+
												'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
													'&nbsp;'+
												'</td>'+
											'</tr>'+
										'</table>'+
										'<div class="small_br"></div>';
					document.getElementById(name+'-title').innerHTML=innertxt;
					//add_event(name+'-title', 'click', name);
				}
				//alert('asas');
			}
			//alert(id);
		}
	}
	close_galleries_div();
}
function open_gallery(id){
	var div=document.getElementById(id);
	if(div){
		close_galleries_div();
		document.getElementById(div.id+'-title').innerHTML='<div class="small_br"></div>'+
																'<table cellspacing="0" cellspacing="0" onclick="close_galleries_div();">'+
																	'<tr>'+
																		'<td width="9" height="27" style="background: url('+img_link+'change_act_left.gif) right center no-repeat;">'+
																			'&nbsp;'+
																		'</td>'+
																		'<td height="27" width="77" style="background: url('+img_link+'change_act_px.gif) right center repeat-x;">'+
																			'<div class="count_change_act" onmouseover="this.style.textDecoration=\'underline\';" onmouseout="this.style.textDecoration=\'none\';">'+
																				meb_close+
																			'</div>'+
																		'</td>'+
																		'<td width="9" height="27" style="background: url('+img_link+'change_act_right.gif) left center no-repeat;">'+
																			'&nbsp;'+
																		'</td>'+
																	'</tr>'+
																'</table>';
		div.style.display = 'block';
		id=div.id;
		tmp=id.split('_');
		gid=tmp[3];
		elid=tmp[2];
		div_child=document.getElementById('div_element_child_'+elid+'_'+gid);
		var top=getElementTop(id)-26;
		var left=getElementLeft('div_location_'+gid)-30;
		div_child.style.position="absolute";
		div_child.style.left=left+'px';
		div_child.style.top=top+'px';
		div_child.style.zIndex='2';
		document.getElementById('div_element_'+elid+'_'+gid).style.height = document.getElementById('div_element_child_'+elid+'_'+gid).clientHeight+'px';		
	}
}
function close_galleries_div(){
	//var galleries_div=$(divid);
	//for(i=0;i<galleries_div.length;i++){
	for (i=1; galleries_div=document.getElementById('div_open_div_'+i); i++){
		child_div=galleries_div.childNodes;
		for(k=0;k<child_div.length;k++){
			if(child_div[k].tagName == 'DIV'){
				if(child_div[k].style.display != 'none'){
					child_div[k].style.display = 'none';
					var gal_but_name=document.getElementById(child_div[k].id+'-title').getAttribute('name');
					var yyy=document.getElementById(gal_but_name);
					if(yyy.innerHTML == 0){
						name=yyy.getAttribute('name');
						document.getElementById(name+'-title').innerHTML='<div class="small_br"></div><table cellspacing="0" cellspacing="0" onclick="open_gallery(\''+name+'\');">'+
											'<tr>'+
												'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
													'&nbsp;'+
												'</td>'+
												'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
													'<div class="count_change">'+
														meb_select+
													'</div>'+
												'</td>'+
												'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
													'&nbsp;'+
												'</td>'+
											'</tr>'+
										'</table><div class="small_br"></div>';
						//add_event(name+'-title', 'click', name);
					}else{
						name=yyy.getAttribute('name');
						document.getElementById(name+'-title').innerHTML='<div class="small_br"></div><table cellspacing="0" cellspacing="0" onclick="open_gallery(\''+name+'\');">'+
																				'<tr>'+
																					'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
																						'&nbsp;'+
																					'</td>'+
																					'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
																						'<div class="count_change">'+
																							meb_change+
																						'</div>'+
																					'</td>'+
																					'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
																						'&nbsp;'+
																					'</td>'+
																				'</tr>'+
																			'</table><div class="small_br"></div>';
						//add_event(name+'-title', 'click', name);
					}
				}
			}
		}
	}
}
function clear_sub_price(){
	for (i=0; document.getElementById('div_open_'+i+'_0'); i++) for (k=0; d=document.getElementById('div_open_'+i+'_'+k); k++) {
		var childs=d.getElementsByTagName('div');
		for(j=0;j<childs.length;j++){
			var id=childs[j].id.split('_');
			if(id[0] == 'yyy'){
				var yyy=document.getElementById(childs[j].id);
				yyy.innerHTML=0;
			}
		}
	}
}
function add_event(target, tasktype, functionref){
	//alert(functionref);
	document.getElementById(target).setAttribute('onmousedown', "open_gallery('"+name+"')");
	document.getElementById(target).innerHTML='xxx';
	//document.getElementById(target).setAttribute('onclick', "alert('dsfsdfsdf');");
	//addEvent(document.getElementById(target), 'onclick', "alert('sadass')");
	//alert(document.getElementById(target).getAttribute('onmousedown'))
	return false;
}
function change_class(id,classname){
	$(id).className=classname;
}
