Index: imagepicker.module
===================================================================
--- imagepicker.module	(revision 49)
+++ imagepicker.module	(working copy)
@@ -984,7 +984,7 @@
       var isFCKeditor = '". (module_exists('fckeditor') ? 'yes' : 'no' ) ."'
       var imgpInsertion;
       var i;
-
+       
       // Get show value
       for (i = 0; i < imgpForm.show.length; i++) {
         if(imgpForm.show[i].checked) {
@@ -1063,22 +1063,28 @@
       if (imgpForm.desc.checked) {
         imgpLinkElement = '<div class=\"imgp_title\">' + imgpImageTitle + '</div>' + imgpLinkElement + '<div class=\"imgp_desc\">' + imgpImageDesc + '</div>';
       }
+      
       // Create a HTML string which should be inserted in the node body
       imgpInsertion = imgpLinkElement.replace('%imgpImageElement%', imgpImageElement);
-
+      
       // Get the parent window of imagepicker iframe
       var win = window.opener ? window.opener : window.dialogArguments;
       if (!win) {
-        win = top;
+        if (window.parent) {
+            win=window.parent;
+        } else {
+            win = top;
+        }
       }
+      
       //var isTinyMCE = win.document.getElementById('mce_editor_0'); // buggy
       var isTinyMCE = win.tinyMCE; // Will be undefined if tinyMCE isn't loaded. This isn't a sure-proof way of knowing if tinyMCE is loaded into a field, but it works.
-
+       
       if (isFCKeditor == 'yes') {
         myFCKeditor = win.FCKeditorAPI.GetInstance(win.fckLaunchedJsId);
       }
 
-      if (isTinyMCE) {
+      if (isTinyMCE) {  
         win.tinyMCE.execCommand('mceInsertContent', false, imgpInsertion);
       }
       else if (isFCKeditor == 'yes' && myFCKeditor && win.fckIsRunning[win.fckLaunchedJsId] && win.document.getElementById(win.fckLaunchedTextareaId[0]).style.display=='none' ){
