openPromoPage = function(page) { 
	var html = '<iframe border="0" frameborder="0" id="network_view" name="network_view" src="http://ididid.eu/'+page+'" width="935" height="600" scrolling="no" allowtransparency="true"></iframe>';	
	showOverlay(html);
	resizePopup(935,599);
};

openPromoPagePopup = function(page) { 
	window.open ('http://ididid.eu/'+page,"mywindow","location=0,status=0,scrollbars=0,width=935,height=599"); 
};

openPromoLayoverScore = function(page, score) {
	var html = '<iframe border="0" frameborder="0" id="network_view" name="network_view" src="http://ididid.eu/'+page+'?score='+score+'" width="878" height="639" scrolling="no" allowtransparency="true"></iframe>';	
	showOverlay(html);
	resizePopup(878,639);
};

openPromoPopupScore = function(page, score) {
	window.open ('http://ididid.eu/'+page+'?score='+score,"mywindow","location=0,status=0,scrollbars=0,width=878,height=639"); 
};

showOverlay = function(html) { 
	$("#popupOverlay").remove();
	$("#popupOverlayWindow").remove();
	
	$("body").append("<div id='popupOverlay' class='popupOverlayBG'></div><div id='popupOverlayWindow'>"+createPopupIdidid(html)+"</div>");
	
	if(overlayDetectMacXFF()){
		$("#popupOverlay").addClass("popupOverlayMacFFBGHack"); //use png overlay so hide flash
	}else{
		$("#popupOverlay").addClass("popupOverlayBG"); //use background and opacity
	}
};

function overlayDetectMacXFF() {
	  var userAgent = navigator.userAgent.toLowerCase();
	  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
	    return true;
	  }
}

createPopupIdidid = function(html) {
	if(html == undefined) { html = ''; }
	var popup = '<div id="ididid_popup_promo"><div class="closeButton" onclick="closePromoPopup()"></div>'+html+'</div>';
	return popup;
};

closePromoPopup = function() { 
	$("#popupOverlay").remove();
	$("#popupOverlayWindow").remove();
};

resizePopup = function(width, height) {
	
	var marginLeft = width / 2;
	var marginTop = height / 2;
	
	$('#ididid_popup_promo').css({
		'width' : width+'px',
		'height' : height+'px',
		'marginLeft' : '-'+marginLeft+'px',
		'marginTop' :'-'+marginTop+'px'
	});
	
};
