var popupStatus = 0;

var code = '<a id="popupContactClose" class="exit" href="#">esci x</a><div id="t1"><p class="testi1">Entra subito nel Music Store di Dada Play.me<br />Un catalogo con oltre 2,5 MILIONI di canzoni mp3 in alta qualit&agrave; ti aspetta!</p></div><iframe id="dadaframe" style="margin-left:20px" name="" width="300" height="420" frameborder="0" src="http://www.dada.it/sso/auth/logout.php?returnurl=http%3A%2F%2Fsso.dada.it%2Fsso%2Fd%2Fs.php%3Fid_leaf%3D0067%26ifrm%3D1%26';
if ( self.wapdld )
	code += 'wapdld%3D' + self.wapdld + '%26media_type%3Daudio%26getmp3%3D1%26';
code += 'css_follow%3D1%26tms%3D1245249355" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no"></iframe>';


function loadPopup()
{
	if(popupStatus==0)
	{
		$(".banner, embed, object, iframe").fadeOut("slow");
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

function disablePopup()
{
	if(popupStatus==1)
	{
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	$(".banner, embed, object, iframe").fadeIn("slow");
}

function centerPopup()
{
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var offsetHeight = document.documentElement.scrollTop;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();

	$("#popupContact").css({
		"position": "absolute",
		"top": offsetHeight + (windowHeight/2 - popupHeight/2),
		"left": windowWidth/2 - popupWidth/2
	});

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

}


$(document).ready(function()
{
	// box registrazione
	$("#button,#scarica,.download").click(function()
	{
		$("#popupContact").html(code);

		$("#popupContactClose").click(function()
		{
			disablePopup();
		});

		$("#dadaframe").attr( 'src', $("#dadaframe").attr('src') + "%26email%3D" + $("#email-reg").attr('value') + "%26passw%3D" + $("#password-reg").attr('value') );

		centerPopup();
		loadPopup();
		return false;
	});

	$("#backgroundPopup").click(function()
	{
		disablePopup();
	});

	$(document).keypress(function(e)
	{
		if(e.keyCode==27 && popupStatus==1)
		{
			disablePopup();
		}
	});
	// end box registrazione

});