$(document).ready(function() {
	$('#banner')
		.after('<div id="navi">')
		.cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 8000,
			pager:  '#navi'
	});
	
	// Load weather module
	$('#vader_placeholder').load('/yr.php #yr-varsel');
	
	// Set default text in the inputs, and add onfocus and onblur-behaviour.
	toggleText($('#form_olympia_name'),'Navn');
	toggleText($('#form_olympia_mail'),'E-post');
	toggleText($('#form_olympia_mobile'),'Mobil');

	
	function toggleText(e, text)
	{
		e.val( text );
		e.attr("title", text);
		
		e.focus(function() {
			if (e.val() == text) {
				e.val('');
				e.css("color","#000");
			}
		});
		e.focusout(function() {
			if (e.val() == '') {
				e.val(text);
				e.css("color","#969696");
			}
		});
	}
});


function isEmail(str) {
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) {
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
