window.addEvent('domready', function() {
	
	var hovers = $$('.mainnavigation li');
	hovers.combine($$('div.toolingwidget'));
	hovers.combine($$('ul.menu_left li'));
	
	hovers.each(function(el) {
		el.addEvent('mouseenter', function(e) {
			el.addClass('hover');
		});
		el.addEvent('mouseleave', function(e) {
			el.removeClass('hover');
		});
		
	});
	if ($chk(lightBox)){
		var lightBox = new LightBox();
	}
});
var carousseloptions = {
	prefillData: 
		{
			readmore: 'Lees meer ',
			uri:'#'
		}, 
	slideTime: 3000,
	containers: {
		currentContainer : {
			options: {
				dataComplete: function(){
						var anchors = $$('#'+this.container.id + ' ul.buttons li');
						var anchor = new Element(anchors[0]);
						var links = anchor.getChildren('a');
						if (!$chk(links[0].getProperty('href'))){
							anchor.hide();
						} else {
							anchor.show();
						}
						
					}
				}
			},
			switchContainer : {
				options: {
					dataComplete: function(){
						var anchors = $$('#'+this.container.id + ' ul.buttons li');
						var anchor = new Element(anchors[0]);
						var links = anchor.getChildren('a');
						if (!$chk(links[0].getProperty('href'))){
							anchor.hide();
						} else {
							anchor.show();
						}
					
					}
				}
			}
		}
	};

/**
 * Linklist functions
 */
var blocksOptions = {
	'addBtnId': 'link-add',
	'deleteBtnId': 'link-remove-',
	
	'nodeType' : 'RELATED_ITEM_LINK',
	'nodeTypeTpl' : 'includes/blocks/relateditem.tpl',
	'jsonItemKey' : 'linkid',
	
	'elPrefixId': 'link-'
};

var fileBlocksOptions = {
	'addBtnId': 'file-add',
	'deleteBtnId': 'file-remove-',
	'nodeType' : 'RELATED_FILE_LINK',
	'nodeTypeTpl' : 'includes/blocks/relatedfile.tpl',
	'jsonItemKey' : 'linkid',
	
	'elPrefixId': 'file-'
}
var blockLinkAdmins = new Hash();

createBlockLinkAdmin = function(nodeId, type) {
	options = blocksOptions;

	if (type == 'file'){
		options = fileBlocksOptions;
	}
	linkAdmin = new EOS.ListAdmin($(type + '-collection_' + nodeId), 'direct', options);
	blockLinkAdmins.set(type, linkAdmin);

	return linkAdmin;
};

handleAddLink = function(nodeId, type) {
	if (!$chk(type)) {
		var type = 'link';
	}
	linkAdmin = blockLinkAdmins.get(type);

	if (linkAdmin === null) {
		linkAdmin = createBlockLinkAdmin(nodeId, type);
	}
	
	linkAdmin.addElement(nodeId);
	return false;
};

handleRemoveLink = function(nodeId, type) {
	if (!$chk(type)) {
		var type = 'link';
	}
	linkAdmin = blockLinkAdmins.get(type);

	if (linkAdmin === null) {
		linkAdmin = createBlockLinkAdmin(nodeId, type);
	}
	
	linkAdmin.deleteElement(nodeId);
	return false;
};