jQuery(document).ready(function(){
   jQuery("a.commenterProfile").click(function(){CP_show(this);return false;});	
});


function CP_remove()
{
	jQuery('#CP').fadeOut(function(){
		jQuery('#CP').remove();
	});
	return false;
}

function CP_position(){
	var w = Math.round(jQuery('body').width()*0.8);
	var h = Math.round(window.innerHeight*0.8);
	jQuery("#CP").css({width: w + 'px', marginLeft: '-' + parseInt((w / 2),10) + 'px', marginTop: '-' + parseInt((h / 2),10) + 'px'});
}

function CP_show(el) {

	var url = el.href;
	
	jQuery("#CP").remove();

	var CP_div = jQuery('<div id="CP"></div>');

	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
    }
	
	CP_div.html('<a href="#" class="closeCommenterProfile">затвори</a>' +  
				'<div id="CP_content"><div class="CP_loader">Събиране на информация от <a href="http://code.google.com/intl/bg/apis/socialgraph/">Големия Брат</a>, моля почакайте!</div></div>');	
	jQuery(CP_div.children('a.closeCommenterProfile')[0]).click(
		function(){
			CP_remove();
			return false;
		});
	
	jQuery("body").append(CP_div);
	
	/*
	var w = Math.round(jQuery('body').width()*0.8);
	var h = Math.round(window.innerHeight*0.8);
	jQuery("#CP").css({width: w + 'px', marginLeft: '-' + parseInt((w / 2),10) + 'px', marginTop: '-' + parseInt((h / 2),10) + 'px'});
	*/
	CP_position();
	
	jQuery(window).resize(CP_position);
	
	jQuery('#CP').fadeIn();

	jQuery.get(url, function(data){
		jQuery('#CP_content').html(data);
	});

	return false;
}
