// quadracom standard functions
// Requires mootools 1.2.1 framework
// Use t3mootools-extensions for TYPO3!

// Init-Script for actions to be taken after dom-ready event uis triggered
function dom_ready() {
	add_ext_links_target();
	init_expandables();
}

/*
Adds target-attrib with value 'blank' to a-tags with classes *-new-window
*/
function add_ext_links_target() {
	$each($$('a.external-link-new-window', 'a.internal-link-new-window'), function(link_item) {
		link_item.set('target', 'blank');
	});
}

/*
Control expandable boxes
*/
function init_expandables() {
	var expandables = $$('div.expandable-box');
	expandables.each( 
		function(el) {
			
			// get heading
			var heading = el.getElements('h1')[0];
			if (heading == undefined) {
				return;
			}

			// get expandable element
			var expandable = el.getElement('div.csc-textpic');
			if (expandable == undefined) {
				expandable = el.getElement('div.csc-text-body');
			}
			if (expandable == undefined) {
				return;
			}

			var el_height = parseInt(expandable.getStyle('height'));

			expandable.setStyle('height', '0px');
			expandable.setStyle('overflow', 'hidden');
			expandable.setStyle('padding-bottom','0px');
			
			heading.setStyle('cursor', 'pointer');

			heading.set('text', heading.get('text') + '\u00a0>');
			
			// Make ce's heading click sensitive
			heading.addEvent('click', function(el) {
				toggle_expandable(expandable, el_height);
			});
			
			heading.set('title', 'Informationen anzeigen');
			if (document.location.href.match(/\/en\//)) heading.title =  'Show information';
		}
	);
	
	var tips = new Tips('.expandable-box h1');
}

function toggle_expandable(expandable, el_height) {
	var padding_bottom = 15;
	if (parseInt(expandable.getStyle('height')) > 0) {
		el_height =  0;
		padding_bottom = 0;
	}
	var tween = new Fx.Morph(expandable, {
		transition: Fx.Transitions.Cubic.easeInOut, 
		duration:1000
	});
	tween.start({
			'height': el_height
			,'padding-bottom': padding_bottom
	});
}


window.addEvent("domready", dom_ready);


