$(function(){

	$('#nav a')

		.css( {backgroundPosition: "-20px 35px"} )

		.mouseover(function(){$(this).stop().animate({backgroundPosition:"(-20px 104px)"}, {duration:500})})

		.mouseout(function(){$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){$(this).css({backgroundPosition: "-20px 35px"})}})})



});

$(function(){

	var a = '<div id="tellfriend" class="contact_form"><a class="close" href="#close" >Close</a>';

	a += '<form id="tellafriend_form" method="post" action="#"  >';

	a += '<label for="from">Din Email: </label>';

	a += '<input class="validate[required,custom[email]] std_input" type="text" id="from" name="from" size="40" maxlength="100" value="" />';

	a += '<label for="name">Ditt Namn: </label>';

	a += '<input class="validate[required,custom[onlyLetter],length[0,35]] std_input" type="text" id="name" name="name" size="40" maxlength="35" value="" />';

	a += '<label for="to">Till: </label>';

	a += '<input class="validate[required,custom[email]] std_input" type="text" id="to" name="to" size="40" maxlength="100" />';

	a += '<label for="subject">Ämne: </label>';

	a += '<input class="validate[required,custom[onlyLetter],length[0,100]] std_input" type="text" id="subject" name="subject" size="40" value="" />';

	a += '<label for="message">Meddelande: </label>';

	a += '<textarea id="message" name="message" class="validate[required,length[6,1500]]" rows="18" cols="40">';

	a += '</textarea>';

	a += '<input type="submit" name="skicka" id="skicka" class="form_but" value="Skicka"/>';

	a += '</form>';

	a += '</div>';

	$(a).appendTo(document.body);

});



//centering popup  

function centerPopup(){  

//request data for centering  

var windowWidth = document.documentElement.clientWidth;  

// var windowHeight = document.documentElement.clientHeight;  

// var popupHeight = $("#tellfriend").height();  

var popupWidth = $("#tellfriend").width();  

//centering  

$("#tellfriend").css({  

"position": "absolute",  

"top": "450px",

"left": windowWidth/2-popupWidth/2  

});  

//"top": windowHeight/2-popupHeight/2,  

//only need force for IE6  

//$("#backgroundPopup").css({"height": windowHeight });  

  

}  





// tipsa än vän

jQuery.fn.fadeToggle = function(speed, easing, callback) {

  return this.animate({opacity: 'toggle'}, speed, easing, callback);  

};

$(document).ready(function() {

	$('#tellfriend').hide();

  	$('li a.email, #tellfriend a.close').click(function() {

		$(".formError").fadeOut(150,function(){$(this).remove();});

		centerPopup();

		$("#tellfriend").fadeToggle('slow');

	  });

	$("#tellafriend_form").validationEngine({

		ajaxSubmit: true,

		ajaxSubmitFile: "ajaxSubmit.php",

		ajaxSubmitMessage: "Tack så mycket !",

		success :  false,

		failure : function() {}

	})

	extrafunction();

  });


