/**
 * april4 Website
 *
 * @author Chris Rose
 */



function april5() {
	
	this.oMenuID = 'category';
	this.oGridItemsID = 'cg_items';
	this.actOMenuSid=0;
	this.actOGridSid=0;
	this.gridPage=1;
	this.gridItemsLength=9;
	this.gridItems=false;
	this.gridLastItems=false;
	this.gridStoredItems=false;
	this.isInitialized=false;
	
	this.init=function() {
		if(this.isInitialized) return;
		this.isInitialized=true;
		this.user._init();
		var cg_items = Ext.get('cg_items');
		if(cg_items)  {
			this.initialCGItemsHeight = cg_items.getHeight();		
		}
		this.storeGridItems();
		this.gridEvents();
		this.hideEmptyRows();
	}
	
	//---------------------------------------------------------------------------------------
	// Content Grid
	//---------------------------------------------------------------------------------------
	this.stopGridEvents=false;
	this.gridEvents = function() {
		this.stopGridEvents=false;
		var gridItems = Ext.DomQuery.select('.cg-item-inner');
		Ext.each(gridItems, function(el){
			var xEl = Ext.get(el);
			if(xEl) {
				if(AP.user.osPC) {
					xEl.on('mouseenter',function(ev){
						if(AP.stopGridEvents) return;
						var span = xEl.child('span');
						if(span) {
							if(!span.isVisible()) {
								span.slideIn('b', {
									easing: 'easeOut',
									duration: .35
								});							
							}
						}
					},xEl,{});
					
					xEl.on('mouseleave',function(e){
						if(AP.stopGridEvents) return;
						var tgt = e.target || e.srcElement;
						var span = xEl.child('span');
						if(span && span.isVisible()) {
							span.slideOut('b', {
								easing: 'easeIn',
								duration: .5
							});		
						}
					},xEl);		
				} else {
					var span = xEl.child('span');
					if(span) span.show(true);
				}
			}
		});		
	}

	this.loadCategory=function(sid,c,p) {
		
		// fallback to href, if no grid is available
		if(!Ext.get(this.oGridItemsID)) {
			if(Ext.get('cat'+sid)) {
				return location.href = Ext.get('cat'+sid).getAttribute('href');
			}
		}

		var p = p || {};
		//if(sid == this.actOMenuSid && p.page == this.gridPage) return;
		
		// fallback of overlay links
		// if grid navigation of this context is not available 
		if((typeof gridnav != 'undefined'
		&& gridnav != c
		&& p.link)
		|| (typeof gridnav == 'undefined') && p.link) {
			return location.href = p.link;
		}
		
		// close overlay
		if(this.overlay) this.closeOverlay();

		
		this.stopGridEvents=true;
		if(c != 'customer-projects') {
			// disable navigation items
			if(Ext.get(this.oMenuID)) {
				var actMenuItems = Ext.get(this.oMenuID).select('a.on');
				if(actMenuItems) {
					actMenuItems.removeClass('on');
				}
			}
			
			// enable navigation item
			var menuItem = Ext.get('cat'+sid);
			if(menuItem) {
				menuItem.addClass('on');
			}
			this.actOMenuSid=sid;
		}
		// mask?
		
		// params
		var method;
		var params = {noxml:1,rtn:'json'};
		switch(c) {
			case'article':
				params['dpa0'] = 'rubrik';
				params['dpa1'] = ','+sid;
				method='openArticles';
				break;
			case'project':
				params['dpa0'] = 'leistung';
				params['dpa1'] = ','+sid;
				method='openAMProjects';
				break;
			case'customer':
				params['dpa0'] = 'branche';
				params['dpa1'] = ','+sid;
				method='openAMCustomers';
				break;
			case'customer-projects':
				params['dpa0'] = 'kunde';
				params['dpa1'] = ','+sid;
				method='openAMProjects';				
				break;
			default: return false;
		}
		
		if(p.header) this.showGridHeader(sid,c,p);
		else this.hideGridHeader(false);
		if(this.gridItems) this.gridLastItems = Ext.apply({},this.gridItems);
		
		if(typeof p.page != 'undefined') {
			params['p'] = p.page;
			this.gridPage = params.p;
		} else this.gridPage = 1;
		
		if(c=='customer-projects') this.requestGrid.defer(50,this,[sid,c,p,method,params]);
		else this.requestGrid(sid,c,p,method,params);
		
	}
	
	this.requestGrid = function(sid,c,p,method,params) {
		Ext.Ajax.request({
			waitMsg: $L('loading'),
			waitMsgTarget: this.oGridItemsID,
			url: '/ajax/loadmethod/'+method,
			method: 'POST', 
			scope:this,
			context:c,
			params: params,
			failure:function(response,options){
				Ext.MessageBox.alert('Warning','An error occured, please try again later.');
				
			},
			success:function(response,options){
				var responseData = Ext.util.JSON.decode(response.responseText);
				this.gridItems = {
					responseData:responseData,
					options:options
				};
				this.buildGrid(responseData,options);
			}
		 });	
	}
	
	this.navigateGrid=function(page,sid,c,p){
		if(!sid) var sid = this.actOMenuSid;
		var p = p || {};
		p.page = page;
		p.force = true;
		this.loadCategory(sid,c,p);
	}
	
	this.buildGrid = function(d,o) {
		// remove all data
		var cgItems = Ext.get(this.oGridItemsID).select('div.cg-item',true);
		if(cgItems && cgItems.elements) {
			Ext.each(cgItems.elements, function(el){
				var xEl = Ext.get(el.id);
				//if(xEl) xEl.dom.innerHTML = '';
			});
		}
		
		// load content items
		if(d && d.data) {
			this.aniLoadGrid(d,o,0,cgItems);
		}
	}

	this.aniLoadGrid=function(d,o,idx,cgItems) {

		if(cgItems 
		&& cgItems.elements 
		&& cgItems.elements[idx]) {
			var xEl = Ext.get(cgItems.elements[idx].id);
			xEl.dom.innerHTML = '';
			if(xEl.hasClass('nav')) xEl.removeClass('nav');
			if(d.data && d.data[idx]) {
				if(d.data[idx]['img'] && d.data[idx]['img'].length>0) {
					var i = new Image();
					i.src = d.data[idx]['img'];
					i.onload = function() {			
						xEl.update(d.data[idx]['content_grid_item'],true); // use update to execute scripts
						var xInner = xEl.first();
						if(idx == (this.gridItemsLength-1)) {
							if(xEl.hasClass('nav')) xEl.removeClass('nav');
						}
						if(xInner) {
							//xInner.show(true);
							xInner.fadeIn({duration:0.25});
						}
						idx++;
						var fn = function(d,o,idx,cgItems) {
							AP.aniLoadGrid(d,o,idx,cgItems);
						};
						fn.defer(50,this,[d,o,idx,cgItems]);
					}
				} else {
					xEl.update(d.data[idx]['content_grid_item'],true); // use update to execute scripts
					var xInner = xEl.first();
					if(d.data[idx]['content_grid_item']
					&& d.data[idx]['content_grid_item'].length>0
					&& d.data[idx]['content_grid_item'].indexOf('AP.navigateGrid') != -1) {
						if(!xEl.hasClass('nav')) xEl.addClass('nav');
					} else if((!d.data[idx]['content_grid_item'])
					|| d.data[idx]['content_grid_item'].length == 0) {
						if(xEl.hasClass('nav')) xEl.removeClass('nav');
					}
					if(xInner) {
						//xInner.show(true);
						xInner.fadeIn({duration:0.25});
					}				
					idx++;
					var fn = function(d,o,idx,cgItems) {
						AP.aniLoadGrid(d,o,idx,cgItems);
					};
					fn.defer(50,this,[d,o,idx,cgItems]);
				}
			} else {
				//if(xEl.hasClass('nav')) xEl.removeClass('nav');
				idx++;
				var fn = function(d,o,idx,cgItems) {
					AP.aniLoadGrid(d,o,idx,cgItems);
				};
				fn.defer(50,this,[d,o,idx,cgItems]);			
			}
		} else {
			if(o.context != 'customer-projects') this.storeGridItems();
			this.gridEvents();
			this.hideEmptyRows();
		}
	}
	
	this.hideEmptyRows = function() {
		if(!Ext.get(this.oGridItemsID)) return;
		var cgItems = Ext.get(this.oGridItemsID).select('div.cg-item',true);
		this.rowIdx=0; this.emptyRowIdx=0;this.emptyRows=[];
		if(cgItems && cgItems.elements) {
			Ext.each(cgItems.elements, function(el){
				var xEl = Ext.get(el.id);
				if(xEl && xEl.dom.innerHTML.length==0) {
					this.emptyRowIdx++;
				}
				this.rowIdx++;
			},this);

			var m = Math.floor(this.emptyRowIdx / 3); // 3 row items per column
			var cg_items = Ext.get('cg_items');
			var h = cg_items.getHeight();
			var dh = (this.initialCGItemsHeight-(this.initialCGItemsHeight/3*m));

			cg_items.scale(
				undefined,
				dh,
				{
					easing: 'easeOut',
					duration: .35
				}
			);
			this.activeCGItemsHeight=dh;
		}
	}


	this.showGridHeader = function(sid,c,p) {
		var tpl = [
			'<div id="cg_items_header">',
				'<a href="#" class="closeCGItemsHeader" onclick="AP.hideGridHeader(true);return false;" id="closeCGItemsHeader" title="{backLink}">{backLink}</a>',
				'<h2>{title}</h2>',
				'<div class="fixfloat"></div>',
			'</div>'
		];	
		var Tpl = new Ext.Template(tpl);
		var cgItems = Ext.get('cg_items_wrapper');
		var innerHeader = Tpl.insertFirst(cgItems,p.header,true);
	
		innerHeader.slideIn('t', {
			easing: 'easeOut',
			duration: .5
		});		
	}
	
	this.hideGridHeader = function(restore) {
		var innerHeader = Ext.get('cg_items_header');
		if(innerHeader) {
			innerHeader.slideOut('t', {
				easing: 'easeIn',
				remove:true,
				duration: .5
			});
		}
		
		if(restore
		&& this.gridStoredItems
		&& Ext.get(this.oGridItemsID)) {
			//this.buildGrid(this.gridLastItems.responseData,this.gridLastItems.options);
			var cgItems = Ext.get(this.oGridItemsID).select('div.cg-item',true);
			this.restoreGridItems(0,cgItems);
			this.gridItems = Ext.apply({},this.gridLastItems);
		}
	}
	
	this.storeGridItems = function() {
		if(!Ext.get(this.oGridItemsID)) return;
		this.gridStoredItems=[]; this.gridStoredItemsIdx=0;
		var cgItems = Ext.get(this.oGridItemsID).select('div.cg-item',true);
		if(cgItems && cgItems.elements) {
			Ext.each(cgItems.elements, function(el){
				var xEl = Ext.get(el.id);
				var span = xEl.child('span.title');
				if(span && span.isVisible()) span.hide();
				this.gridStoredItems[this.gridStoredItemsIdx] = xEl.dom.innerHTML;
				this.gridStoredItemsIdx++;
			},this);
		}	
	}
	
	this.restoreGridItems = function(idx,cgItems) {
		if(cgItems && cgItems.elements && cgItems.elements[idx]) {
			var xEl = Ext.get(cgItems.elements[idx].id);
			xEl.dom.innerHTML = ''; 
			xEl.update(this.gridStoredItems[idx],true); // use update to execute scripts
			var xInner = xEl.first();
			if(this.gridStoredItems[idx]
			&& this.gridStoredItems[idx].length>0
			&& this.gridStoredItems[idx].indexOf('AP.navigateGrid') != -1) {
				if(!xEl.hasClass('nav')) xEl.addClass('nav');
			} else if((!this.gridStoredItems[idx])
			|| this.gridStoredItems[idx].length == 0) {
				if(xEl.hasClass('nav')) xEl.removeClass('nav');
			}
			if(xInner) {
				//xInner.show(true);
				xInner.fadeIn({duration:0.25});
			}				
			idx++;
			var fn = function(idx,cgItems) {
				AP.restoreGridItems(idx,cgItems);
			};
			fn.defer(50,this,[idx,cgItems]);
		} else {
			this.gridEvents();
			this.hideEmptyRows();
		}
	}
	
	//---------------------------------------------------------------------------------------
	// Content Overlay
	//---------------------------------------------------------------------------------------
	
	this.loadOverlay = function(sid,c,p) {
		var p = p || {};
		if(sid == this.actOGridSid) return;
		
		// mask? // coverbackground
		this.coverbackground(true,{preload:true,close:true,closeFN:function(){AP.closeOverlay();}});

		// params
		var method;
		var params = {noxml:1,rtn:'json'};
		switch(c) {
			case'article':
				params['dpa0'] = ','+sid;
				method='openArticles';			
				break;
			case'project':
				params['dpa0'] = ','+sid;
				method='openAMProjects';
				break;
			case'customer':
				params['dpa0'] = ','+sid;
				method='openAMCustomers';
				break;
		}
		
		Ext.Ajax.request({
			waitMsg: $L('loading'),
			waitMsgTarget: this.oGridItemsID,
			url: '/ajax/loadmethod/'+method,
			method: 'POST',
			context:c,
			scope:this,
			params: params,
			failure:function(response,options){
				this.coverbackground(false);
				Ext.MessageBox.alert('Warning','An error occured, please try again later.');
				
			},
			success:function(response,options){
				var responseData = Ext.util.JSON.decode(response.responseText);
				this.buildOverlay(responseData,options);
			}
		 });
		this.actOGridSid=sid;
	}
	
	this.buildOverlay = function(d,o) {

		o.oh = 820;
		o.ow = 960;
		o.ww = this.getWindowWidth();
		o.tp = 150;
		o.wh = window.innerHeight || document.body.offsetHeight || document.documentElement.offsetHeight;
		
		this.overlay = document.createElement('div');
		this.overlay.id = 'contentOverlay';
		this.overlay.style.position = (this.user.osIOS) ? 'absolute' : 'fixed';
		this.overlay.style.zIndex = 100001;
		this.overlay.style.width = o.ow+'px';
		//this.overlay.style.height = o.oh+'px';
		this.overlay.style.left = ((o.ww/2)-(o.ow/2))+'px';
		//this.overlay.style.backgroundColor = '#fff';
		this.overlay.style.visibility = 'hidden';
		this.overlay.className = o.context;
		if(d.data
		&& d.data.youtube_id
		&& d.data.youtube_id.length > 1) this.overlay.className += ' video';
		
		switch(o.context) {
			case'project':
				this.buildProjectOverlay(d,o);
				break;
			case'article':
				switch(d.data.template) {
					case'project':
						this.buildProjectOverlay(d,o);
						break;
					case'html':
					default:
						this.buildHTMLOverlay(d,o);
				}
				break;			
		}
	
	}
	// HTML Overlay
	//---------------------------------------------------------------------------------------
	this.buildHTMLOverlay = function(d,o) {
		
		var Tpl = new Ext.Template(this.getHTMLOverlayTemplate(d,o));
		var xTplContent = Tpl.append(this.overlay, d.data, true);
		document.getElementsByTagName('body')[0].appendChild(this.overlay);
		this.runScripts(xTplContent.child('.overlayContent').dom);
		
		// better top position
		var ch = (o.wh-this.overlay.offsetHeight)/2;
		if(ch < o.tp) o.tp = ch;
		if(ch<10) o.tp = 10;
		if(this.user.osIOS) {
			window.scrollTo(0, o.tp);
		}
		this.overlay.style.top = o.tp+'px';
		
		// set close button position (fixed)
		var topbarCloseOverlay = Ext.get('topbarCloseOverlay');
		if(topbarCloseOverlay) {
			topbarCloseOverlay.setStyle('top',o.tp+'px');
			topbarCloseOverlay.setStyle('left',(((o.ww/2)-(o.ow/2)) + (o.ow - (14+13)))+'px');
		}
		
		var innerHeader = Ext.get('innerHeader');
		if(innerHeader) innerHeader.setStyle('height','33px');

		this.overlay.style.visibility = 'visible';
	}
	
	this.getHTMLOverlayTemplate = function(d,o) {
		var o = d.data || {};
		
		return tpl = [
			//'<a href="#" class="closeOverlay" onclick="AP.closeOverlay();return false;" id="topbarCloseOverlay" title="'+$L('close')+'"></a>',
			'<div id="innerHeader">',
				'<div id="bottombar">',
					'<a href="#" class="closeOverlay" onclick="AP.closeOverlay();return false;" id="bottombarCloseOverlay" title="'+$L('close')+'"></a>',
				'</div>',
			'</div>',
			'<div id="innerOverlay">',
				'<h1 class="ref">{title}&nbsp;<span>{subheading}</span></h1>',
				'<div class="overlayContent">{article}</div>',
			'</div>'
		];			
	}
	
	// ProjectOverlay
	//---------------------------------------------------------------------------------------
	this.buildProjectOverlay = function(d,o) {

		var Tpl = new Ext.Template(this.getProjectOverlayTemplate(d,o));
		Tpl.append(this.overlay, d.data, true);
		document.getElementsByTagName('body')[0].appendChild(this.overlay);
		
		// better top position
		var ch = (o.wh-this.overlay.offsetHeight)/2;
		if(ch < o.tp) o.tp = ch;
		if(ch<10) o.tp = 10;
		if(this.user.osIOS) {
			window.scrollTo(0, o.tp);
		}
		this.overlay.style.top = o.tp+'px';
		
		// set close button position (fixed)
		var topbarCloseOverlay = Ext.get('topbarCloseOverlay');
		if(topbarCloseOverlay) {
			topbarCloseOverlay.setStyle('top',o.tp+'px');
			topbarCloseOverlay.setStyle('left',(((o.ww/2)-(o.ow/2)) + (o.ow - (14+13)))+'px');
		}
	
		this.overlay.style.visibility = 'visible';
		this.initOverlayEvents.defer(1,this,[]);
		this.hideOverlayHeader.defer(750,this,[]);
		this.hideOverlayFooter.defer(750,this,[]);
	}

	this.YoutubeCallBack = function(d) {
		// gets data via youtube api, not needed yet
		// call via: this.addScript('https://gdata.youtube.com/feeds/api/videos/'+d.data.youtube_id+'?v=2&alt=json-in-script&callback=AP.YoutubeCallBack');
	}
	
	this.toggleOverlayHeader=function(f) {
		if(AP.overlayHeaderStatus=='open') this.hideOverlayHeader(f);
		else this.showOverlayHeader(f);
	}
	
	this.overlayHeaderStatus='open';
	this.hideOverlayHeader = function(f) {
		if(!f) {
			if(AP.overlayHeaderStatus!='open') return;
			if((typeof this.tOverlayHeader != 'undefined') && (this.tOverlayHeader)) return;
		}
		var innerHeader = Ext.get('innerHeader');
		if(innerHeader) {
			var iow = innerHeader.getHeight();
			var topbarInfo = Ext.get('bottombarInfo');
			if(topbarInfo) topbarInfo.show(true);
			var bottombarCloseOverlay = Ext.get('bottombarCloseOverlay');
			if(bottombarCloseOverlay) bottombarCloseOverlay.show(true);					
			var contentOverlay = Ext.get('contentOverlay');
			var y = contentOverlay.getY();			
			innerHeader.shift({
				y: -(iow-33-y), // ext uses website position...
				easing: 'easeOut',
				duration: .35,
				callback:function() {
					AP.overlayHeaderStatus='closed';
					var innerHeader = Ext.get('innerHeader');
					if((innerHeader) && (!innerHeader.isVisible())) innerHeader.show();
				}
			});		
		}	
	}
	this.showOverlayHeader = function() {
		if(AP.overlayHeaderStatus!='closed') return;
		if((typeof this.tOverlayHeader != 'undefined') && (!this.tOverlayHeader)) return;
		var innerHeader = Ext.get('innerHeader');
		if(innerHeader) {
			var topbarInfo = Ext.get('bottombarInfo');
			if(topbarInfo) topbarInfo.hide(true);
			var bottombarCloseOverlay = Ext.get('bottombarCloseOverlay');
			if(bottombarCloseOverlay) bottombarCloseOverlay.hide(true);			
			var contentOverlay = Ext.get('contentOverlay');
			var y = contentOverlay.getY();						
			innerHeader.shift({
				y: y, // ext uses website position...
				easing: 'easeOut',
				duration: .35,
				callback:function() {
					AP.overlayHeaderStatus='open';
				}
			});		
		}	
	}
	
	this.overlayFooterStatus='open';
	this.hideOverlayFooter = function() {
		if(AP.overlayFooterStatus!='open') return;
		if((typeof this.tOverlayFooter != 'undefined') && (this.tOverlayFooter)) return;
		var preview = Ext.get('preview');
		if(preview) {
			var iow = preview.getHeight();
			var overlayFooter = Ext.get('overlayFooter');
			var y = overlayFooter.getY();
			// pos of footer...
			preview.shift({
				y: (y+iow+32), // ext uses website position...
				easing: 'easeOut',
				duration: .35,
				callback:function() {
					AP.overlayFooterStatus='closed';
					var preview = Ext.get('preview');
					if((preview) && (!preview.isVisible())) preview.show();
				}
			});		
		}	
	}
	this.showOverlayFooter = function() {
		if(AP.overlayFooterStatus!='closed') return;
		if((typeof this.tOverlayFooter != 'undefined') && (!this.tOverlayFooter)) return;
		var preview = Ext.get('preview');
		if(preview) {
			var overlayFooter = Ext.get('overlayFooter');
			var y = overlayFooter.getY();
			preview.shift({
				y: y, // ext uses website position...
				easing: 'easeOut',
				duration: .35,
				callback:function() {
					AP.overlayFooterStatus='open';			
				}
			});		
		}	
	}	
	
	this.initOverlayEvents=function() {

		var handleMove = function(e) {
			var t = e.getTarget();
			this.tOverlayHeader = e.getTarget('div#overlayHeader');
			this.tOverlayFooter = e.getTarget('div#overlayFooter');
			if(e) this.mouseCoords={x:e.getPageX(),y:e.getPageY()};
		};
		
		//Ext.EventManager.addListener(window, 'mousemove', handleMove,this,{});
		Ext.getBody().on('mousemove', handleMove, this);
		
		// hide innerHeader
		var innerHeader = Ext.get('overlayHeader');
		if(innerHeader) {
			innerHeader.on('mouseleave',function(e){
				var tgt = e.target || e.srcElement;
				AP.hideOverlayHeader.defer(1250,AP,[]);
			},innerHeader,{});			
		}
		
		var overlayHeader = Ext.get('overlayHeader');
		if(overlayHeader) {
			overlayHeader.on('mouseenter',function(ev){
				AP.showOverlayHeader.defer(100,AP,[]);
			},overlayHeader,{});			
		}

		var overlayFooter = Ext.get('overlayFooter');
		if(overlayFooter) {
			overlayFooter.on('mouseleave',function(ev){
				AP.hideOverlayFooter.defer(1000,AP,[]);
			},innerHeader,{});			
		}
		
		var overlayFooter = Ext.get('overlayFooter');
		if(overlayFooter) {
			overlayFooter.on('mouseenter',function(ev){
				AP.showOverlayFooter.defer(100,AP,[]);
			},overlayHeader,{});			
		}

		if(Ext.get('infoCarousel')) { // home carousel
			var conf = {itemSelector: 'li.c-content',width:700,height:438};
			if(typeof startSlide != 'undefined') conf.startSlide = parseInt(startSlide);
			this.crsl = new AP.Carousel('infoCarousel',conf);
		}
	}
	
	this.getProjectOverlayTemplate=function(d,o) {
		
		switch(o.context) {
			case'article':
				return tpl = [
					'<div id="innerOverlay">	',
						'<div id="overlayHeader">',
							'<div id="innerHeader">',
								'<div id="topbar">',
									'<a href="#" onclick="AP.hideOverlayHeader(true);return false;" id="topbarInfo" title="'+$L('info')+'"></a>',
									'<a href="#" class="closeOverlay" onclick="AP.closeOverlay();return false;" id="topbarCloseOverlay" title="'+$L('close')+'"></a>',
								'</div>			',
								'<div id="infos">',
									'{article}',
								'</div>',
								'<div id="bottombar">',
									'<a href="#" onclick="AP.showOverlayHeader(true);return false;" id="bottombarInfo" title="'+$L('info')+'"></a>',
									'<a href="#" onclick="AP.toggleOverlayHeader(true);return false;" id="bottombarHandle" title="'+$L('handle')+'"></a>',
								'</div>',
							'</div>',
						'</div>',
						'<div class="carouselContainer" id="infoCarousel">',
							'<h1 class="ref">{title}&nbsp;<span>{subheading}</span></h1>',
							'<a href="#" id="c_next" class="c_next"></a>',	
							'<a href="#" id="c_back" class="c_back"></a>',
							'<div class="c-contentContainer">',
								'<ul class="c-slidesWrap">',
									'{mainimages}',
								'</ul>',
							'</div>',
							'<div class="fixfloat"></div>',
							'<div id="overlayFooter">',
								'<div id="preview" class="previews"><div class="innerPreviews">{previews}</div></div>',
								'<div class="bottomNav" id="bottomNav"></div>',
							'</div>',
						'</div>',
					'</div>'
				];
				break;
			default:		
			
				if(d.data
				&& d.data.youtube_id
				&& d.data.youtube_id.length > 1) { // video template
					var ovstyle = ''; var ifstyle='';
					if(d.data.mainimage && d.data.mainimage.length>0) {
						ovstyle += 'background-image:url('+d.data.mainimage+');';
						var mt = (500-parseInt(d.data.youtube_height))/2;
						if(mt < 0) mt = 0;
						ifstyle += 'margin-top:'+mt+'px;margin-bottom:'+mt+'px';
					}
					
					if(ifstyle.length>0) ifstyle = ' style="'+ifstyle+'"';
					if(ovstyle.length>0) ovstyle = ' style="'+ovstyle+'"';
					
					return tpl = [
						//'<button id="closeOverlay" onclick="AP.closeOverlay();"></button>',
						'<div id="innerOverlay" class="video">	',
							'<div id="overlayHeader">',
								'<div id="innerHeader">',
									'<div id="topbar">',
										'<a href="#" onclick="AP.hideOverlayHeader(true);return false;" id="topbarInfo" title="'+$L('info')+'"></a>',
										'<a href="#" class="closeOverlay" onclick="AP.closeOverlay();return false;" id="topbarCloseOverlay" title="'+$L('close')+'"></a>',
									'</div>			',
									'<div id="infos">',
										'<div class="beschreibung">',
											'<h1>'+$L('description')+'</h1>',
											'{description}',
											'{url}',
										'</div>',
										
										'<div class="leistung">',
											'<h1>'+$L('AM_Agenturleistung')+'</h1>',
											'<ul>{project_categories}</ul>',
										'</div>',
									  
										'<div class="branche">',
											'<h1>'+$L('AM-CustomerCatgeory')+'</h1>',
											'<ul>{customer_categories}</ul>',
										'</div>',
										'<div class="fixfloat"></div>',
									'</div>',
									'<div id="bottombar">',
										'<a href="#" onclick="AP.showOverlayHeader(true);return false;" id="bottombarInfo" title="'+$L('info')+'"></a>',
										'<a href="#" onclick="AP.toggleOverlayHeader(true);return false;" id="bottombarHandle" title="'+$L('handle')+'"></a>',
									'</div>',
								'</div>',
							'</div>',
							'<h1 class="ref">{title}&nbsp;<span>{subheading}</span></h1>',
							'<div class="overlayContent video"'+ovstyle+'>',
								'<iframe'+ifstyle+' longdesc="{youtube_url}" class="video" width="{youtube_width}" height="{youtube_height}" src="{youtube_src}" frameborder="0" allowfullscreen></iframe>',
							'</div>',
						'</div>	'
					];						
				
				
				} else {
					return tpl = [
						//'<button id="closeOverlay" onclick="AP.closeOverlay();"></button>',
						'<div id="innerOverlay">	',
							'<div id="overlayHeader">',
								'<div id="innerHeader">',
									'<div id="topbar">',
										'<a href="#" onclick="AP.hideOverlayHeader(true);return false;" id="topbarInfo" title="'+$L('info')+'"></a>',
										'<a href="#" class="closeOverlay" onclick="AP.closeOverlay();return false;" id="topbarCloseOverlay" title="'+$L('close')+'"></a>',
									'</div>			',
									'<div id="infos">',
										'<div class="beschreibung">',
											'<h1>'+$L('description')+'</h1>',
											'{description}',
											'{url}',
										'</div>',
										
										'<div class="leistung">',
											'<h1>'+$L('AM_Agenturleistung')+'</h1>',
											'<ul>{project_categories}</ul>',
										'</div>',
									  
										'<div class="branche">',
											'<h1>'+$L('AM-CustomerCatgeory')+'</h1>',
											'<ul>{customer_categories}</ul>',
										'</div>',
										'<div class="fixfloat"></div>',
									'</div>',
									'<div id="bottombar">',
										'<a href="#" onclick="AP.showOverlayHeader(true);return false;" id="bottombarInfo" title="'+$L('info')+'"></a>',
										'<a href="#" onclick="AP.toggleOverlayHeader(true);return false;" id="bottombarHandle" title="'+$L('handle')+'"></a>',
									'</div>',
								'</div>',
							'</div>',
							'<div class="carouselContainer" id="infoCarousel">',
								'<h1 class="ref">{customer_title}&nbsp;<span>{title}</span></h1>',
								'<a href="#" id="c_next" class="c_next"></a>',	
								'<a href="#" id="c_back" class="c_back"></a>',
								'<div class="c-contentContainer">',
									'<ul class="c-slidesWrap">',
										'{mainimages}',
									'</ul>',
								'</div>',
								'<div class="fixfloat"></div>',
								'<div id="overlayFooter">',
									'<div id="preview" class="previews"><div class="innerPreviews">{previews}</div></div>',
									'<div class="bottomNav" id="bottomNav"></div>',
								'</div>',
							'</div>',
						'</div>	'
					];	
				}
		}
	}
	
	this.closeOverlay=function() {
		var overlay = Ext.get(this.overlay.id);
		if(overlay) overlay.remove();
		this.overlay=false;
		this.coverbackground(false);
		this.actOGridSid=false;
		this.overlayHeaderStatus='open';
		this.overlayFooterStatus='open';
	}
	
	//---------------------------------------------------------------------------------------

	this.coverbackground = function(vs,p) {
		
		if(typeof p != 'object') p = {};
		if(!p.bg_color) p.bg_color = "#000000";
		if(!p.op) p.op = 0.8;
		
		if(!this.cover) {
			this.cover = document.createElement('div');
			this.cover.style.position = 'fixed';
			this.cover.style.zIndex = 99999;
			this.cover.style.left = 0+'px';
			this.cover.style.top = 0+'px';
			this.cover.style.right = 0+'px';
			//this.cover.style.bottom = 0+'px';
			this.cover.style.opacity = p.op; 
			this.cover.style.filter = "alpha(opacity:"+Math.round(p.op*100)+")";
			this.cover.style.backgroundColor = p.bg_color;
			document.getElementsByTagName('body')[0].appendChild(this.cover);
		}
		
		if(p.preload) {
			var preoloadUrl = '/mcms/april5/_img/interface/ajax-loader-b.gif';
			this.preload = document.createElement('div');
			this.preload.className='preload';
			this.preload.style.zIndex = 100000;
			this.preload.style.position = (this.user.osIOS) ? 'absolute' : 'fixed';
			this.preload.style.top = '150px';
			this.preload.style.backgroundImage = 'url("'+preoloadUrl+'")';
			document.getElementsByTagName('body')[0].appendChild(this.preload);
		} else if(this.preload) this.preload.style.display='none';
		
		if(!vs) {
			this.cover.style.visibility = 'hidden';
		} else {
			var wh = this.getWindowHeight();
			bodyheight = document.body.offsetHeight;
			if(wh > bodyheight) bodyheight = wh;
			this.cover.style.width = '100%';
			this.cover.style.height = (bodyheight)+'px';
			//this.cover.style.height = '100%';			
			this.cover.style.visibility =  'visible';			
		}
		
		if(p.close) {
			this.coverX = Ext.get(this.cover);
			this.coverX.on('click',p.closeFN,this);
		}
	}		

	//---------------------------------------------------------------------------------------
	this.getWindowWidth = function() {
		var w = 0;
		if(window.innerWidth) {
			w=window.innerWidth;
		} else if(document.documentElement && document.documentElement.clientWidth) {
			w=document.documentElement.clientWidth;
		} else if(document.body) {
			w=document.body.clientWidth;
		}
		return w;
	}

	this.getWindowHeight = function() {
		var h = 0;
		if(window.innerHeight) {
			h=window.innerHeight;
		} else if(document.documentElement && document.documentElement.clientHeight) {
			h=document.documentElement.clientHeight;
		} else if(document.body) {
			h=document.body.clientHeight;
		}
		return h;
	};
	
	this._bind = function(obj, cback, fun, capture) {
		if (obj.addEventListener) {
			obj.addEventListener(cback, fun, !!capture);
		}
		else if (obj.attachEvent) {
			obj.attachEvent("on"+cback, fun);
		}	
	}

	this.addScript=function(scriptURL) {
		var scriptTag = document.createElement("script");
		scriptTag.type = "text/javascript";
		scriptTag.src = scriptURL;
		this.getScriptArea().appendChild(scriptTag);
		return scriptTag;
	}
	
	this.getScriptArea=function() {
		var parentElement = document.getElementsByTagName("head");
		if (!parentElement || parentElement.length < 1) {
			parentElement = document.body;
		}
		else {
			parentElement = parentElement[0];
		}
		return parentElement;
	}

	this.runScripts = function(e) {
		if (e.nodeType != 1) return; //if it's not an element node, return

		if (e.tagName.toLowerCase() == 'script') {
			if(e && e.src && e.src.length >0) {
				this.addScript(e.src);
			} else {
				if (window.execScript) {
					window.execScript(e.text);
				} else eval(e.text); //run the script
			}
		}
		else {
			var n = e.firstChild;
			while (n) {
				if (n.nodeType == 1) {
					fn = function(n) {this.runScripts( n )}; 
					defer(fn,5,this,[n]);
				}
				n = n.nextSibling;
			}
		}
	}	
}

var AP = new april5();
AP._bind(window, 'load', function() { AP.init(); }, false);
AP._bind(window,'DOMContentLoaded',function() {AP.init();},false);

//---------------------------------------------------------------------------------------

AP.user = new function() {
	// OSes
	this.osAndroid = false;
	this.osIOS = false;
	this.osPC = false;
	
	// devices
	this.devIPhone = false;
	this.devIPad = false;
	this.devIPod = false;
	
	// browsers
	this.brwWebkit = false;
	
	this._init = function() {
		
		nav = navigator;
		ua = nav.userAgent.toLowerCase();
		check = function(r){
			return r.test(ua);
		};
		checkPlatform = function(r){
			return r.test(nav.platform);
		};
		
		this.devIsDevice = check(/iphone|ipod|ipad|android/gi);
		this.devIsIPad = check(/ipad/gi);
		this.devIsRetina = 'devicePixelRatio' in window && window.devicePixelRatio > 1;
		this.brwIsSafari = nav.appVersion.match(/Safari/gi),
		this.hasHomescreen = 'standalone' in nav && this.devIsDevice;
		this.isStandalone = this.hasHomescreen && nav.standalone;
		this.OSVersion = nav.appVersion.match(/OS \d+_\d+/g),
		this.OSVersion = this.OSVersion ? this.OSVersion[0].replace(/[^\d_]/g,'').replace('_','.')*1 : 0;
		this.platform = nav.platform.split(' ')[0],
		(nav.language) ? this.language = nav.language.replace('-', '_') : this.language = 'en',
		
		this.devIPhone = check(/iphone/);
		this.devIPad = check(/ipad/);
		this.devIPod = check(/ipod/);
		if (this.devIPad || this.devIPhone || this.devIPod)
			this.osIOS = true;
		else if(check(/android/)) {
			this.osAndroid = true;
			if(check(/2.1/) || check(/2.2/)) this.AndroidVideo=true;
		} else this.osPC = true;
		this.brwWebkit = check(/webkit/);
		this.devOpera = check(/opera/);
		this.devGecko = check(/gecko/);	
		this.brwSafari = check(/safari/);
		this.brwChrome = check(/chrome/);
		this.ff4 = check(/firefox\/4./);
	};	
};

//---------------------------------------------------------------------------------------
AP.Carousel = Ext.extend(Ext.util.Observable, {
	interval: 5,
	transitionDuration: 0.35,
	transitionType: 'carousel',
	transitionEasing: 'easeOut',// 'elasticOut',//'easeOut',// 'elasticOut',//'easeOut',
	itemSelector: 'img',
	activeSlide: 0,
	startSlide: 0,
	autoPlay: true,
	auotPlayStart: (1000*60),//(1000*60*90),
	showPlayButton: false,
	pauseOnNavigate: true,
	wrap: false,
	freezeOnHover: true,
	navigationOnHover: false,
	hideNavigation: false,
	width: null,
	height: null,

	constructor: function(elId, config) {
		config = config || {};
		Ext.apply(this, config);
		
		AP.Carousel.superclass.constructor.call(this, config);
		
		this.addEvents(
			'beforeprev',
			'prev',
			'beforenext',
			'next',
			'change',
			'play',
			'pause',
			'freeze',
			'unfreeze'
		);
		
		this.el = Ext.get(elId);
		this.slides = this.els = [];
		this.btnavImgs = [];
		
		if(this.autoPlay || this.showPlayButton) {
			this.wrap = true;
		};
		
		if(this.autoPlay && typeof config.showPlayButton === 'undefined') {
			this.showPlayButton = true;
		}
		
		this.initMarkup();
		this.initEvents();
		
		if(this.carouselSize > 0) {
			this.refresh();
		}
		
		if(this.startSlide > 0 && this.activeSlide != this.startSlide) {
			if(typeof this.startfn == 'function') this.startSlideFN = this.startfn;
			this.setSlide.defer(1000,this,[this.startSlide]);	
		}
		//this.els.navBottom.setStyle('visibility','visible');
		this.els.navBottom.setStyle.defer(500,this.els.navBottom,['visibility','visible']);
	},

	initMarkup: function() {

		this.carouselSize = 0;
		// slides
		var items = this.el.select(this.itemSelector);

		// navigation elements
		this.els.navBottom = Ext.get(this.el.select('div.bottomNav',true).elements[0]);
		// slide container
		this.els.container =  Ext.get(this.el.select('div.c-contentContainer',true).elements[0]);
		this.els.slidesWrap =  Ext.get(this.el.select('ul.c-slidesWrap',true).elements[0]);
		this.els.navNext = Ext.get(this.el.select('a.c_next',true).elements[0]);
		this.els.navPrev = Ext.get(this.el.select('a.c_back',true).elements[0]);
		
		// set the dimensions of the container
		this.containerWidth = this.width || this.el.getWidth(true);
		this.containerHeight = this.height || this.el.getHeight(true);

		// set dimensions of the slide
		this.slideWidth = this.containerWidth;//-this.els.navPrev.getWidth() - this.els.navNext.getWidth();
		this.slideHeight = this.containerHeight-this.els.navBottom.getHeight();

		this.els.container.setStyle({
			width: this.slideWidth + 'px',
			height: this.slideHeight + 'px'
		});
		this.sidx=0;
		Ext.each(items.elements,function(item){
			xitem = Ext.get(item);
			
			// set slides with and height and fill slides array
			this.slides.push(xitem);
			xitem.setWidth(this.slideWidth + 'px').setHeight(this.slideHeight + 'px');
			// create bottom nav
			var btnavImg = Ext.DomHelper.append(this.els.navBottom,{
				tag:'span',
				cls:'c-bottomNavWR',
				children:[{
					tag:'img',
					cls:'c-bottomNav-img',
					src:(this.sidx === 0) ? '/mcms/april5/_img/interface/overlay/dot_on.png' : '/mcms/april5/_img/interface/overlay/dot_off.png'							
				},
				{
					tag:'span',
					cls:'c-bottomNav-txt',
					html:''//f.bottomNavTitle
				}]
			},true);
			this.btnavImgs.push(btnavImg);
			this.sidx++;
		},this);
		
		
		this.carouselSize = this.slides.length;
	},

	initEvents: function() {
		
		for(bidx=0;bidx<this.btnavImgs.length;bidx++) {
			this.btnavImgs[bidx].addListener('click',function(ev,el,o){
				ev.preventDefault();
				var target = ev.getTarget();
				target.blur();
				if(this.pauseOnNavigate) {
					this.pause();
				}				
				this.setSlide(o.bidx);				
			},this,{preventDefault:true,bidx:bidx});
		}
		
		var previewItems = this.el.select('a.preview');
		if(previewItems && previewItems.elements && previewItems.elements.length>0) {
			var pvIs = previewItems.elements;
			for(pidx=0;pidx<pvIs.length;pidx++) {
				var xPvI = Ext.get(pvIs[pidx]);
				xPvI.addListener('click',function(ev,el,o){
					ev.preventDefault();
					var target = ev.getTarget();
					target.blur();
					if(this.pauseOnNavigate) {
						this.pause();
					}										
					this.setSlide(o.pidx);				
				},this,{preventDefault:true,pidx:pidx});
			}		
		}
		
		this.els.container.on('click', function(ev) {
            ev.preventDefault();
            var target = ev.getTarget();
            target.blur();
            if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
            this.next();
        }, this);

		
        this.els.navPrev.on('click', function(ev) {
            ev.preventDefault();
            var target = ev.getTarget();
            target.blur();            
            if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
            this.prev();
        }, this);

        this.els.navNext.on('click', function(ev) {
            ev.preventDefault();
            var target = ev.getTarget();
            target.blur();
            if(Ext.fly(target).hasClass('ux-carousel-nav-disabled')) return;
            this.next();
        }, this);

		if(this.freezeOnHover) {
			if(AP.overlay) {
				var apo = Ext.get(AP.overlay);
				apo.on('mouseenter', function(){
					if(this.playing) {
						this.fireEvent('freeze', this.slides[this.activeSlide]);
						Ext.TaskMgr.stop(this.playTask);
					}
				}, this);
				apo.on('mouseleave', function(){
					if(this.stopPlaying) return true;
					if(this.playing) {
						this.fireEvent('unfreeze', this.slides[this.activeSlide]);
						Ext.TaskMgr.start(this.playTask);
					}
				}, this, {buffer: (this.interval/2)*1000});

			} else {
				this.els.container.on('mouseenter', function(){
					if(this.playing) {
						this.fireEvent('freeze', this.slides[this.activeSlide]);
						Ext.TaskMgr.stop(this.playTask);
					}
				}, this);
				this.els.container.on('mouseleave', function(){
					if(this.stopPlaying) return true;
					if(this.playing) {
						this.fireEvent('unfreeze', this.slides[this.activeSlide]);
						Ext.TaskMgr.start(this.playTask);
					}
				}, this, {buffer: (this.interval/2)*1000});
			}
		};			
		if(this.interval && this.autoPlay) {
			this.playTimeout = this.play.defer(this.auotPlayStart,this);
		};			
	},
			
	prev: function() {
		if (this.fireEvent('beforeprev') === false) {
			return;
		}
		if(this.pauseOnNavigate) {
			this.pause();
		}
		this.setSlide(this.activeSlide - 1);

		this.fireEvent('prev', this.activeSlide);        
		return this; 	
	},
	
	next: function() {
		if(this.fireEvent('beforenext') === false) {
			return;
		}
		if(this.pauseOnNavigate) {
			this.pause();
		}
		this.setSlide(this.activeSlide + 1);

		this.fireEvent('next', this.activeSlide);        
		return this;  		  
	},

	pause: function() {
		if(this.playing) {
			Ext.TaskMgr.stop(this.playTask);
			this.playTaskBuffer.cancel();
			this.playing = false;
			if(this.showPlayButton) {
				if(this.els.navPlay) this.els.navPlay.removeClass('ux-carousel-playing');
			}
			this.fireEvent('pause');
		}   
		
		// restart timer
		if(this.playTimeout) window.clearTimeout(this.playTimeout);
		if(this.interval && this.autoPlay) {
			this.playTimeout = this.play.defer(this.auotPlayStart,this);
		};			
		
		return this;	
	},

	play: function() {
		if(!this.playing) {
			this.playTask = this.playTask || {
				run: function() {
					this.playing = true;
					this.setSlide(this.activeSlide+1);
				},
				interval: this.interval*1000,
				scope: this
			};
			
			this.playTaskBuffer = this.playTaskBuffer || new Ext.util.DelayedTask(function() {
				Ext.TaskMgr.start(this.playTask);
			}, this);

			this.playTaskBuffer.delay(this.interval*1000);
			this.playing = true;
			if(this.showPlayButton) {
				if(this.els.navPlay) this.els.navPlay.addClass('ux-carousel-playing');
			}
			this.fireEvent('play');
		}        
		return this;
	},			

	clear: function() {},
	add: function(el, refresh) {},
	
	refresh: function() {
		this.carouselSize = this.slides.length;
		this.els.slidesWrap.setWidth((this.slideWidth * this.carouselSize) + 'px');
		if(this.carouselSize > 0) {
			this.activeSlide = 0;
			this.setSlide(0, true);
		}                
		return this;  		   
	},
	
	setSlide: function(index, initial) {
	
		if(!this.wrap && !this.slides[index]) {
			return;
		}
		else if(this.wrap) {
			if(index < 0) {
				index = this.carouselSize-1;
			}
			else if(index > this.carouselSize-1) {
				index = 0;
			}
		}
		if(!this.slides[index]) {
			return;
		}

		if(this.els.caption) this.els.caption.update(this.slides[index].child(':first-child', true).title || '');
		if(typeof TV == 'object') {
			if(typeof this.startSlideFN != 'function') {
				TV.stopVideos();
			}
		}			
		
		var offset = index * this.slideWidth;
		if (!initial) {
			switch (this.transitionType) {
				case 'fade':
					this.slides[index].setOpacity(0);
					this.slides[this.activeSlide].stopFx(false).fadeOut({
						duration: this.transitionDuration / 2,
						callback: function(){
							this.els.slidesWrap.setStyle('left', (-1 * offset) + 'px');
							this.slides[this.activeSlide].setOpacity(1);
							this.slides[index].fadeIn({
								duration: this.transitionDuration / 2
							});
						},
						scope: this
					})
					break;

				default:
					var xNew = (-1 * offset) + this.els.container.getX();
					this.els.slidesWrap.stopFx(false);
					this.els.slidesWrap.shift({
						duration: this.transitionDuration,
						x: xNew,
						scope:this,
						callback:function() {
							if(typeof this.startSlideFN == 'function') {
								this.startSlideFN.defer(500,this,[this]);
								this.startSlideFN = false;
							}
						},
						easing: this.transitionEasing
					});
					break;
			}
		}
		else {
			this.els.slidesWrap.setStyle('left', '0');
		}
		
		this.updateBottomNav(index,this.activeSlide);
		this.activeSlide = index;
		this.updateNav();
		this.fireEvent('change', this.slides[index], index);
	},

	updateNav: function() {
		return;
		this.els.navPrev.removeClass('carousel-nav-disabled');
		this.els.navNext.removeClass('carousel-nav-disabled');
		if(this.activeSlide === 0) {
			this.els.navPrev.addClass('carousel-nav-disabled');
		}
		if(this.activeSlide === this.carouselSize-1) {
			this.els.navNext.addClass('carousel-nav-disabled');
		}
	},
	
	updateBottomNav: function(i,o) {
		if(this.btnavImgs) {
			if(this.btnavImgs[i]) {
				var img = this.btnavImgs[i].select('.c-bottomNav-img',true);
				img.elements[0].src = '/mcms/april5/_img/interface/overlay/dot_on.png';
				var txt = this.btnavImgs[i].select('.c-bottomNav-txt',true);
				Ext.get(txt.elements[0]).addClass('active');
			}
			if(this.btnavImgs[o] && o != i) {
				var img = this.btnavImgs[o].select('.c-bottomNav-img',true);
				img.elements[0].src = '/mcms/april5/_img/interface/overlay/dot_off.png';
				var txt = this.btnavImgs[o].select('.c-bottomNav-txt',true);
				Ext.get(txt.elements[0]).removeClass('active');
			}
		}		
	}
	
});


//---------------------------------------------------------------------------------------
//-- TinyMCE Settings -------------------------------------------------------------------
//---------------------------------------------------------------------------------------

if(typeof IF != 'object') {
	function Interface() {
		this.init=function() {}
	}
	var IF = new Interface();
}

IF.tinymceSettings = {
	theme : "advanced",
	height: "400", //config.height,
	plugins: "safari,pagebreak,style,advhr,advimage,advlink,table,emotions,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking",
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code",
	theme_advanced_buttons3 : "hr,removeformat,|,sub,sup,|,charmap,nonbreaking,media,advhr,|,ltr,rtl,|,insertdate,inserttime,preview,|,forecolor",
	theme_advanced_buttons4 : "tablecontrols,|,visualaid,|,iespell,fullscreen,attribs,styleprops", // tables needed @ accognis.de
	//theme_advanced_buttons4 : "styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking",
	
	
	//theme_advanced_buttons4 : "styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : false,
	extended_valid_elements : "a[name|href|target|title|onclick|class],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	//theme_advanced_blockformats : "p,h1,h2,h3,h4,h5,h6,blockquote,div,address",
	cleanup_on_startup:false,
	//cleanup:false,
	verify_html:false,
	//template_external_list_url : "example_template_list.js"
	//file_browser_callback : "FileBrowser"
	file_browser_callback:"ezfilemanager",
	relative_urls:false,
	theme_advanced_enable:"styleselect",
	content_css: "/mcms/april5/_css/wysiwyg.css",
	body_id:'content',
	body_class:'p-normargin',	 
	language:"de"
	//onchange_callback:"myCustomOnChangeHandler"
	//add_form_submit_trigger:true
	//body_id:"content"
};


function defer(fn, millis, obj, args, appendArgs) {
	fn = createDelegate(fn, obj, args, appendArgs);
	if (millis > 0) {
		return setTimeout(fn, millis);
	}
	fn();
	return 0;
}

 /* @param {Function} fn The function to delegate.
 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
 * <b>If omitted, defaults to the browser window.</b>
 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
 * if a number the args are inserted at the specified position
 * @return {Function} The new function
 */
function createDelegate(fn, obj, args, appendArgs) {
	if (!typeof fn == 'function') {
		return fn;
	}
	return function() {
		var callArgs = args || arguments;
		if (appendArgs === true) {
			callArgs = Array.prototype.slice.call(arguments, 0);
			callArgs = callArgs.concat(args);
		}
		else if (typeof appendArgs == 'number') {
			callArgs = Array.prototype.slice.call(arguments, 0);
			// copy arguments first
			var applyArgs = [appendArgs, 0].concat(args);
			// create method call params
			Array.prototype.splice.apply(callArgs, applyArgs);
			// splice them in
		}
		if(typeof fn == 'function') return fn.apply(obj || window, callArgs);
		else return fn;
	};
}
