You almost had it, you want the action "AXRaise" to bring a window forward. This doesn't actually swap the windows positions in the list of ordered windows, it just brings the back most window to the front and pushes the other windows back like a stack of cards:
tell application "System Events"
set myApp to first application process whose name is "TextEdit"
-- If you are running from a Script launcher like FastScripts, you might want something like this...
-- set myApp to first application process whose frontmost is true
-- This creates a filterd list of windows that ignores floating windows and minimized windows
set myWindows to (every window whose (subrole is "AXStandardWindow" and value of attribute "AXMinimized" is false)) of myApp
-- We need at least two windows to swap
if (count of myWindows) < 2 then
beep
return
end if
-- The magic that gets the back most window to the front
perform action "AXRaise" of last item of myWindows
end tell