COSEconfig = new Array();
COSEconfig['templateFolder'] = 'default/';
COSEconfig['Workflow'] = 'overview,create,entities,textedit,media,embedding,publisher';
COSEconfig['desktopHandlerScript'] = '/external/cose/v2/js/desktop/desktopHandler.js';
COSEconfig['lLightVideoTypeIDs'] = '41,42,43';
COSEconfig['CBOXArticleOverview'] = 'http://cbox.computec.de/?dll=0501';
COSEconfig['SystemJSscripts'] = 'pluginControlHandler,ajaxControlHandler,draftControlHandler';
COSEconfig['formTextElementHeightLight'] = 358;
COSEconfig['formTextStep5ElementHeightLight'] = 463;
COSEconfig['backgroundLayer'] = 'COSEbackgroundLayer';
COSEconfig['editmodus'] = 'cbox';
COSEconfig['desktopFrameEntityHeight'] = 700;
COSEconfig['lEditorialReviewTypeIDs'] = '2,3,4,23,30,40,46';
COSEconfig['desktopLayer'] = 'COSEdesktopLayer';
COSEconfig['desktopFrameArticleHeight'] = 700;
COSEconfig['formElementsWidth'] = 530;
COSEconfig['overallCloseButton'] = 'COSEcloseButton';
COSEconfig['ajaxControlHandler'] = '/external/cose/v2/js/system/ajaxControlHandler.js';
COSEconfig['formTextElementHeight'] = 312;
COSEconfig['formTextStep5ElementHeight'] = 463;
COSEconfig['lVideoTypeIDs'] = '15,41,42,43';
COSEconfig['pluginControlHandler'] = '/external/cose/v2/js/system/pluginControlHandler.js';
COSEconfig['CBOXEntityOverview'] = 'http://cbox.computec.de/?dll=0401';
COSEconfig['mainDesktopFrame'] = 'COSEmainDesktopFrame';
COSEconfig['lEntityTypes'] = '';
COSEconfig['DesktopJSscripts'] = 'desktopHandlerScript,controlHandlerScript';
COSEconfig['desktopFrameEntityWidth'] = 1000;
COSEconfig['controlHandlerScript'] = '/external/cose/v2/js/desktop/controlHandler.js';
COSEconfig['scriptPath'] = '/external/cose/v2/';
COSEconfig['desktopFrameArticleWidth'] = 1000;
COSEconfig['draftControlHandler'] = '/external/cose/v2/js/system/draftControlHandler.js';
COSEconfig['plugins'] = 'overview,create,authors,textedit,entities,media,images,image_upload,image_sort,videos,assets,embeddedhtml,media_embeddedhtml,extended_embedding,html_editor,embedding,links,csv,statements,rating,gamesvote,publisher';


// ---------------------- including ../js/desktop/desktopHandler.js ----------------------
// #########################################################################
// Desktop-Handler
// This script is only for the activation of the COSE edit layer (article or 
// entity). It creates two div-layers to "grey-out" the background and open 
// the COSE system in an iframe. All following tasks are running in this iframe
// - Author: Marc Polatschek
// #########################################################################

function cbox_edit_start(object, object_id, cbmode, editlayerWidth, editlayerHeight)
	{
	var framesrc = COSEconfig['scriptPath']
	if (object_id == null)
		{
		framesrc = framesrc + '?cbobject=' + object + '&cbmode=new';
		}
	else
		{
		framesrc = framesrc + '?cbobject=' + object + '&cbid=' + object_id + '&cbmode=' + cbmode;
		}
	// create desktop layers if needed
	createBasicElements(object, framesrc);
	}

function cbox_editlayer_stop() {
	try {
		//ff, ie
		window.onbeforeunload = null;
		//webkit
		top.window.onbeforeunload = null;		
		parent.document.body.style.overflow = 'auto'; 
		parent.document.getElementsByTagName('body')[0].removeChild(parent.document.getElementById(COSEconfig['backgroundLayer']));
	}
	catch(e) { 
		//alert('error' + e);
		//for social sites, permission is denied to close layer, as this script comes from another subdomain
		//parent.cbox_editlayer_stop();
	}
}

iframeCreated = 0;

// creating basic layers for onsite-editing
function createBasicElements(object, framesrc) {
	// checking and creating layers
	// checking for transparent backgroundlayer to "grey out" current site and create it if needed
	if (document.getElementById(COSEconfig['backgroundLayer']) == null) {
		// creating the "grey-out" layer
		var backgroundLayer = document.createElement('div');
		backgroundLayer.setAttribute('id',COSEconfig['backgroundLayer']);
		document.getElementsByTagName('body')[0].appendChild(backgroundLayer);

		// creating the "white" desktop layer
		var desktopLayer = document.createElement('div');
		desktopLayer.setAttribute('id',COSEconfig['desktopLayer']);
		if(object == 'article') {
			desktopLayer.style.width = COSEconfig['desktopFrameArticleWidth'] + 'px';
			desktopLayer.style.height = COSEconfig['desktopFrameArticleHeight'] + 'px';
		}
		else {
			desktopLayer.style.width = COSEconfig['desktopFrameEntityWidth'] + 'px';
			desktopLayer.style.height = COSEconfig['desktopFrameEntityHeight'] + 'px';
		}
		document.getElementById(COSEconfig['backgroundLayer']).appendChild(desktopLayer);
		
		// creating the desktop iframe and loading onsite-editing
		myDate = new Date();
		myDateMillisec = myDate.getMilliseconds();
		myDate.setTime(myDate.getTime() + 87765);
		document.cookie = 'coseiframe=' + myDateMillisec + '; path=/;expires=' + myDate.toGMTString();
		var mainDesktopFrame = document.createElement('iframe');
		mainDesktopFrame.setAttribute('id',COSEconfig['mainDesktopFrame'] + myDateMillisec);
		mainDesktopFrame.setAttribute('name',COSEconfig['mainDesktopFrame'] + myDateMillisec);
		mainDesktopFrame.setAttribute('src',framesrc);
		mainDesktopFrame.setAttribute('scrolling','no');
		mainDesktopFrame.setAttribute('align','middle');
		mainDesktopFrame.setAttribute('frameborder','0');	
		if(object == 'article') {
			mainDesktopFrame.style.width = COSEconfig['desktopFrameArticleWidth'] + 'px';
			mainDesktopFrame.style.height = COSEconfig['desktopFrameArticleHeight'] + 'px';
		}
		else {
			mainDesktopFrame.style.width = COSEconfig['desktopFrameEntityWidth'] + 'px';
			mainDesktopFrame.style.height = COSEconfig['desktopFrameEntityHeight'] + 'px';
		}
		document.getElementById(COSEconfig['desktopLayer']).appendChild(mainDesktopFrame);
	}
}

function resizeDesktopLayer(doWhat)
	{
	var PluginWidth = COSEconfig['desktopFrameArticleWidth'] + COSEconfig['desktopFrameArticlePluginWidth'];														  

	if (doWhat == 'open')
		{
		document.getElementById(COSEconfig['desktopLayer']).style.width = PluginWidth + 'px';
		document.getElementById(COSEconfig['mainDesktopFrame']).style.width = PluginWidth + 'px';
		}
	else if (doWhat == 'close')
		{
		document.getElementById(COSEconfig['desktopLayer']).style.width = COSEconfig['desktopFrameArticleWidth'] + 'px';			
		document.getElementById(COSEconfig['mainDesktopFrame']).style.width = COSEconfig['desktopFrameArticleWidth'] + 'px';
		}
	} 

// ---------------------- including ../js/desktop/controlHandler.js ----------------------
function coseControls(type,uid)
	{
	if (typeof COSEconfig != 'undefined')
		{
		switch(type)
			{
			case "article":
				coseControlsArticle(uid);
				break;
			case "entity":
				coseControlsEntity(uid);
				break;				
			default:
				document.write('ERROR: Funktionsset nicht gefunden!');
				break;
			}
		}
	}
	
function coseControlsEntity(uid)
	{
	if (typeof COSEconfig != 'undefined')
		{
		document.write('<ul>');
		// Edit-Button
		document.write('<li><a onclick=\"cbox_edit_start(\'entity\', ' + uid + ', \'requestupdate\', ' + COSEconfig['desktopFrameEntityWidth'] + ', ' + COSEconfig['desktopFrameEntityHeight'] + ');\">Entität bearbeiten</a></li>');
		// View-Button
		document.write('<li><a onclick=\"cbox_edit_start(\'entity\', ' + uid + ', \'display\', ' + COSEconfig['desktopFrameEntityWidth'] + ', ' + COSEconfig['desktopFrameEntityHeight'] + ');\">Entwurf anzeigen</a></li>');
		// Create-Button
		document.write('<li><a onclick=\"cbox_edit_start(\'entity\', 1, \'new\', ' + COSEconfig['desktopFrameEntityWidth'] + ', ' + COSEconfig['desktopFrameEntityHeight'] + ');\">Neue Entität anlegen</a></li>');
		document.write('</ul>');
		}
	}
	
function coseControlsArticle(uid)
	{
	if (typeof COSEconfig != 'undefined')
		{
		document.write('<ul>');
		// Edit-Button
		document.write('<li><a onclick=\"cbox_edit_start(\'article\', ' + uid + ', \'requestupdate\', ' + COSEconfig['desktopFrameArticleWidth'] + ', ' + COSEconfig['desktopFrameArticleHeight'] + ');\">Artikel bearbeiten</a></li>');
		// View-Button
		document.write('<li><a onclick=\"cbox_edit_start(\'article\', ' + uid + ', \'display\', ' + COSEconfig['desktopFrameArticleWidth'] + ', ' + COSEconfig['desktopFrameArticleHeight'] + ');\">Entwurf anzeigen</button></a>');
		// Create-Button
		document.write('<li><a onclick=\"cbox_edit_start(\'article\', \'\', \'new\', ' + COSEconfig['desktopFrameArticleWidth'] + ', ' + COSEconfig['desktopFrameArticleHeight'] + ');\">Neuen Artikel anlegen</a></li>');
		document.write('</ul>');
		}
	} 
