var prev_color = 0;
var myedit;
var	current_color;
var	site_height = 0;
//mypinEdit = system.objects.pinedit; //geht nicht weil es da system noch nicht gibt
function pinonload(){
	if(!system.objects.pinedit)
		system.objects.pinedit = document.getElementById(system.vars.pinedit).contentWindow;
		
	if(site_height == 0){
		site_height = (document.body.offsetHeight-40)+"px";
//		document.getElementById('content').style.height = site_height;
		document.getElementById(system.vars.pinedit).style.height = site_height;
	}
	
	//system.objects.pinedit.document.getElementById('pinEdit').contentWindow.document.execCommand("undo", false, null);

	mypinEdit = system.objects.pinedit;
	current_color = 0;
	myedit = document.getElementById(system.vars.pinedit);

	while(myedit){

		if(myedit.bgColor)
			current_color = myedit.bgColor;

		if(myedit.style && myedit.style.background)
			current_color = myedit.style.background;

		if(myedit.backgroundColor)
			current_color = myedit.backgroundColor;


		if(myedit.id)
			if(css.findRule("#"+myedit.id))
				current_color = css.findRule("#"+myedit.id).style.backgroundColor;		
	
		if(myedit.className)
			if(css.findRule("."+myedit.className))
				current_color =  css.findRule("."+myedit.className).style.backgroundColor;

		if(current_color)	myedit = 0;
		else myedit = myedit.parentNode;
	}

//alert(document.getElementById('site').offsetHeight);
	//alert(current_color);
	
	system.objects.pinedit.document.getElementById('pinEdit').contentWindow.document.body.style.background = current_color;

	if(browser.ie) prev_color = system.objects.pinedit.document.body.style.backgroundColor;
	else prev_color = system.objects.pinedit.document.body.style.background;
	
	
}

function __pinonload(){
	try {
		pinonload();
	} catch(error){
		setTimeout("__pinonload()",200);
	}
}

//__pinonload();


function mypreview(){
	prev_color = system.objects.pinedit.document.body.style.backgroundColor;
	system.objects.pinedit.document.body.style.backgroundColor = current_color;
	//system.objects.pinedit.document.body.style.margin = "0px";
}

function mymain(){
	if(browser.ie) system.objects.pinedit.document.body.style.backgroundColor = prev_color;
	else system.objects.pinedit.document.body.style.background = prev_color;

	//system.objects.pinedit.document.body.style.margin = "1px 2px 2px";
	
}

	// Versuch Toolbar auszuklinken
	/*
	edit_doc = document.getElementById('pinEditID1').contentWindow.document;
	toolbar_top = edit_doc.getElementById('toolbar_top').contentWindow.document;
	document.getElementsByTagName( 'head' )[ 0 ] = edit_doc.getElementsByTagName( 'head' )[ 0 ];
	mysrc = edit_doc.getElementById('toolbar_top').src;
	document.getElementById('footer').appendChild(edit_doc.getElementById('toolbar_top'));
	document.getElementById('toolbar_top').src = mysrc;
	*/

function save_pinedit(){

	eval(system.vars.pinedit_save);

	if(!document.form_tbs.table_edit){
		document.form_tbs.editor_action.value = "save";
		document.form_tbs.submit();
	}
}

function cancle_pinedit(){
	document.form_tbs.editor_action.value = "cancle";
	document.form_tbs.submit();
}


function openLink(){
	test = false;
	if(browser.ie && test){
		mypinEdit.editLink();
		return;
	}
	mytop = ((screen.height.toString().replace('px','')-180)/2)+'px';
	myleft = ((screen.width.toString().replace('px','')-450)/2)+'px';

	if(browser.ie) linkfile = "link_ie.html";
	else linkfile = "link_ff.html";

	mylinkdialog = window.open(STARTPATH+"sys/templates/de/_sys/pinEdit/html/"+linkfile, "", "width=450,height=180,top="+mytop+",left="+myleft+",scrollbar=no");
		
}

