jQuery(function(){
	//initialize superfish menu
	jQuery('ul.sf-menu').superfish();
	//top menu search text
	$('#src_text_field').focus(function(){ if($(this).val() == 'Søk i MediaForum') $(this).val(''); });
	$('#src_text_field').blur(function(){ if($(this).val() == '') $(this).val('Søk i MediaForum'); });
	
	//toggle labels for form input/textarea when focused/blured
	$('#nwl_form .frm_field input:text').each(function(){
		if($(this).val() != '') $(this).siblings('label').hide();
		$(this).siblings('label').click(function(){
			$(this).siblings('input').focus();
		});
		$(this).focus(function(){
			$(this).siblings('label').hide();
			$(this).parent().removeClass('error');
		});
		$(this).blur(function(){		
			if($(this).val() == '') $(this).siblings('label').show();
		});	
	});		
});

//submit the newsletter form
function submitNwlForm(form){
	//showLoading();
	$.ajax({
	  url: $(form).attr('action'),
	  type: 'post',
	  data: 'ajax=1'+$(form).serialize(),
	  dataType: 'json',
	  success: function(response) {
		  if(response.status == 'success'){
			  $(form).hide();
			  $('#nwl_form_response').html(response.message);
		  }
		  else alert(response.message);
	  }
	});
	return false;
}

//rewrites the email addresses so they can't be read by the bots
function writeEmailAddress(domain, user, tld, extra, boxId){
	var html = '<a href="mai'+'lto:'+user+'@'+domain+'.'+tld+'" '+extra+'>'+user+'@'+domain+'.'+tld+'</'+'a>';
	if(typeof(boxId) == 'undefined') document.write(html);
	else document.getElementById(boxId).innerHTML = html;
}

