jQuery(function ($) {

	$('#search').focus(function() {
		if(this.value == 'Søg')
			this.value = '';
	}).focusout(function() {
		if(this.value == '')
			this.value = 'Søg';
	});
	
	$('#newsletter_inside_submit').click(function() {
		
		var txt = $('#newsletter_inside_input').attr("value");
		if(txt != "Indtast e-mail her" && txt != ""){
			$('#newsletter_inside_signup').hide();
			$('#newsletter_inside_signup_tak').show();
			send_mail(txt,'subscribe');
			$('#newsletter_inside_input_tak').text(txt);
		}
	});
	
	$('#newsletter_outside_submit').click(function() {

		var txt = $('#newsletter_outside_input').attr("value");
		if(txt != "Indtast e-mail her" && txt != ""){
			$('#newsletter_outside_signup').hide();
			$('#newsletter_outside_signup_tak').show();
			send_mail(txt,'unsubscribe');
			$('#newsletter_outside_input_tak').text(txt);
		}
	});
	
	$('#newsletter_fot_submit').click(function() {
		var txt = $('#newsletter_fot_input').attr("value");
		if(txt != "Indtast e-mail her" && txt != ""){
			$('#footer_newsletter').hide();
			$('#footer_newsletter_tak').show();
			send_mail(txt,'subscribe');
			$('#newsletter_fot_input_tak').text(txt);
		}
	});
	
	$('#newsletter_submit').click(function() {

		var txt = $('#newsletter_input').attr("value");
		if(txt != "Indtast e-mail her" && txt != ""){
			$('#newsletter_signup').hide();
			$('#newsletter_signup_tak').show();
			send_mail(txt,'subscribe');
			$('#newsletter_input_tak').text(txt);
		}
	});
	
	$('#newsletter_inside_input').focus(function() {
		if(this.value == 'Indtast e-mail her')
			this.value = '';
	}).focusout(function() {
		if(this.value == '')
			this.value = 'Indtast e-mail her';
	});
	
	$('#newsletter_outside_input').focus(function() {
		if(this.value == 'Indtast e-mail her')
			this.value = '';
	}).focusout(function() {
		if(this.value == '')
			this.value = 'Indtast e-mail her';
	});
	
	$('#newsletter_input').focus(function() {
		if(this.value == 'Indtast e-mail her')
			this.value = '';
	}).focusout(function() {
		if(this.value == '')
			this.value = 'Indtast e-mail her';
	});
	
	$('#newsletter_fot_input').focus(function() {
		if(this.value == 'Indtast e-mail her')
			this.value = '';
	}).focusout(function() {
		if(this.value == '')
			this.value = 'Indtast e-mail her';
	});
		
});

function send_mail(email,type){
	if (window.XMLHttpRequest) {
			  xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			// 
		}
	}
	xmlhttp.open("GET","/Control/sendMail.php?type="+type+"&user="+email,true);
	xmlhttp.send();
}

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
var ddmenuitemparent = 0;

function menu_open()
{  menu_canceltimer();
   menu_close();
   ddmenuitemparent = $(this);
   ddmenuitem = ddmenuitemparent.find('ul').css('visibility', 'visible');
   $(this).find('a:first').css('background-image', 'url(/Images/menu_onclick.png)');
   var pos = ddmenuitemparent.offset();

//ddmenuitem.style.left=(pos.left)+"px";
ddmenuitem.css({"left":(pos.left-40)+"px"});
   //ddmenuitem.css({"margin-left":(pos.left-162-510)+"px"});
}

function menu_close(){  
	if(ddmenuitem){
		ddmenuitem.css('visibility', 'hidden');
		ddmenuitemparent.find('a:first').css('background-image', 'url(/Images/menu_bg.png)');
		$('#selected').css('background-image', 'url(/Images/menu_onclick.png)');
	}
}

function menu_timer()
{  closetimer = window.setTimeout(menu_close, timeout);}

function menu_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#menu > li').bind('mouseover', menu_open)
   $('#menu > li').bind('mouseout',  menu_timer)});

document.onclick = menu_close;

