// Add site spesific javascript here
function addNewsletterTopic() {
	
	displayLayer('newsletter-subscription-categories-id');
     
       
};


function toggleArchive() {
	$('archive-overview').toggle();
}
function toggleSearch() {
	$('archive-search').toggle();
}
function addInvoiceFields() {
	$('invoiceorganisation').value = $('organisation').value;
	$('invoicename').value = $('name').value;
	$('invoiceaddress').value = $('address').value;
	$('invoicecity').value = $('city').value;
	$('invoicezip').value = $('zip').value;
}

function isMouseLeaveOrEnter(e, handler) {
if (e.type != 'mouseout' && e.type != 'mouseover') return false;
var reltg = e.relatedTarget ? e.relatedTarget :
e.type == 'mouseout' ? e.toElement : e.fromElement;
while (reltg && reltg != handler) reltg = reltg.parentNode;
return (reltg != handler);
}

function showLayer(Id) {
		hideCalendarLayers();
		displayLayer(Id);
}
	
	

	

function hideCalendarLayers() {
	$$('div.small-calendar-popup').each(function(element) {
		element.hide();
	});
}



	// Check for mouseout-event on tile, hide all layers
	document.observe('dom:loaded', function(event) {
$$('div.small-calendar').each(function(element) {
		element.observe('mouseout', function(event) {
		event.stop();
		if(isMouseLeaveOrEnter(event, element)) {
		hideCalendarLayers();
		}
		});
		});
		});
		


document.observe('dom:loaded', function(event) {
	$$("div.bannerdisplay").each(function(element) {
		var videos = element.select("div.myvideoclass");
		var videocount = videos.size();
		if (videocount > 1) {
			var random = Math.round(Math.random(0, videocount-1));
			videos[random].show();
		} else if (videocount == 1) { 
			videos.first().show();
		} else {
		}
	});
	}
	
 );

