$(function(){

	// add hover class on bluebox
	$('.bluebox').hover( 
	function() {
		$(this).addClass('hover');
	}, function() {
		  $(this).removeClass('hover');
	});

	// fontsize links
	$('#extras li.SmallerFont a').click(function()
	{
		$.fontSize({ change:-2 });
		return false;
	});
	$('#extras li.BiggerFont a').click(function()
	{
		$.fontSize({ change:2 });
		return false;
	});

	// sliderbox on frontpage
	
	$('.accordion').accordion({ header:'h3', change:function(){ } }).accordion( 'activate', 0 );

	// text in searchbox
	$('#SearchString').originalValue();
	$('#year').originalValue();



	// background changes when hover on a in lists - boxes
	$('.subpage #content ul li a').hover(
		function(){
			$(this).parents('li').css( { background:'url(/library/9224) no-repeat left 10px'  } );
		},
		function(){
			$(this).parents('li').css( { background:'url(/library/9242) no-repeat left 10px' } );
		}
	)

	// background changes when hover on a in lists - arrows
	$('.arrowlist ul li a').hover(
		function(){
			$(this).parents('li').css( { background:'url(/library/9241) no-repeat left 4px'  } );
		},
		function(){
			$(this).parents('li').css( { background:'url(/library/9190) no-repeat left 4px' } );
		}
	)

	// makes #content same height as #leftpanel if shorter
	if( $('#content > .padding').height() < $('#leftpanel').innerHeight()-68 )	
	{	
		$('#content > .padding').height($('#leftpanel').innerHeight()-68) 
	}



});


function search_onclick() {
	var search = document.getElementById('SearchString');
	if (search.value == 'Sláðu inn leitarorð') {
		search.value = '';
	}
}

function search_onblur() {
	var search = document.getElementById('SearchString');
	if (search.value == '') {
		search.value = 'Sláðu inn leitarorð';
	}
}

/* General form-validation */

function validate(form) {
	var isValid = true;
	for (var i = 0; i < form.elements.length; i++) {
		var elem = form.elements[i];
		if (elem.className.indexOf('reqd') > 0) {
			
			/* input, select og textarea er höndlað á sama hátt .... */
			if ((elem.tagName == "INPUT") || (elem.tagName == "TEXTAREA") || (elem.tagName == "SELECT")) {			
				if (elem.className.indexOf('emailval') > 0) {
					isValid = isValidEmail(elem.value);
				} else {
					isValid = (elem.value != '');
				}
				
				if (!isValid) {
					alert(elem.title + ' er ekki rétt útfyllt!');
					elem.focus();
					elem.style.borderColor = '#FF4A4A';
					elem.style.backgroundColor = '#FDFAD0';
					return false;
				} else {
					elem.style.borderColor = '';
					elem.style.backgroundColor = '';
				}
			}			
		}
	}
	return true;
}

function isValidEmail(value) {
	return (value.indexOf(".") > 0) && (value.indexOf("@") > 0);
}


// Björgvin Sigurðsson 26. júlí 2007.
// The function is used in employee lists to avoid showing full email addresses on the web.
// Changes email address with [hja] instead of @ and adds the new value to the 
// href of the element which has the id specified in id.
// Assumes that the element is a link and assumes that the email is a string with [hja] instead of @.
// param email: the string with the [hja]
// param id:  ID of the link-element which the email address belongs to.
function changeEmail(email, id)
{
	var newEmail = email.replace('[hja]', '@');
	document.getElementById(id).href = "mailto:"+email.replace('[hja]', '@');
}

