// popups logic
$(document).ready(function(){

    $(".popup").each(function(){
		// move all popups to the body for better positioning
		$(this).remove().appendTo("body");
        // close popup on mouseout from it
		$(this).hover(null, function(){$(this).hide()});
    });

    $(".opener").click(function(){
    	// close all other popups
    	$("#login-form-window, .popup").hide();

    	// find needed one and open it above cliked element
    	var offset = $(this).offset();
    	var p = $("#"+$(this).attr("id")+"-popup");
    	p.css("top", 0).css("left", -1000).show();
    	var top = offset.top - p.height() - 5;
    	var left = offset.left - p.width()/5;
    	p.css("top", top).css("left", left);

    	return false;
    });

    // close popup on "close" button click
    $(".popup-close").click(function(){
    	$(this).parents(".popup:first").hide();
    });

    // show link instead of submit button
    $("a.submit").each(function(){
    	$(this).parent().find(":submit").hide();
    	$(this).removeClass("hidden").click(function(){
	    	$(this).parent().submit();
    		return false;
    	});
    });

});

