google.load("jquery", "1.3");

var hideForm = function() {
	$("#petition_form_bg").fadeOut("slow");
	$("#petition_form").fadeOut("slow");
}

var applyComments = function() {
	$(".comment").each( function (el) {
		console.log(el);
	});
}

function showForm(center) {
	var windowWidth = document.documentElement.clientWidth;
	var popupWidth = $("#petition_form").width();
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#petition_form").height();

	jQuery("#petition_form").center(true);

	$("#petition_form_bg").css({"opacity": "0.7"});  
	$("#petition_form_bg").fadeIn("slow");
	$("#petition_form").fadeIn("slow");
	$("#petition_form_bg").click( hideForm );
}
google.setOnLoadCallback(function() {
	
	jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        '50%', 
            zIndex:        '99'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
	};
	
	if ($("#petition_form").hasClass('show')) {
		showForm();
	}
	$('#sign').click( showForm );

	$(".imgcomment").each( function (i) {
		var id = '#com_cnt_'+i;
		if ($(id).html()) {
			$(this).qtip({
				content: $(id).html()
			});
		}
	});
	
	
});


