var TabMap = new Array();
var cmsTimerLock=0;
function initCMS(pagenum) {
	var divs = new Array('leftcol','main1','main2','box1','box2','box3');
	var thisDiv;
	for (i=0;i<divs.length;i++) {
		thisDiv = divs[i];
			
		TabMap[thisDiv+"edit"] = i+1;	
		var imgTag = document.createElement("img");
		imgTag.setAttribute('src',"/media/edit.gif");
		imgTag.id = thisDiv+"edit";
		imgTag.title = "Bearbeiten";
		imgTag.style.position = 'absolute';
		imgTag.style.right = '0px';
		imgTag.style.margin = '2px';
		imgTag.style.visibility = 'hidden';
		imgTag.onclick = function () { 
			if (cmsTimerLock) return;
			cmsTimerLock=1;
			setTimeout("cmsTimerLock=0;",1000);
			window.open('/cms/pageform.php?PAGE_ID='+pagenum+'&SHOWTAB='+TabMap[this.id]+'&seed='+Math.random(),'pagewin'+pagenum,'width=780px,height=750px,left=0,top=0'); 
			return;

			var outer = this.parentNode;
			while (outer.hasChildNodes()) {
				outer.removeChild(outer.firstChild)
			}
			var editframe = document.createElement("iframe");			
			editframe.id = "DATA_MAIN1_TEXT___Frame";
			editframe.setAttribute("src","/fck/editor/fckeditor.html?InstanceName=DATA_MAIN1_TEXT&amp;Toolbar=Schatztruhe");
			editframe.style.width = '500px';
			editframe.style.height = '300px';
			editframe.style.border = '0';
			editframe.style.scrolling = 'no';
			outer.appendChild(editframe); 		

		}
			
		var myDiv = document.getElementById(thisDiv);
		
		if (!myDiv.hasChildNodes()) {
			var placeholder = document.createElement("p");
			placeholder.className = 'placoholder';
			placeholder.style.border = '1px dashed blue';
			placeholder.style.height = '100px';
			placeholder.style.margin = '5px';
			myDiv.appendChild(placeholder); 		
		}
		myDiv.insertBefore(imgTag,myDiv.firstChild); 	
		myDiv.onmouseover = function () { this.style.backgroundColor='#c0c0c0'; document.getElementById(this.id+'edit').style.visibility='visible'; }
		myDiv.onmouseout = function () {  this.style.backgroundColor='white'; document.getElementById(this.id+'edit').style.visibility='hidden'; }
	}	
	
	var mn = document.getElementById('mainnav');
	var item = document.createElement('h1');
	item.style.color='red';
	item.style.paddingTop='5px';
	item.onclick=function() {window.open('/cms/pageform.php?PAGE_ID=-1&SHOWTAB=1&seed='+Math.random(),'pagewin'+pagenum,'width=780px,height=750px,left=0,top=0,scrollbars=yes,resizeable=yes;'); }
	item.appendChild(document.createTextNode('Seite hinzufügen'));	
	mn.appendChild(item);
}
